-
Notifications
You must be signed in to change notification settings - Fork 8
/
multibrot.codon
67 lines (48 loc) · 1.53 KB
/
multibrot.codon
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
WIDTH = 960
HEIGHT = 960
MAX_ITERS = 200
MIN_X = -2.0
MAX_X = 0.6
MIN_Y = -1.5
MAX_Y = 1.5
def mandelbrot_kernel(c):
z = c
for i in range(MAX_ITERS):
z = z * z + c # Change this for different Multibrot sets (e.g., 2 for Mandelbrot)
if z.real * z.real + z.imag * z.imag > 4:
return i
return MAX_ITERS
def compute_mandelbrot():
t = [[0 for _ in range(WIDTH)] for _ in range(HEIGHT)] # Pixel matrix
dx = (MAX_X - MIN_X) / WIDTH
dy = (MAX_Y - MIN_Y) / HEIGHT
@par(collapse=2)
for row in range(HEIGHT):
for col in range(WIDTH):
t[row][col] = mandelbrot_kernel(complex(MIN_X + col * dx, MIN_Y + row * dy))
return t
compute_mandelbrot()
# @python
# def show_plot(tensor):
# import matplotlib.pyplot as plt
# from matplotlib import colors
# import numpy as np
# WIDTH = 960
# HEIGHT = 960
# MAX_ITERS = 200
# SCALE = 10
# DPI = 64
# numpy_array = np.zeros((HEIGHT, WIDTH), np.float64)
# for row in range(HEIGHT):
# for col in range(WIDTH):
# numpy_array.itemset((col, row), tensor[col][row])
# fig = plt.figure(1, [SCALE, SCALE * HEIGHT // WIDTH], DPI)
# ax = fig.add_axes((0.0, 0.0, 1.0, 1.0))
# light = colors.LightSource(315, 10, 0, 1, 1, 0)
# image = light.shade(numpy_array, plt.cm.hot, colors.PowerNorm(0.3), "hsv", 0, 0, 1.5)
# plt.imshow(image)
# plt.axis("off")
# plt.savefig("multibrot.codon.png")
# plt.show()
# mandelbrot = compute_mandelbrot()
# show_plot(mandelbrot)