Ratings | | Unique User Downloads | | Download Rankings |
Not yet rated by the users | | Total: 55 | | All time: 10,593 This week: 69 |
|
Description | | Author |
This package can generate noise images using the SimpleX algorithm.
It can take several parameters to configure the generation of noise values like the zoom level, octaves, persistence, and elevation.
The class can return the noise level values in different positions given the X and Y coordinates of the points in the noise plane. Innovation Award
August 2022
Number 9 |
Noise is a signal that can cause certain disturbances. It is often associated with sound but can also be associated with an image.
Noise images can be helpful. For instance, you may use noise images to generate CAPTCHA validation images that may obfuscate a picture with text that the user needs to recognize.
The noise image can help obfuscate the text to make it harder for robots to recognize the text while humans may be able to identify it.
This package can generate noise data for creating noise images for CAPTCHA validation or other purposes.
It uses the SimpleX noise algorithm. This algorithm has several advantages over classic forms of generating noise like the Perlin algorithm.
For instance, the simplex algorithm requires less computing power to create noise.
Manuel Lemos |
| |
|
|
Innovation award
Nominee: 5x |
|
Example
<?php
declare(strict_types=1);
error_reporting(-1);
require_once __DIR__ . '/../vendor/autoload.php';
$mapWidth = $_GET['w'] ?? 100;
$mapHeight = $_GET['h'] ?? 100;
$offsetX = $_GET['x'] ?? 0;
$offsetY = $_GET['y'] ?? 0;
$scale = $_GET['scale'] ?? 5;
$zoom = $_GET['zoom'] ?? 0.025;
$octaves = $_GET['octaves'] ?? 4;
$persistence = $_GET['persistence'] ?? 0.5;
$elevation = $_GET['elevation'] ?? 1.0;
$gradient = $_GET['gradient'] ?? 'greyscale.png';
$gradient = imagecreatefrompng(__DIR__ . '/gradients/' . $gradient);
$colors = [];
for ($i = 0; $i < 256; $i++) {
$colors[] = imagecolorat($gradient, $i, 1);
}
$displayWidth = $mapWidth * $scale;
$displayHeight = $mapHeight * $scale;
$noiseImage = imagecreatetruecolor((int)$mapWidth, (int)$mapHeight);
$displayImage = imagecreatetruecolor($displayWidth, $displayHeight);
$noise2D = new \BlackScorp\SimplexNoise\Noise2D(
(float)$zoom,
(int)$octaves,
(float)$persistence,
(float)$elevation
);
for ($x = 0; $x < $mapWidth; $x++) {
for ($y = 0; $y < $mapHeight; $y++) {
$locationX = $offsetX + $x;
$locationY = $offsetY + $y;
$greyValue = $noise2D->getGreyValue($locationX, $locationY);
$color = $colors[$greyValue];
imagesetpixel($noiseImage, $x, $y, $color);
}
}
imagecopyresampled(
$displayImage,
$noiseImage,
0,
0,
0,
0,
$displayWidth,
$displayHeight,
(int)$mapWidth,
(int)$mapHeight
);
header('Content-Type:image/png');
imagepng($displayImage);
imagedestroy($displayImage);
|
Details
PHP SimplexNoise
this is just a php version of the original code at
https://weber.itn.liu.se/~stegu/simplexnoise/simplexnoise.pdf
Installation
composer require blackscorp/simplexnoise
Usage
$noise2D = new \BlackScorp\SimplexNoise\Noise2D();
$greyValue = $noise2D->getGreyValue($locationX, $locationY);
var_dump($greyValue); //a value between 0 and 255
Examples
for more examples and details please take a look at examples folder.
just copy more png images into exampels/gradients in order to create cool effects
currently only 2D is implemented
|
Applications that use this package |
|
No pages of applications that use this class were specified.
If you know an application of this package, send a message to the author to add a link here.