Add Hugo's unfinished mandelbrot fractal demo
This commit is contained in:
parent
baab639b4f
commit
c7e66e6c51
1 changed files with 34 additions and 0 deletions
34
editor/mandelbrot.c6l
Normal file
34
editor/mandelbrot.c6l
Normal file
|
@ -0,0 +1,34 @@
|
|||
;; Constants.
|
||||
width = 30
|
||||
height = 30
|
||||
size_pow_two = 16
|
||||
size = 4
|
||||
max_iteration = 100 ; How god the algorithm is
|
||||
|
||||
for x_pos do width times
|
||||
for y_pos do height times
|
||||
|
||||
is_inside_mandelbrot = 1
|
||||
x = 0 ; x_math
|
||||
y = 0 ; y_math
|
||||
|
||||
for i do max_iteration times
|
||||
;; because the set is so small we need to scale evrything up with scale.
|
||||
|
||||
;; if x^2 + y^2 > 2^2 * size^2 then outside set.
|
||||
if x * x + y * y > 4 * size_pow_two then
|
||||
is_inside_mandelbrot = 0
|
||||
else
|
||||
;; z = z^2 + c
|
||||
;; z = x + yi
|
||||
;; c = x_pos + i*y_pos
|
||||
;; z^2 = (x + yi)(x + yi) = x^2 -y^2 + 2yxi
|
||||
;; therefore: x = x^2 - y^2 + x_pos, y = 2xy + y_pos
|
||||
x = x*x - y *y + x_pos * size
|
||||
y = 2 * x * y +y_pos * size
|
||||
end
|
||||
end
|
||||
if is_inside_mandelbrot == 1 then
|
||||
draw_pixel(x_pos,y_pos)
|
||||
end
|
||||
end
|
Loading…
Add table
Reference in a new issue