Sprawdzi to ktoś? Nie interesuje mnie alternatywa tego kodu ale dlaczego w tym przypadku nie chodzi tak jak powinien.
Biblioteka gd na cba działa ale chyba dla większej ilości iteracji nie chce już chodzić, bo czas skryptu ograniczony, poza tym ,czy tutaj ta funkcja losowania jest taka jak być powinna, czy trzeba coś jeszcze inicjować?

  1. <? //barnsley fern
  2. $wysokosc=568;
  3. $szerokosc=824;
  4. $obraz=ImageCreateTrueColor($szerokosc, $wysokosc);
  5. $bialy=ImageColorAllocate($obraz, 255, 0, 255);
  6. $blue=ImageColorAllocate($obraz, 0,0,255);
  7. $green = imagecolorallocate($obraz, 0,100,0);
  8. $yellow= ImageColorAllocate($obraz, 255, 255, 0);
  9. ImageFill($obraz, 0, 0, $blue);
  10.  
  11. $point[0] = array('x' => 0, 'y' => 0);
  12. $x=Array();
  13. $y=Array();
  14. class zespolona{
  15. public $imaginary;
  16. public $real;
  17. public function im($a){return $imaginary=$a;}
  18. public function re($a){return $real=$a;}
  19. }
  20. class operacje{
  21. public function dodaj($z,$y){
  22. return $z+$y;}
  23. public function pomnoz($z,$y){
  24. return $z*$y;}
  25. }
  26. $z = new zespolona();
  27. $v = new zespolona();
  28. $result=new operacje();
  29.  
  30. $x0 = ($point[0]['x']);
  31. $y0 = ($point[0]['y']);
  32. $x[0]=$x0;
  33. $y[0]=$y0;
  34. for($j=0;$j<=100000;$j++){
  35. //srand((double) microtime()*1000000);
  36. $ra=rand(0,6999);
  37.  
  38. if($ra<70){
  39. $x[$i]=$result->dodaj(0,0);
  40. $y[$i]=$result->pomnoz(0.16,$y[$i-1]);
  41. imagesetpixel($obraz, round($x[$i]+100),round($y[$i]+10), $yellow);
  42. }else if($ra>=70 && $ra<5950){
  43. $x[$i]=$result->dodaj($result->pomnoz(0.85,$x[$i-1]),$result->pomnoz(0.04,$y[$i-1]));
  44. $y[$i]=$result->dodaj($result->dodaj($result->pomnoz(-0.04,$x[$i-1]),$result->pomnoz(0.85,$y[$i-1])),1.6);
  45. imagesetpixel($obraz, round($x[$i]+100),round($y[$i]+10), $yellow);
  46. }else if($ra>=5950 && $ra<6440){
  47. $x[$i]=$result->dodaj($result->pomnoz(0.2,$x[$i-1]),$result->pomnoz(-0.26,$y[$i-1]));
  48. $y[$i]=$result->dodaj($result->dodaj($result->pomnoz(0.23,$x[$i-1]),$result->pomnoz(0.22,$y[$i-1])),1.6);
  49. imagesetpixel($obraz, round($x[$i]+100),round($y[$i]+10), $yellow);
  50. }else if($ra>=6440 && $ra<7000){
  51. $x[$i]=$result->dodaj($result->pomnoz(-0.15,$x[$i-1]),$result->pomnoz(0.28,$y[$i-1]));
  52. $y[$i]=$result->dodaj($result->dodaj($result->pomnoz(0.26,$x[$i-1]),$result->pomnoz(0.24,$y[$i-1])),0.44);
  53. imagesetpixel($obraz, round($x[$i]+100),round($y[$i]+10), $yellow);
  54. }
  55. }
  56. Header('Content-type: image/png');
  57. ImagePng($obraz);
  58. ImageDestroy($obraz);
  59. ?>