Skip to content

Commit 6e8b88e

Browse files
committed
Add mandelbrot snippet
1 parent b89d95c commit 6e8b88e

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

wasm/demo/snippets/mandelbrot.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# NOTE: will take a while, up to around a minute, to run.
2+
# Expect this page to freeze.
3+
4+
w = 50.0
5+
h = 50.0
6+
7+
y = 0.0
8+
while y < h:
9+
x = 0.0
10+
while x < w:
11+
Zr, Zi, Tr, Ti = 0.0, 0.0, 0.0, 0.0
12+
Cr = 2 * x / w - 1.5
13+
Ci = 2 * y / h - 1.0
14+
15+
i = 0
16+
while i < 50 and Tr + Ti <= 4:
17+
Zi = 2 * Zr * Zi + Ci
18+
Zr = Tr - Ti + Cr
19+
Tr = Zr * Zr
20+
Ti = Zi * Zi
21+
i = i + 1
22+
23+
if Tr + Ti <= 4:
24+
print('*', end='')
25+
else:
26+
print('·', end='')
27+
28+
x = x + 1
29+
30+
print()
31+
y = y + 1

0 commit comments

Comments
 (0)