xplshn
·
2025-08-13
mandelbrot.b
B
1W 80;
2H 40;
3IT 100;
4
5f 1000;
6
7gradient "@%#*+=-:. ";
8
9m(cr,ci) {
10 auto a, b, i, tmp;
11 cr -= 3*W/4;
12 ci -= H/2;
13
14 cr = (cr * f * 3) / W;
15 ci = (ci * f * 3) / H;
16
17 a = b = 0;
18
19 i = 0; while (i < IT) {
20 if (a*a/f + b*b/f > 2*2*f) {
21 return (9 - (i*10 / IT));
22 }
23
24 tmp = (a*a - b*b)/f + cr;
25 b = (a*b)/f*2 + ci;
26 a = tmp;
27
28 i++;
29 }
30
31 return (0);
32}
33
34main() {
35 extrn char, putchar;
36
37 // we can't use more precision on 16-bit systems.
38 if (&0[1] <= 2) {
39 f = 50;
40 IT = 90;
41 }
42
43 auto i, j;
44 j = 0; while (j < H) {
45 i = 0; while (i < W) {
46 putchar(char(gradient, m(i,j)));
47 i++;
48 }
49 putchar('\n');
50
51 j++;
52 }
53}