forked from standupmaths/xmastree2021
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
- Loading branch information
1 parent
ca8f2b8
commit 97f3b31
Showing
21 changed files
with
6,793 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# ggjgc_bouncing_balls.py | ||
|
||
This spawns a number of balls of light in the tree and bounces them around the bounding box of the tree. | ||
|
||
Requires matts_tree_helpers.py from https://github.com/gentlegiantJGC/xmastree2021-simulator | ||
|
||
# ggjgc_bouncing_balls.csv | ||
|
||
The baked version of the python program for Matt's tree. | ||
|
||
Runs at 30fps. This is baked into the FRAME_TIME column as read by https://github.com/standupmaths/xmastree2021/pull/30 |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
# Here are the libraries I am currently using: | ||
import random | ||
from colorsys import hsv_to_rgb | ||
import numpy | ||
|
||
# You are welcome to add any of these: | ||
# import time | ||
# import math | ||
# import random | ||
# import scipy | ||
# import sys | ||
|
||
from matts_tree_helpers import get_coords_pixels, FrameManager | ||
|
||
|
||
def bouncing_balls(): | ||
# NOTE THE LEDS ARE GRB COLOUR (NOT RGB) | ||
|
||
# If you want to have user changeable values, they need to be entered from the command line | ||
# so import sys and use sys.argv[0] etc. | ||
# some_value = int(sys.argv[0]) | ||
|
||
coords, pixels = get_coords_pixels("coords_2021.csv") | ||
|
||
# YOU CAN EDIT FROM HERE DOWN | ||
|
||
frame_time = 1 / 30 | ||
|
||
ball_count = 10 | ||
|
||
# find the bounds of the LEDs | ||
bounds = [(min(axis), max(axis)) for axis in zip(*coords)] | ||
tree_height = bounds[2][1] - bounds[2][0] | ||
|
||
ball_radius = 0.1 * tree_height | ||
speed = 0.2 * tree_height | ||
|
||
ball_locations = [ | ||
[random.uniform(axis_min, axis_max) for axis_min, axis_max in bounds] | ||
for _ in range(ball_count) | ||
] | ||
ball_velocities = [] | ||
for _ in range(ball_count): | ||
v = numpy.random.rand(3) - 0.5 | ||
ball_velocities.append(speed * v / numpy.linalg.norm(v)) | ||
|
||
def hue_to_grb(hue): | ||
rgb = hsv_to_rgb(hue, 1, 1) | ||
return 255 * rgb[1], 255 * rgb[0], 255 * rgb[2] | ||
|
||
ball_colours = [hue_to_grb(i / ball_count) for i in range(ball_count)] | ||
|
||
while True: | ||
with FrameManager(frame_time): | ||
# find which ball each pixel is in (if any) | ||
for i, coord in enumerate(coords): | ||
for ball_location, ball_colour in zip(ball_locations, ball_colours): | ||
if ( | ||
sum((bax - cax) ** 2 for bax, cax in zip(ball_location, coord)) | ||
** 0.5 | ||
< ball_radius | ||
): | ||
pixels[i] = ball_colour | ||
break | ||
else: | ||
pixels[i] = (0, 0, 0) | ||
|
||
# use the show() option as rarely as possible as it takes ages | ||
# do not use show() each time you change a LED but rather wait until you have changed them all | ||
pixels.show() | ||
|
||
# find the new ball locations | ||
for i, (ball_location, ball_velocity) in enumerate( | ||
zip(ball_locations, ball_velocities) | ||
): | ||
ball_locations[i] = ball_location = [ | ||
loc + vel * frame_time | ||
for loc, vel in zip(ball_location, ball_velocity) | ||
] | ||
ball_velocities[i] = [ | ||
vel if axis_min < loc < axis_max else -vel | ||
for loc, vel, (axis_min, axis_max) in zip( | ||
ball_location, ball_velocity, bounds | ||
) | ||
] | ||
|
||
|
||
if __name__ == "__main__": | ||
bouncing_balls() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# ggjgc_rainbow_orbit.py | ||
|
||
This is a rainbow effect that rotates around the tree over time. | ||
|
||
Requires matts_tree_helpers.py from https://github.com/gentlegiantJGC/xmastree2021-simulator | ||
|
||
# ggjgc_rainbow_orbit.csv | ||
|
||
The baked version of the python program for Matt's tree. | ||
|
||
Runs at 30fps. This is baked into the FRAME_TIME column as read by https://github.com/standupmaths/xmastree2021/pull/30 |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
# Here are the libraries I am currently using: | ||
import time | ||
from colorsys import hsv_to_rgb | ||
import math | ||
|
||
# You are welcome to add any of these: | ||
# import random | ||
# import numpy | ||
# import scipy | ||
# import sys | ||
|
||
from matts_tree_helpers import get_coords_pixels, FrameManager | ||
|
||
|
||
def rainbow_oribt(): | ||
# NOTE THE LEDS ARE GRB COLOUR (NOT RGB) | ||
|
||
# If you want to have user changeable values, they need to be entered from the command line | ||
# so import sys and use sys.argv[0] etc. | ||
# some_value = int(sys.argv[0]) | ||
|
||
coords, pixels = get_coords_pixels("coords_2021.csv") | ||
|
||
# YOU CAN EDIT FROM HERE DOWN | ||
|
||
speed = 0.2 | ||
|
||
frame_time = 1 / 30 | ||
|
||
while True: | ||
with FrameManager(frame_time): | ||
# calculate the colour for each pixel | ||
t = time.time() | ||
for i, coord in enumerate(coords): | ||
tree_angle = math.atan2(coord[0], coord[1]) / (2 * math.pi) | ||
hue = (speed * t + tree_angle) % 1 | ||
rgb = hsv_to_rgb(hue, 1, 1) | ||
pixels[i] = (255 * rgb[1], 255 * rgb[0], 255 * rgb[2]) | ||
|
||
# use the show() option as rarely as possible as it takes ages | ||
# do not use show() each time you change a LED but rather wait until you have changed them all | ||
pixels.show() | ||
|
||
|
||
if __name__ == "__main__": | ||
rainbow_oribt() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# ggjgc_rainbow_scroll.py | ||
|
||
This is a rainbow effect that travels up the tree over time. | ||
|
||
Requires matts_tree_helpers.py from https://github.com/gentlegiantJGC/xmastree2021-simulator | ||
|
||
# ggjgc_rainbow_scroll.csv | ||
|
||
The baked version of the python program for Matt's tree. | ||
|
||
Runs at 30fps. This is baked into the FRAME_TIME column as read by https://github.com/standupmaths/xmastree2021/pull/30 |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
# Here are the libraries I am currently using: | ||
import time | ||
from colorsys import hsv_to_rgb | ||
|
||
# You are welcome to add any of these: | ||
# import math | ||
# import random | ||
# import numpy | ||
# import scipy | ||
# import sys | ||
|
||
from matts_tree_helpers import get_coords_pixels, FrameManager | ||
|
||
|
||
def rainbow_scroll(): | ||
# NOTE THE LEDS ARE GRB COLOUR (NOT RGB) | ||
|
||
# If you want to have user changeable values, they need to be entered from the command line | ||
# so import sys and use sys.argv[0] etc. | ||
# some_value = int(sys.argv[0]) | ||
|
||
coords, pixels = get_coords_pixels("coords_2021.csv") | ||
|
||
# YOU CAN EDIT FROM HERE DOWN | ||
|
||
y_coords = list(zip(*coords))[2] | ||
max_y = max(y_coords) | ||
min_y = min(y_coords) | ||
speed = (max_y - min_y) * 0.03 | ||
|
||
frame_time = 1 / 30 | ||
|
||
y_coords = list(zip(*coords))[2] | ||
max_y = max(y_coords) | ||
min_y = min(y_coords) | ||
|
||
while True: | ||
with FrameManager(frame_time): | ||
# calculate the colour for each pixel | ||
t = time.time() | ||
for i, coord in enumerate(coords): | ||
tree_offset = (coord[2] - min_y) / (max_y - min_y) | ||
hue = (speed * t + tree_offset) % 1 | ||
rgb = hsv_to_rgb(hue, 1, 1) | ||
pixels[i] = (255 * rgb[1], 255 * rgb[0], 255 * rgb[2]) | ||
|
||
# use the show() option as rarely as possible as it takes ages | ||
# do not use show() each time you change a LED but rather wait until you have changed them all | ||
pixels.show() | ||
|
||
|
||
if __name__ == "__main__": | ||
rainbow_scroll() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# ggjgc_rainbow_spiral.py | ||
|
||
This is a rainbow effect that spiral up the tree and the colours travel through the spiral over time. | ||
|
||
Requires matts_tree_helpers.py from https://github.com/gentlegiantJGC/xmastree2021-simulator | ||
|
||
# ggjgc_rainbow_spiral.csv | ||
|
||
The baked version of the python program for Matt's tree. | ||
|
||
Runs at 30fps. This is baked into the FRAME_TIME column as read by https://github.com/standupmaths/xmastree2021/pull/30 |
Oops, something went wrong.