-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsnowflakes.py
43 lines (29 loc) · 831 Bytes
/
snowflakes.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
"""
Snowflakes are symmetrical, we should only have to create a 3x3 corner and rotate
End result might resemble a star-wars spaceship instead of snowball.
Equally seasonal imho...
"""
from microbit import *
SIDE_SIZE = 3
BRIGHTNESS = {
0: 0,
1: 4,
2: 9,
}
def get_random_corner():
return [[random(3) for _ in range(SIDE_SIZE)] for _ in range(SIDE_SIZE)]
def get_flake():
flake = list(get_random_corner())
for row in flake:
row += reversed(row[:-1]) # Middle column doesn't change
for row in reversed(flake[:-1]):
flake.append(row)
return flake
def to_display(flake):
for y, row in enumerate(flake):
for x, col in enumerate(row):
display.set_pixel(x, y, BRIGHTNESS[col])
while True:
flake = get_flake()
to_display(flake)
sleep(1000)