-
Notifications
You must be signed in to change notification settings - Fork 0
/
mandelbrot.mar
47 lines (44 loc) · 1.31 KB
/
mandelbrot.mar
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
import ui.mar
fun main(): Never {
var texture = screen_texture()
var zoom = 1.0
var move_x = 0.0 - 0.5
var move_y = 0.0
var max_iterations = 256
var width = texture.width.to_float()
var height = texture.height.to_float()
loop {
for x in 0..texture.width do
for y in 0..texture.height do {
var pixel_real = 1.5 * {x.to_float() - {width / 2.0}}
/ {0.5 * zoom * width} + move_x
var pixel_imag = {y.to_float() - {height / 2.0}}
/ {0.5 * zoom * height} + move_y
var new_real = 0.0
var new_imag = 0.0
var old_real = 0.0
var old_imag = 0.0
var i = 0
loop {
if i == max_iterations then break
i = i + 1
old_real = new_real
old_imag = new_imag
new_real = {old_real * old_real} - {old_imag * old_imag} + pixel_real
new_imag = 2.0 * old_real * old_imag + pixel_imag
if {new_real * new_real} + {new_imag * new_imag} > 4.0 then break
}
| println("Pixel at {x}, {y} looped {i} times")
var color = if i == max_iterations
then black
else color(
i % 256,
i % 256,
i % 256,
)
texture.&.draw(x @ y, color)
}
texture.show()
zoom.& *= {11.to_float() / 10.to_float()}
}
}