Skip to content

Commit 97f3b31

Browse files
Added my examples with the source code used to generate them
Added my sequences. I wrote these using python so I have added the source python files as well as the baked CSV files. I wrote a version of the neopixel library that can be run without the tree. It visualises the tree using matplotlib and has the option to generate the CSV file from the inputs it was given. It also adds the baked CSV files for Matt's tree. Some of these are designed to run at slower frame rates so require standupmaths#30
1 parent ca8f2b8 commit 97f3b31

21 files changed

+6793
-0
lines changed
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# ggjgc_bouncing_balls.py
2+
3+
This spawns a number of balls of light in the tree and bounces them around the bounding box of the tree.
4+
5+
Requires matts_tree_helpers.py from https://github.com/gentlegiantJGC/xmastree2021-simulator
6+
7+
# ggjgc_bouncing_balls.csv
8+
9+
The baked version of the python program for Matt's tree.
10+
11+
Runs at 30fps. This is baked into the FRAME_TIME column as read by https://github.com/standupmaths/xmastree2021/pull/30

examples/ggjgc_bouncing_balls/ggjgc_bouncing_balls.csv

Lines changed: 894 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
# Here are the libraries I am currently using:
2+
import random
3+
from colorsys import hsv_to_rgb
4+
import numpy
5+
6+
# You are welcome to add any of these:
7+
# import time
8+
# import math
9+
# import random
10+
# import scipy
11+
# import sys
12+
13+
from matts_tree_helpers import get_coords_pixels, FrameManager
14+
15+
16+
def bouncing_balls():
17+
# NOTE THE LEDS ARE GRB COLOUR (NOT RGB)
18+
19+
# If you want to have user changeable values, they need to be entered from the command line
20+
# so import sys and use sys.argv[0] etc.
21+
# some_value = int(sys.argv[0])
22+
23+
coords, pixels = get_coords_pixels("coords_2021.csv")
24+
25+
# YOU CAN EDIT FROM HERE DOWN
26+
27+
frame_time = 1 / 30
28+
29+
ball_count = 10
30+
31+
# find the bounds of the LEDs
32+
bounds = [(min(axis), max(axis)) for axis in zip(*coords)]
33+
tree_height = bounds[2][1] - bounds[2][0]
34+
35+
ball_radius = 0.1 * tree_height
36+
speed = 0.2 * tree_height
37+
38+
ball_locations = [
39+
[random.uniform(axis_min, axis_max) for axis_min, axis_max in bounds]
40+
for _ in range(ball_count)
41+
]
42+
ball_velocities = []
43+
for _ in range(ball_count):
44+
v = numpy.random.rand(3) - 0.5
45+
ball_velocities.append(speed * v / numpy.linalg.norm(v))
46+
47+
def hue_to_grb(hue):
48+
rgb = hsv_to_rgb(hue, 1, 1)
49+
return 255 * rgb[1], 255 * rgb[0], 255 * rgb[2]
50+
51+
ball_colours = [hue_to_grb(i / ball_count) for i in range(ball_count)]
52+
53+
while True:
54+
with FrameManager(frame_time):
55+
# find which ball each pixel is in (if any)
56+
for i, coord in enumerate(coords):
57+
for ball_location, ball_colour in zip(ball_locations, ball_colours):
58+
if (
59+
sum((bax - cax) ** 2 for bax, cax in zip(ball_location, coord))
60+
** 0.5
61+
< ball_radius
62+
):
63+
pixels[i] = ball_colour
64+
break
65+
else:
66+
pixels[i] = (0, 0, 0)
67+
68+
# use the show() option as rarely as possible as it takes ages
69+
# do not use show() each time you change a LED but rather wait until you have changed them all
70+
pixels.show()
71+
72+
# find the new ball locations
73+
for i, (ball_location, ball_velocity) in enumerate(
74+
zip(ball_locations, ball_velocities)
75+
):
76+
ball_locations[i] = ball_location = [
77+
loc + vel * frame_time
78+
for loc, vel in zip(ball_location, ball_velocity)
79+
]
80+
ball_velocities[i] = [
81+
vel if axis_min < loc < axis_max else -vel
82+
for loc, vel, (axis_min, axis_max) in zip(
83+
ball_location, ball_velocity, bounds
84+
)
85+
]
86+
87+
88+
if __name__ == "__main__":
89+
bouncing_balls()
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# ggjgc_rainbow_orbit.py
2+
3+
This is a rainbow effect that rotates around the tree over time.
4+
5+
Requires matts_tree_helpers.py from https://github.com/gentlegiantJGC/xmastree2021-simulator
6+
7+
# ggjgc_rainbow_orbit.csv
8+
9+
The baked version of the python program for Matt's tree.
10+
11+
Runs at 30fps. This is baked into the FRAME_TIME column as read by https://github.com/standupmaths/xmastree2021/pull/30

examples/ggjgc_rainbow_orbit/ggjgc_rainbow_orbit.csv

Lines changed: 899 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# Here are the libraries I am currently using:
2+
import time
3+
from colorsys import hsv_to_rgb
4+
import math
5+
6+
# You are welcome to add any of these:
7+
# import random
8+
# import numpy
9+
# import scipy
10+
# import sys
11+
12+
from matts_tree_helpers import get_coords_pixels, FrameManager
13+
14+
15+
def rainbow_oribt():
16+
# NOTE THE LEDS ARE GRB COLOUR (NOT RGB)
17+
18+
# If you want to have user changeable values, they need to be entered from the command line
19+
# so import sys and use sys.argv[0] etc.
20+
# some_value = int(sys.argv[0])
21+
22+
coords, pixels = get_coords_pixels("coords_2021.csv")
23+
24+
# YOU CAN EDIT FROM HERE DOWN
25+
26+
speed = 0.2
27+
28+
frame_time = 1 / 30
29+
30+
while True:
31+
with FrameManager(frame_time):
32+
# calculate the colour for each pixel
33+
t = time.time()
34+
for i, coord in enumerate(coords):
35+
tree_angle = math.atan2(coord[0], coord[1]) / (2 * math.pi)
36+
hue = (speed * t + tree_angle) % 1
37+
rgb = hsv_to_rgb(hue, 1, 1)
38+
pixels[i] = (255 * rgb[1], 255 * rgb[0], 255 * rgb[2])
39+
40+
# use the show() option as rarely as possible as it takes ages
41+
# do not use show() each time you change a LED but rather wait until you have changed them all
42+
pixels.show()
43+
44+
45+
if __name__ == "__main__":
46+
rainbow_oribt()
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# ggjgc_rainbow_scroll.py
2+
3+
This is a rainbow effect that travels up the tree over time.
4+
5+
Requires matts_tree_helpers.py from https://github.com/gentlegiantJGC/xmastree2021-simulator
6+
7+
# ggjgc_rainbow_scroll.csv
8+
9+
The baked version of the python program for Matt's tree.
10+
11+
Runs at 30fps. This is baked into the FRAME_TIME column as read by https://github.com/standupmaths/xmastree2021/pull/30

examples/ggjgc_rainbow_scroll/ggjgc_rainbow_scroll.csv

Lines changed: 899 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
# Here are the libraries I am currently using:
2+
import time
3+
from colorsys import hsv_to_rgb
4+
5+
# You are welcome to add any of these:
6+
# import math
7+
# import random
8+
# import numpy
9+
# import scipy
10+
# import sys
11+
12+
from matts_tree_helpers import get_coords_pixels, FrameManager
13+
14+
15+
def rainbow_scroll():
16+
# NOTE THE LEDS ARE GRB COLOUR (NOT RGB)
17+
18+
# If you want to have user changeable values, they need to be entered from the command line
19+
# so import sys and use sys.argv[0] etc.
20+
# some_value = int(sys.argv[0])
21+
22+
coords, pixels = get_coords_pixels("coords_2021.csv")
23+
24+
# YOU CAN EDIT FROM HERE DOWN
25+
26+
y_coords = list(zip(*coords))[2]
27+
max_y = max(y_coords)
28+
min_y = min(y_coords)
29+
speed = (max_y - min_y) * 0.03
30+
31+
frame_time = 1 / 30
32+
33+
y_coords = list(zip(*coords))[2]
34+
max_y = max(y_coords)
35+
min_y = min(y_coords)
36+
37+
while True:
38+
with FrameManager(frame_time):
39+
# calculate the colour for each pixel
40+
t = time.time()
41+
for i, coord in enumerate(coords):
42+
tree_offset = (coord[2] - min_y) / (max_y - min_y)
43+
hue = (speed * t + tree_offset) % 1
44+
rgb = hsv_to_rgb(hue, 1, 1)
45+
pixels[i] = (255 * rgb[1], 255 * rgb[0], 255 * rgb[2])
46+
47+
# use the show() option as rarely as possible as it takes ages
48+
# do not use show() each time you change a LED but rather wait until you have changed them all
49+
pixels.show()
50+
51+
52+
if __name__ == "__main__":
53+
rainbow_scroll()
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# ggjgc_rainbow_spiral.py
2+
3+
This is a rainbow effect that spiral up the tree and the colours travel through the spiral over time.
4+
5+
Requires matts_tree_helpers.py from https://github.com/gentlegiantJGC/xmastree2021-simulator
6+
7+
# ggjgc_rainbow_spiral.csv
8+
9+
The baked version of the python program for Matt's tree.
10+
11+
Runs at 30fps. This is baked into the FRAME_TIME column as read by https://github.com/standupmaths/xmastree2021/pull/30

0 commit comments

Comments
 (0)