-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathcontain.py
46 lines (39 loc) · 919 Bytes
/
contain.py
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
import math
import random
import xy
def low_pass(values, alpha):
result = []
y = 0.0
for x in values:
y = y - (alpha * (y - x))
result.append(y)
return result
def normalize(values, new_lo, new_hi):
result = []
lo = min(values)
hi = max(values)
for x in values:
p = (x - lo) / (hi - lo)
x = new_lo + p * (new_hi - new_lo)
result.append(x)
return result
random.seed(13)
N = 400
noises = [random.random() * 2 - 1 for _ in range(N)]
for _ in range(3):
noises = low_pass(noises, 0.2)
noises = normalize(noises, -1, 1)
paths = []
x = 0
y = 0
m = 0.5
for i, n in enumerate(noises):
r = i + 1 #N - i
paths.append(xy.circle(x, y, r, 120))
a = n * math.pi
x += math.cos(a) * m
y += math.sin(a) * m
drawing = xy.Drawing(paths)
s = 315 / 2.0
drawing = drawing.crop(-s, -s, s, s)
drawing.render().write_to_png('contain.png')