Forum Moderators: coopster
<?php
$s=500;
$im=imagecreatetruecolor($s,$s);
$tmp=rand(1,$s-1);
$x=rand(0,1)?(rand(0,1)?0:$s-1):$tmp;
$y=$x&&$x<$s-1?(rand(0,1)?0:$s-1):$tmp;
$vx=0;
$vy=0;
for($i=0;$i<1000;$i++) {
$_x=$x;
$_y=$y;
$x=$x+(rand(0,1)?1:-1)+$vx;
$y=$y+(rand(0,1)?1:-1)+$vy;
if($x<0) {
$x=0;
$vx=-$vx;
}
if($x>=$s) {
$x=$s-1;
$vx=-$vx;
}
if($y<0) {
$y=0;
$vy=-$vy;
}
if($y>=$s) {
$y=$s-1;
$vy=-$vy;
}
$vx=$vx*.8+($x-$_x)*.2;
$vy=$vy*.8+($y-$_y)*.2;
$c=imagecolorallocate($im,0,(255-$i)%255,$i%255);
imageline($im,$_x,$_y,$x,$y,$c);
}
imagefilter($im,IMG_FILTER_GAUSSIAN_BLUR);
header('Content-type:image/png;');
imagepng($im);
imagedestroy($im);
?>
These parameters are integers between 0 and 255 or hexadecimals between 0x00 and 0xFF.
imagecolorallocate with the third argument (green) as a negative number, this causes imagecolorallocate to return false, which imageline is interpreting as black.