Image demonstrating Lorentz attractor

Chaos Theory and Lorentz attractors: check out for this graphic representation of Lorentz attractor using PHP.

Date: 21-dec-2009
/*
Math reference:
Lorentz attractors and Chaos Theory
http://mathworld.wolfram.com/LorenzAttractor.html
initially for r=28, s = 10, b = 8/3.

The Lorenz attractor is generated by the differential equation written by

dx/dt= -10x +10y
dy/dt= 28x -y -xz
dz/dt= -8/3z +xy.


By http://freedelta.free.fr 21-dec-2009
*/
header("Content-type: image/jpeg"); define("TIMESTEP",0.0001); /* Numerical timestep for dt */ define("XSCALE",4); /* Appropriate scaling factors for */ define("YSCALE",4); /* each axis. */ define("ZSCALE",4); define("TSCALE",20); /* Scaling factor for the time axis */ define("INTERVAL",100); /* Sample function every INTERVAL points for output */ $height = 530; $width = 620; $im = imagecreate($width,$height); // Canvas width , height px

// Color definitions $white = imagecolorallocate($im,255,255,255); $black = imagecolorallocate($im,0,0,0); $red = imagecolorallocate($im,255,0,0); $green = imagecolorallocate($im,0,255,0); $blue = imagecolorallocate($im,0,0,255); $indigo= imagecolorallocate($im,75,0,130); // double $x1=0.0; $y1=0.0; $z1=0.0; $x=0.0; $y=0.0; $z=0.0; $t=0.0; $dt=0.0; $t0=0.0; // int $xp=0; $yp=0; $tp=0; $gxp=0; $gyp=0; $gzp=0; $x1=($y1=($z1=($t=0.0001))); /* Initial conditions */ $dt=TIMESTEP; // Plan lines and messages imagestring($im, 4 , 2, 5, "Demonstration of Lorentz attractor", $blue); imageline($im,320,0,320,479,$red); imageline($im,0,240,639,240,$black); imagestring($im, 3, 2, 285, "X variable with respect to time", $black); imageline($im,0,300,639,300,$black); imagestring($im, 3 , 2, 365, "Y variable with respect to time", $black); imageline($im,0,380,639,380,$black); imagestring($im, 3, 2, 445, "Z variable with respect to time", $black); imageline($im,0,460,639,460,$black); $lineWidth=0.1; while($tp<639) { $x=$x1 + ( -10.0*$x1 + 10.0*$y1 ) * $dt; $y=$y1 + ( 28.0*$x1 - $y1 - $x1*$z1 ) * $dt; $z=$z1 + ( -(8/3)*$z1 + $x1*$y1 ) * $dt; $t=$t + $dt; $xp=320+(int)floor(XSCALE*$x); $yp=240-(int)floor(YSCALE*$z); $tp=(int)floor(TSCALE*$t); if ($tp>639) { $tp=479; } $gxp=300-(int)floor(XSCALE*$x/4); $gyp=380-(int)floor(YSCALE*$y/4); $gzp=460-(int)floor(ZSCALE*$z/4); imageline($im, $xp, $yp, $xp+$lineWidth, $yp+$lineWidth, $blue); // x variable with respect to time imageline($im, $tp, $gxp, $tp+$lineWidth, $gxp+$lineWidth, $red); // y variable with respect to time imageline($im, $tp, $gyp, $tp+$lineWidth, $gyp+$lineWidth, $green); // z variable with respect to time imageline($im, $tp, $gzp, $tp+$lineWidth, $gzp+$lineWidth, $indigo); $x1=$x; $y1=$y; $z1=$z; } // Display image imagejpeg($im);

It will output an image like this one: