| 1 |
module buddhabrot; |
|---|
| 2 |
|
|---|
| 3 |
import qd, tools.base, std.math; |
|---|
| 4 |
|
|---|
| 5 |
void main() { |
|---|
| 6 |
screen(1024, 768); |
|---|
| 7 |
cls(Black); |
|---|
| 8 |
auto tx = translate(0, screen.w, -2.0, 2.0), ty = translate(0, screen.h, -2.0, 2.0); |
|---|
| 9 |
auto backx = translate(-2.0, 2.0, 0, screen.w), backy = translate(-2.0, 2.0, 0, screen.h); |
|---|
| 10 |
int aa = 4; |
|---|
| 11 |
for (int y = 0; y < screen.h; ++y) { |
|---|
| 12 |
for (int x = 1; x < screen.w; ++x) { |
|---|
| 13 |
for (int yaa = 0; yaa < aa; ++yaa) { |
|---|
| 14 |
for (int xaa = 0; xaa < aa; ++xaa) { |
|---|
| 15 |
creal start = tx(x + xaa * 1.0 / aa) * 1fi + ty(y + yaa * 1.0 / aa), c = 0.0 + 0.0i; |
|---|
| 16 |
int iters = 4000; |
|---|
| 17 |
int bailout = -1; |
|---|
| 18 |
for (int i = 0; i < iters; ++i) { |
|---|
| 19 |
c = c * c + start; |
|---|
| 20 |
if (sqrt(c.re * c.re + c.im * c.im) > 2) { bailout = i; break; } |
|---|
| 21 |
} |
|---|
| 22 |
if (bailout == -1) continue; |
|---|
| 23 |
c = 0.0 + 0.0i; |
|---|
| 24 |
for (int i = 0; i < bailout; ++i) { |
|---|
| 25 |
c = c * c + start; |
|---|
| 26 |
int round(float f) { return cast(int) (f + 0.5); } |
|---|
| 27 |
auto bx = round(backx(c.im)), by = round(backy(c.re)); |
|---|
| 28 |
if (bx < 1 || by < 0 || bx !< screen.w || by !< screen.h) break; |
|---|
| 29 |
auto target = pget(bx, by); |
|---|
| 30 |
if (i < 20) { if (target.r < 255) target.r ++; } |
|---|
| 31 |
else if (i < 200) { if (target.g < 255) target.g ++; } |
|---|
| 32 |
else /*if (bailout < 2000)*/ { if (target.b < 255) target.b ++; } |
|---|
| 33 |
pset(bx, by, target); |
|---|
| 34 |
} |
|---|
| 35 |
} |
|---|
| 36 |
} |
|---|
| 37 |
} |
|---|
| 38 |
pset(0, y, White); |
|---|
| 39 |
flip; events; |
|---|
| 40 |
} |
|---|
| 41 |
while (true) { flip; events; } |
|---|
| 42 |
} |
|---|