-
Notifications
You must be signed in to change notification settings - Fork 0
/
mandelbrot.dei
36 lines (32 loc) · 876 Bytes
/
mandelbrot.dei
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
static IMAGE_DIM: i32 = 150; # Size of image
static MAX_ITER: i32 = 100;
static THRESHOLD: i32 = 30;
sub mandel_iter(x: f32, y: f32, count: &i32) {
let i: i32 = 1, cx: f32 = 0.0, cy: f32 = 0.0, tx: f32, ty: f32;
while (i < MAX_ITER and cx*cx + cy*cy < 4.0) {
tx = cx;
ty = cy;
cx = tx*tx - ty*ty + x;
cy = 2.0*tx*ty + y;
i = i + 1;
}
*count = i;
}
program {
let x: i32 = 0, y: i32 = 0, c: f32, it: i32;
c = (IMAGE_DIM as f32) / 2.0;
while (y < IMAGE_DIM) {
x = 0;
while (x < IMAGE_DIM) {
call mandel_iter(((x as f32)-c*0.5)/(c/2.0), ((y as f32)-c)/(c/2.0), &it);
if (it > THRESHOLD) {
print 42 as u8;
} else {
print 32 as u8;
}
x = x + 1;
}
print "\n";
y = y + 1;
}
}