|
|
|
|
@ -10,7 +10,8 @@ |
|
|
|
|
modified by anon |
|
|
|
|
*/ |
|
|
|
|
|
|
|
|
|
function write_mandelbrot_to_stream($w, $h, $stream, $bitmap) { |
|
|
|
|
function write_mandelbrot_to_stream($w, $h, $stream, $bitmap) |
|
|
|
|
{ |
|
|
|
|
if ($bitmap) |
|
|
|
|
fprintf($stream, "P4\n%d %d\n", $w, $h); |
|
|
|
|
|
|
|
|
|
@ -27,17 +28,27 @@ function write_mandelbrot_to_stream($w, $h, $stream, $bitmap) { |
|
|
|
|
for ($y = 0; $y < $h; ++$y) { |
|
|
|
|
$Ci = $y * $yfac - 1.0; |
|
|
|
|
for ($x = 0; $x < $w; ++$x) { |
|
|
|
|
$Zr = 0; $Zi = 0; $Tr = 0; $Ti = 0.0; |
|
|
|
|
$Zr = 0.0; |
|
|
|
|
$Zi = 0.0; |
|
|
|
|
$Tr = 0.0; |
|
|
|
|
$Ti = 0.0; |
|
|
|
|
$Cr = $x * $xfac - 1.5; |
|
|
|
|
|
|
|
|
|
try { |
|
|
|
|
do { |
|
|
|
|
for ($i = 0; $i < $iter; ++$i) { |
|
|
|
|
$Zi = 2.0 * $Zr * $Zi + $Ci; |
|
|
|
|
$Zr = $Tr - $Ti + $Cr; |
|
|
|
|
$Tr = $Zr * $Zr; |
|
|
|
|
if (($Tr+($Ti = $Zi * $Zi)) > 4.0) break 2; |
|
|
|
|
|
|
|
|
|
if (($Tr + ($Ti = $Zi * $Zi)) > 4.0) { |
|
|
|
|
throw new Exception("break 2"); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
$byte_acc += $bit_num; |
|
|
|
|
} while (false); |
|
|
|
|
} catch (Exception $e) { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if ($bitmap) { |
|
|
|
|
if ($bit_num === 1) { |
|
|
|
|
@ -68,7 +79,8 @@ function write_mandelbrot_to_stream($w, $h, $stream, $bitmap) { |
|
|
|
|
return true; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
function treffynnon_mandelbrot_to_file($filename, $w, $h, $binary_output) { |
|
|
|
|
function treffynnon_mandelbrot_to_file($filename, $w, $h, $binary_output) |
|
|
|
|
{ |
|
|
|
|
$file_open_type = 'w'; |
|
|
|
|
if ($binary_output) |
|
|
|
|
$file_open_type = 'wb'; |
|
|
|
|
@ -82,7 +94,8 @@ function treffynnon_mandelbrot_to_file($filename, $w, $h, $binary_output) { |
|
|
|
|
return true; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
function treffynnon_mandelbrot_to_mem($w, $h, $binary_output) { |
|
|
|
|
function treffynnon_mandelbrot_to_mem($w, $h, $binary_output) |
|
|
|
|
{ |
|
|
|
|
$file_open_type = 'w+'; |
|
|
|
|
if ($binary_output) |
|
|
|
|
$file_open_type = 'w+b'; |
|
|
|
|
@ -98,4 +111,12 @@ function treffynnon_mandelbrot_to_mem($w, $h, $binary_output) { |
|
|
|
|
return $ret; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
echo treffynnon_mandelbrot_to_mem((int) $argv[1], (int) $argv[1], false); |
|
|
|
|
function main() |
|
|
|
|
{ |
|
|
|
|
global $argv; |
|
|
|
|
if (count($argv) < 3) { |
|
|
|
|
echo "Usage: php mandelbrot.php <width> <height> [<output_file>]\n"; |
|
|
|
|
exit(1); |
|
|
|
|
} |
|
|
|
|
echo treffynnon_mandelbrot_to_mem((int)$argv[2], (int)$argv[2], false); |
|
|
|
|
} |
|
|
|
|
|