function is_mandelbrot($n, $k) { $cu = new complex(0, 0); $ca = $this; for ($i = 0; $i < $n; $i++) { $square_cu = $cu->cpow($k); $cu = $square_cu->add($ca); if ($cu->mod > 2) { return mandelpercent($i, $n); } } return 255; }
<?php include 'complex.class.php'; //---- // this class gets 2 complex numbers and calculates add, sub, mul & div of them. // useful for educational use. //---- //---- 2 complex number. $n1['re'] = 2; $n1['im'] = -10; $n2['re'] = -1; $n2['im'] = 0; $c = new complex($n1, $n2); $sum = $c->add(); $sub = $c->sub(); $mul = $c->mul(); $div = $c->div(); print 'num1 = ' . $n1['re'] . ' ' . $n1['im'] . 'i' . '<br>'; print 'num2 = ' . $n2['re'] . ' ' . $n2['im'] . 'i' . '<br><br>'; print 'add = ' . $sum['re'] . ' ' . $sum['im'] . 'i' . '<br>'; print 'sub = ' . $sub['re'] . ' ' . $sub['im'] . 'i' . '<br>'; print 'mul = ' . $mul['re'] . ' ' . $mul['im'] . 'i' . '<br>'; print 'div = ' . $div['re'] . ' ' . $div['im'] . 'i' . '<br>';