-
Notifications
You must be signed in to change notification settings - Fork 0
/
northern_lights.py
65 lines (46 loc) · 2.07 KB
/
northern_lights.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
from math import floor
import random
from geometer import *
def draw(canvas):
canvas.set_stroke_width(random.random() * 0.4 + 0.1)
x_offset = canvas.width / 20
y_offset = canvas.height / 20
p1 = Point(x_offset, canvas.center.y)
p2 = Point(canvas.width - x_offset, canvas.center.y)
x = random.random() * canvas.width / 2.0 + canvas.width / 4.0
sheets = 24
for i in range(sheets):
canvas.set_stroke_color(base1.hair()) # alpha(random.random() * 0.5 + 0.25))
x += 100
y = (canvas.height / sheets) * i + y_offset
p3 = Point(x, y)
line1 = Line(center=p3, to_point=p1)
line1.extended().draw(canvas)
left_lines = [line1]
line2 = Line(center=p3, to_point=p2)
line2.extended().draw(canvas)
right_lines = [line2]
left_distances = sorted(random.sample(range(int(floor(line1.length))), 5))
left_points = [line1.point_from_center(d) for d in left_distances]
right_lines.extend([Line(center=l_p, to_point=p2) for l_p in left_points])
right_distances = sorted(random.sample(range(int(floor(line2.length))), 5))
right_points = [line2.point_from_center(d) for d in right_distances]
left_lines.extend([Line(center=r_p, to_point=p1) for r_p in right_points])
left_pairs = [left_lines[x:x + 2] for x in range(0, len(left_lines), 2)]
right_pairs = [right_lines[x:x + 2] for x in range(0, len(right_lines), 2)]
for r1, r2 in right_pairs:
r1.extended().draw(canvas)
r2.extended().draw(canvas)
for l1, l2 in left_pairs:
s = Shape(0)
s.points = [
l1.intersection_with(r1),
l1.intersection_with(r2),
l2.intersection_with(r2),
l2.intersection_with(r1)
]
l1.extended().draw(canvas)
l2.extended().draw(canvas)
fill = band(fills, i, sheets)
canvas.set_fill_color(fill.alpha(1.0 / 8))
s.draw(canvas)