Generating Perlin noise requires heavy calculation and PHP (in my opinion) is not the best language for this task but still it can be useful. The algorithm is an adaptation form this pseudo code. The class seems to work but I’m not if it works 100% correctly. The tricky part was to deal with the types because PHP tends to convert large integers to float, and the algorithm uses bitwise operators on some stages.
This class is just for testing purposes it consumes a lot of CPU cycles and I hardly recommend to avoid using it in live environment. Try to keep the cycles low as well as the octaves number close to 1.
Sample SVG result: noise.svg. Example usage (generate SVG map of terrain):
require("class.perlin.php");
$per = new Perlin;
$xl = 100;
$yl = 40;
header("Content-type: image/svg+xml");
echo '';
echo '<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN"
"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">';
echo '';
Download: classperlinphp.zip
Comment by stelt — 02.03.2008 @ 15:08
Comment by AquilaX — 02.03.2008 @ 16:11
Comment by Christian — 26.12.2008 @ 16:02
Comment by AquilaX — 26.12.2008 @ 19:05
Comment by Derek — 19.07.2009 @ 18:21
Comment by AquilaX — 19.07.2009 @ 18:39
Comment by Dylan — 23.07.2010 @ 08:55
Comment by Joseph — 17.07.2011 @ 14:30