Newton Basin Project
Open Source Your Knowledge, Become a Contributor
Technology knowledge has to be shared and made accessible for free. Join the movement.
Here is a slightly more interesting output
Note that here is the Heaviside step function but it's applied to the (shifted) modulus of a function rather than a variable. That is, we are interested in roots of
Is 7 in the basin of attraction of any roots of the function f(z)?
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
from PIL import Image, ImageDraw
from basin import cubicbrot, MAX_ITER, sinebrot
from collections import defaultdict
from math import floor, ceil
def linear_interpolation(color1, color2, t):
return color1 * (1 - t) + color2 * t
# Image size (pixels)
WIDTH = 1900
HEIGHT = 400
# Plot window
RE_START = -2
RE_END = 8
IM_START = -1
IM_END = 1
histogram = defaultdict(lambda: 0)
values = {}
im = Image.new('RGB', (WIDTH, HEIGHT), (0, 0, 0))
draw = ImageDraw.Draw(im)
for x in range(0, WIDTH):
for y in range(0, HEIGHT):
# Convert pixel coordinate to complex number
c = complex(RE_START + (x / WIDTH) * (RE_END - RE_START),
IM_START + (y / HEIGHT) * (IM_END - IM_START))
# Compute the number of iterations
m = sinebrot(c)
values[(x, y)] = m
if m < MAX_ITER:
histogram[floor(m)] += 1
total = sum(histogram.values())
hues = []
h = 0
for i in range(MAX_ITER):
h += histogram[i] / total
hues.append(h)
hues.append(h)
im = Image.new('HSV', (WIDTH, HEIGHT), (0, 0, 0))
draw = ImageDraw.Draw(im)
for x in range(0, WIDTH):
for y in range(0, HEIGHT):
m = values[(x, y)]
# The color depends on the number of iterations
Enter to Rename, Shift+Enter to Preview
1
from math import exp
Enter to Rename, Shift+Enter to Preview
Open Source Your Knowledge: become a Contributor and help others learn. Create New Content