function generate_mandelbrot($fname, $size, $min, $max, $iterations) { $img = ImageCreate($size[0], $size[1]); $colors = array(); $colors['inside'] = imagecolorallocate($img, 0, 0, 0); Profiler::startTimer("palette"); $palette = imagecreatefrompng("palette.png"); for ($i = 0; $i < imagesx($palette); $i++) { $rgb = imagecolorat($palette, $i, 0); $colors[$i] = imagecolorallocate($img, $rgb >> 16 & 0xff, $rgb >> 8 & 0xff, $rgb & 0xff); } Profiler::stopTimer("palette"); Profiler::startTimer("mainloop"); for ($i = 0; $i < $size[0]; $i++) { for ($j = 0; $j < $size[1]; $j++) { Profiler::startTimer("math"); $x = $min[0] + $i * (($max[0] - $min[0]) / ($size[0] - 1)); $y = $min[1] + $j * (($max[1] - $min[1]) / ($size[1] - 1)); $iteration = 0; $z0 = 0; $z1 = 0; $x2 = $y2 = 0; while ($iteration <= $iterations && $x2 + $y2 <= 4) { $z1 = 2 * $z0 * $z1 + $y; $z0 = $x2 - $y2 + $x; $x2 = $z0 * $z0; $y2 = $z1 * $z1; $iteration++; } Profiler::stopTimer("math"); Profiler::startTimer("setpixel"); $color = $colors[$iteration == $iterations ? 'inside' : $iteration]; ImageSetPixel($img, $i, $j, $color); Profiler::stopTimer("setpixel"); } } Profiler::stopTimer("mainloop"); Profiler::startTimer("saveimage"); ImagePNG($img, $fname); Profiler::stopTimer("saveimage"); //print Profiler::display(); }
// Load console scriptfiles /* ========================= */ $files = GetSubfiles("$abspath/cscripts"); foreach ($files as $file) require_once("$abspath/cscripts/$file"); /* ========================= */ // Start session /* ========================= */ require_once("session.php"); require_once("system/links.php"); $prof->stopTimer( "include" ); $prof->startTimer( "database" ); /* ========================= */ // Connect to database /* ========================= */ if (($str = db_connect()) !== true) echo "Failed to connect to database!"; $prof->stopTimer( "database" ); /* ========================= */ // Set initial data /* ========================= */ if (!isset($_SESSION['murrix']['root_id'])) $_SESSION['murrix']['root_id'] = getSetting("ROOT_NODE_ID", 1, "any");