mandelbrot.php 978 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. <?php
  2. require_once 'bootstrap.php';
  3. $width=500;
  4. $height=500;
  5. $maxIterations = 100;
  6. $minX = -2.0;
  7. $maxX = 1.0;
  8. $minY = -1.5;
  9. $maxY = 1.5;
  10. $pixelCraft->createImage($width,$height);
  11. for ($y = 0; $y < $height; $y++) {
  12. for ($x = 0; $x < $width; $x++) {
  13. $cx = $minX + ($x / $width) * ($maxX - $minX);
  14. $cy = $minY + ($y / $height) * ($maxY - $minY);
  15. $zx = 0.0;
  16. $zy = 0.0;
  17. $iteration = 0;
  18. while ($zx * $zx + $zy * $zy < 4 and $iteration < $maxIterations) {
  19. $temp = $zx * $zx - $zy * $zy + $cx;
  20. $zy = 2 * $zx * $zy + $cy;
  21. $zx = $temp;
  22. $iteration++;
  23. }
  24. $colorIntensity = (int)(255 * $iteration / $maxIterations);
  25. $colorName = 'C_' . $colorIntensity . '0' . (255 - $colorIntensity);
  26. $pixelCraft->addColor($colorName, $colorIntensity, 0, 255 - $colorIntensity);
  27. $pixelCraft->drawPixel($x, $y, $colorName);
  28. }
  29. }
  30. $pixelCraft->renderImage();