array('default'=>0, 'min_range'=>0, 'max_range'=>1073741824)); $x_get=filter_input(INPUT_GET, 'x', FILTER_VALIDATE_INT, $opts); $y_get=filter_input(INPUT_GET, 'y', FILTER_VALIDATE_INT, $opts); $it_get=filter_input(INPUT_GET, 'it', FILTER_VALIDATE_INT, array('options'=>array('default'=>50, 'min_range'=>3, 'max_range'=>100))); $z_get=filter_input(INPUT_GET, 'z', FILTER_VALIDATE_INT, array('options'=>array('default'=>0, 'min_range'=>0, 'max_range'=>30))); $palette_get=filter_input(INPUT_GET, 'palette', FILTER_SANITIZE_STRING, array('options'=>array('default'=>"default"))); //3ICE: Spit back: header("X-Debug--Pos: ".$x_get."; ".$y_get); header("X-Debug--Zoom: ".$z_get); header("X-Debug--Iter: ".$it_get); header("X-Debug--Plte: ".$palette_get); define('MAX_ITERATIONS', $it_get); //palette.png must be wider (or equal) define('SKIP_ITERATIONS', MAX_ITERATIONS + 1); define('STEP', pow(2, -($z_get-1))); header("X-Debug--STEP: ".STEP); define('X_MIN', -1.5 + $x_get * STEP); define('X_MAX', X_MIN + STEP); define('Y_MIN', -1 + $y_get * STEP); define('Y_MAX', Y_MIN + STEP); //todo SQL Check if already generated & cached in database, return that if yes: //todo else (file doesn't exist yet) generate it and save to cache: $img = imagecreate(WIDTH, HEIGHT); // Load the palette to find colors $colors = array(); $inside = imagecolorallocate($img, 0, 0, 0); switch ($palette_get) { case "default": $palette = imagecreatefrompng("palette.png"); break; case "continuous": $palette = imagecreatefrompng("palette-continuous.png"); break; case "greyscale": $palette = imagecreatefrompng("palette-greyscale.png"); break; case "fine": $palette = imagecreatefrompng("palette-fine.png"); break; default: header("X-Debug--Palette-ERROR: ".$palette_get); $palette = imagecreatefrompng("palette.png"); } for($i=0; $i> 16) & 0xFF, ($rgb >> 8) & 0xFF, $rgb & 0xFF); } //3ICE: Debug statistics: $cardiodskipcount = 0; $bulbskipcount = 0; $skipcount2 = 0; $pixels = 0; $flops = 0; for($i=0; $i 2, then the sequence will tend to infinity so we can exit the loop while($it <= MAX_ITERATIONS && $x2+y2 <= 4){ // In order to get the next term in the sequence, we need to square the previous number and then add the original complex number // z(n+1) = z(n)^2+c //3ICE: Optimized by removing $k = $z; // z is a complex number. Here's how to square a complex number in the form x+yi: // New real component: x^2-y^2 // New imaginary component: 2*real*imaginary //3ICE: Optimized from $z[0] = $x2 - $y2; $z_i *= 2 * $z_r; //3ICE: Further optimized by using *= $z_r = $x2 - $y2; // Add Complex Number //3ICE: Optimized from $z[0] = $z[0] + $x; $z_r += $x; //3ICE: Further optimized from $z_i = $z_i + $y; $z_i += $y; //3ICE: Optimized from $x2 = pow($z[0], 2); $x2 = $z_r * $z_r; $y2 = $z_i * $z_i; ++$it; ++$flops; } if($it >= MAX_ITERATIONS){ if($it < SKIP_ITERATIONS){++$skipcount2;} imagesetpixel($img, $i, $j, $inside); }else{ ++$pixels; imagesetpixel($img, $i, $j, $colors[$it]); } } } header("X-Debug--Flops: ".$flops); header("X-Debug--Pixels: ".$pixels); header("X-Debug--SKIPPED_EFFICIENT_BULB: ".$bulbskipcount); header("X-Debug--SKIPPED_EFFICIENT_CARDIOD: ".$cardiodskipcount); header("X-Debug--SKIPPED_INEFFICIENT_MAXITER: ".$skipcount2); imagepng($img); //todo remember to save in DB. // töröljük a képet a memóriából imagedestroy($img); ?>