-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmandelbrot.php
56 lines (45 loc) · 1.04 KB
/
mandelbrot.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
<?php
class Mandelbread {
public function index()
{
for ($y = -39; $y < 39; $y++) {
printf("\n");
for ($x = -39; $x < 39; $x++) {
$i = $this->mandelbrot(
$x / 40.0,
$y / 40.0
);
if ($i == 0) {
printf("*");
} else {
printf(" ");
}
}
}
printf("\n");
}
private function mandelbrot($x, $y)
{
$cr = $y - 0.5;
$ci = $x;
$zi = 0.0;
$zr = 0.0;
$i = 0;
while (1) {
$i++;
$temp = $zr * $zi;
$zr2 = $zr * $zr;
$zi2 = $zi * $zi;
$zr = $zr2 - $zi2 + $cr;
$zi = $temp + $temp + $ci;
if ($zi2 + $zr2 > 16) {
return $i;
}
if ($i > 5000) {
return 0;
}
}
}
}
$mandelbread = new Mandelbread();
$mandelbread->index();