My 500 LED xmas tree

Overview

xmastree2020

This repository contains the code used for Matt's Christmas tree, as featured in "I wired my tree with 500 LED lights and calculated their 3D coordinates".

xmaslights-spin.py is the original source code from the video. Code in the examples folder has been provided by other contributors!

Usage

This is a Python project which depends on board for representing an n-dimensional board, and neopixel for communicating with the LEDs.

With these packages installed, run xmaslights-spin.py.

Contributing

You're welcome to contribute! There are a few different places that your PR could target:

  • Small bug fixes, as well as small changes that significantly increase usability, will be accepted directly in to the original code.

  • The examples folder has been created as a place for any effects contained within a single Python file. Files should be named based on the effect - fire.py for example.

  • If you've done a bigger bit of work, consider keeping this in your own repository, and opening a PR to update the Further Work section below.

Further Work

Links to larger projects based on this one

Comments
  • Conway's Tree of Life

    Conway's Tree of Life

    Not sure how you want folks to submit animations, but I spent a little bit tonight making Conway's Game of Life on your tree. It was really fun - thank you for setting it up!

    Side note: I think this could be made a LOT prettier by fading the LEDs out rather than just turning them off and on, but I didn't have time to implement that visual feature. There are also probably other Cellular Automata rules that will look prettier on a tree. Should be easy enough to add whatever rule you like to the transition_function.

    Another fun thing you could try is initializing the states to try to create gliders. Might be impossible given it's being computed on a graph, not a grid, though.

    opened by kevroy314 6
  • Dan/3d octahedron

    Dan/3d octahedron

    • Grapher file removed
    • Octahedron now spins in a random direction for a while, switching axes periodically to keep things interesting.
    • Octahedron radius "ballradius" can be changed. Set ballradius to a large number to illluminate the entire tree!
    • colourA through colourH can be modified to create a personalized holiday spirit!
    opened by danielkwalsh 5
  • 2 old school demo effects

    2 old school demo effects

    3D Plasma and 3D Fire.

    My simulator being dumb at the moment it is really hard to see how plasma would render on a real 3D Christmas tree and would probably need a lot of tweaks.

    I think 3D fire do works fine, probably would need some tweaks to run properly on the real tree.

    opened by Godzil 5
  • Fire animation

    Fire animation

    I wasn't able to test this for real, so I hope it works...

    The animation it produces should look something like this (except that it will continue smoothly instead of stuttering after each loop...):

    The animation is designed to tile horizontally, so I map it onto the tree by taking the angle of an LED from the central axis and using that as the X coordinate in the animation frame.

    opened by Diggsey 5
  • Quantum simulation effect

    Quantum simulation effect

    Each coordinate is assigned a bit string such that the Hamming distance can only be large between two bit strings if the Euclidean distance between the coordinates is large. That's something that's tricky even on a grid, and worse on a Christmas tree!

    The lights are then controlled by a simulation of a quantum computer. I basically use the same effect as I once wrote a blog about here.

    The script uses the actual board and neopixel when available, and otherwise tries to use sim.py from #5.

    opened by quantumjim 4
  • can't install neopixel

    can't install neopixel

    Following the instructions at https://learn.adafruit.com/neopixels-on-raspberry-pi/python-usage on how to install the neopixel library, I get this:

    Collecting sysv-ipc (from Adafruit-Blinka->adafruit-circuitpython-neopixel)
      Using cached https://files.pythonhosted.org/packages/0c/d7/5d2f861155e9749f981e6c58f2a482d3ab458bf8c35ae24d4b4d5899ebf9/sysv_ipc-1.1.0.tar.gz
        Complete output from command python setup.py egg_info:
        Traceback (most recent call last):
          File "<string>", line 1, in <module>
          File "/tmp/pip-build-p029qfz7/sysv-ipc/setup.py", line 11, in <module>
            import prober
          File "/tmp/pip-build-p029qfz7/sysv-ipc/prober.py", line 137
            d["SYSV_IPC_VERSION"] = f'"{version}"'
                                                 ^
        SyntaxError: invalid syntax
    
    

    I checked that I have python3 installed.

    The second command doesn't work either:

    pi@kano4:~/xmastree2020-main $ sudo python3 -m pip install --force-reinstall adafruit-blinka
    Collecting adafruit-blinka
      Using cached https://www.piwheels.org/simple/adafruit-blinka/Adafruit_Blinka-5.13.1-py3-none-any.whl
    Collecting sysv-ipc (from adafruit-blinka)
      Using cached https://files.pythonhosted.org/packages/0c/d7/5d2f861155e9749f981e6c58f2a482d3ab458bf8c35ae24d4b4d5899ebf9/sysv_ipc-1.1.0.tar.gz
        Complete output from command python setup.py egg_info:
        Traceback (most recent call last):
          File "<string>", line 1, in <module>
          File "/tmp/pip-build-5yeeu738/sysv-ipc/setup.py", line 11, in <module>
            import prober
          File "/tmp/pip-build-5yeeu738/sysv-ipc/prober.py", line 137
            d["SYSV_IPC_VERSION"] = f'"{version}"'
                                                 ^
        SyntaxError: invalid syntax
    
    

    Ignoring the error and trying to run anyway didn't work...

    pi@kano4:~/xmastree2020-main $ python3 xmaslights-spin.py
    Traceback (most recent call last):
      File "xmaslights-spin.py", line 144, in <module>
        xmaslight()
      File "xmaslights-spin.py", line 9, in xmaslight
        import neopixel
    ImportError: No module named 'neopixel'
    pi@kano4:~/xmastree2020-main $ python xmaslights-spin.py
    Traceback (most recent call last):
      File "xmaslights-spin.py", line 144, in <module>
        xmaslight()
      File "xmaslights-spin.py", line 43, in xmaslight
        pixels = neopixel.NeoPixel(board.D18, PIXEL_COUNT, auto_write=False)
    AttributeError: 'module' object has no attribute 'NeoPixel'
    
    

    Any suggestions what to do next? (btw python newbie, so can I ask you to spell it out and not assume I know much about how python works)

    thanks

    Graham

    opened by gtoal 3
  • Lightning inspiration

    Lightning inspiration

    Based of my previous one, now instead searching for x number of nodes in a semi-sphere below and then jumping to one least "bright" or random if all nodes are the same brightness. Didn't send this in by mail to Matt, I think it was enough with first one :) I guess it's similar to the falling spheres they had in their video in many ways, except this jumps around a bit more hectic :) Also, probably some mistakes, but eh, works atleast somewhat.

    Many thanks to @DutChen18, using his simulator from Pull Request #5 to test!

    opened by Tirine 3
  • Real-Time 3D Octahedron Rotation Graphic

    Real-Time 3D Octahedron Rotation Graphic

    Real-Time 3D Octahedron Rotation Graphic.

    What this code does: This code generalizes the two-color rotation effect that Matt Parker showed in his video (https://www.youtube.com/watch?v=TvlpIojusBE) to an eight-color version, where the cones spanning the octahedron's faces partition the tree into eight regions with customizable colors. The octahedron animates by rotating along an arbitrary, user-configurable direction.

    • Colors are defined using colourA through colorH. • Rotation speed is controlled by adjusting the 'theta' variable, representing the angle in radians by which the octahedron rotates in a single timestep. • [ux, uy, uz] is the UNIT vector about which the octahedron rotates. This vector must have unit norm.

    Future expansions: • Allow rotation direction to wander randomly over time. • Allow colored octahedron faces to evolve over time • Allow center of rotation to wander randomly over time. • Allow radial dependence in color. Fading out as r increases, or perhaps a hard cutoff at a radius R where the color abruptly becomes black, to form a colored sphere rotating within the Christmas tree. • Allow the number of faces to also be configurable, so other platonic solids can be used. • Use this rotation effect as a "filter" to apply to other light effects

    opened by danielkwalsh 3
  • Traveling Santa

    Traveling Santa

    As Santa prepares his reindeer and sleigh, there's a problem NP hard here at play. Your Christmas tree bulbs were all very nice, but a random walk through them will not suffice,

    To light them all up Santa will need, a computed path to help him with speed. To hop here and there like a quick-flying raven, for him I computed the Traveling Salesman.

    So what I've done is I took the coordinates of the bulbs and computed the shortest Hamiltonian Path through them with the assumption that they form a fully connected graph of straight-line distances.

    I used the 2-opt local search algorithm to find the solution and it took a while to compute (almost as long as it took me to settle on a rhyme for the word "salesman"). The solution is hardcoded into the script so you will not have to wait for it to compute every time you run it.

    The algorithm finds an approximation only, so the path I found may not be the actual best path. It may qualify for the title of a Parker path though.

    Enjoy the Santa bulb running around your Christmas tree. : )

    I'm also attaching a visualization of the two paths. The blue path represents the cable on which the bulbs are (I'm assuming) and the red path represents the Hamiltonian path solution:

    visualization

    opened by SimonRovder 3
  • Add RGB spheres animation

    Add RGB spheres animation

    This adds a script that will simulate RGB spheres.

    3 spheres are created. Each of the 3 spheres represents one of the RGB primary colors.

    During the initialization, the origin of each sphere is chosen such that they are approximately as far away from each other as possible. Each origin will be at one of the given LED coordinates.

    The sphere’s radii will increase and decrease during the animation. The initial radius is chosen at random for each sphere. For each enlarge or shrinking cycle, the green sphere uses 120 animation frames the red sphere uses 160 frames, and the blue sphere uses 200 frames

    Each RGB color component is calculated using the distance to the corresponding sphere. Specifically, the formular used is 255 * (1 - dist / max_dist) ^ 3, where max_dist is the maximum distance any of the LED can have from the sphere.

    The sphere changes from enlarging to shrinking, when the current radius is approximately equal to its max_dist. It switches back to enlarging, once its current radius is approximately 0.

    I tested this already using the simulator provided in #5.

    opened by NeunEinser 3
  • Rainbow and fireplace effects

    Rainbow and fireplace effects

    Slight refactor into 3 functions, containing original effects and two new effects, a rainbow that moves vertically and spins and a fireplace for the cozy winter months. Also added a switch at the top to test with 3d scatter plot to verify code. Simply just need to comment/uncomment the *_lights functions in the main xmaslight function to pick the corresponding effect.

    Not sure if the LED values I choose are bright enough, but I did include a scaling in the USE_PLOTS that could potentially be taken out of the if statement: colors = np.array(colors) * SCALE_FACTOR

    opened by tealnoise 3
  • Make colors RGB again

    Make colors RGB again

    The hardware never considered the lights to be in GRB order. However, there was something else going on. Basically, the library is written to always allow you to specify colors in RGB order, but it can then write those colors to the lights in different orders (mainly RGB or GRB) and for some reason, by default it assumes your LEDs take the colors in GRB order.

    As such, it was rewriting the RGB colors to GRB format, even though the LEDs actually took them in RGB order, which made the colors wrong. Writing the colors as GRB is the opposite of this, so it undoes the change, making it seem that's the right way to specify the colors.

    By just telling the library that the LEDs are taking the colors in RGB order, you can specify the colors the way you normally do: RGB.

    opened by JasperHorn 0
  • How to map the LEDs

    How to map the LEDs

    So in the video you say there is much better ways to track the LEDs. Fun Fact, there is not. is there any way we can grab a copy of your tracking code and a list of dependency's. Not after a full tutorial just enough that I can stumble uphill instead of downhill.

    P.S. Love your work.

    opened by sirtoxic 1
  • Functional animation

    Functional animation

    Calculation of pixel color calculated by a function that accepts 4d space+time coordinates of current LED and current time.

    Animation is stateless - no state is kept between calls to the animation function or between animation loops. Animation rate and form are determined only by the color function. The color functions also uses parameters extensively so many aspects of the animation can be set without re-writing the math.

    Several samples are provided, starting from a simple blink to a few more complex ones.

    Visualization using matplotlib - many thanks to @DutChen18 ! #5

    Intended to fix #18

    opened by qt1 3
  • candycane stripes with adjustable swirl

    candycane stripes with adjustable swirl

    Candycane stripes with adjustable swirl.

    https://user-images.githubusercontent.com/116757/103164481-a9f7d980-47d9-11eb-9a7e-e9633a680c55.mp4

    https://user-images.githubusercontent.com/116757/103164482-ab290680-47d9-11eb-9699-0435fe468ed5.mp4

    opened by jweather 3
Owner
Stand-up Maths
Various bits of code from Matt Parker's projects
Stand-up Maths
An emulated LED scoreboard for Major League Baseball ⚾

An LED scoreboard for Major League Baseball. Displays a live scoreboard for your team's game on that day.

Tyler Porter 8 Apr 8, 2022
Rasberry Pie GPIO memory game. Press the corresponding key to the lit LED.

RPie-keyboard-game Rasberry Pie GPIO memory game. Press the corresponding key to the lit LED. Randem LED (general output) is lit up on rasberrypi rand

Shawn Dowling 1 Oct 24, 2021
The example shows using local self-hosted runners on-premises by making use of a runner on a Raspberry Pi with LED's attached to it

The example shows using local self-hosted runners on-premises by making use of a runner on a Raspberry Pi with LED's attached to it

Martin Woodward 6 Nov 13, 2021
LED effects plugin for klipper

This plugin allows Klipper to run effects and animations on addressable LEDs, such as Neopixels, WS2812 or SK6812.

Julian Schill 238 Jan 4, 2023
Run this code to blink your ThinkPad LED with a hidden mysterious Morse code! ;)

TMorse Run this code to blink your ThinkPad LED with a hidden mysterious Morse code! ;) Compatible with python3.9+. No third-party library is required

Mahyar 2 Jul 11, 2022
A simple program to make MSI Modern 15 speaker and microphone mute led work.

MSI Modern 15 sound led fixup for linux A simple program to fix the MSI Modern 15 speaker and microphone mute LEDs. Installation Requirements pulsectl

Seyed Danial Movahed 4 Oct 18, 2022
SPI driven CircuitPython driver for PCA9745B constant current LED driver.

Introduction THIS IS VERY MUCH ALPHA AND IN ACTIVE DEVELOPMENT. THINGS WILL BREAK! THIS MAY ALSO BREAK YOUR THINGS! SPI driven CircuitPython driver fo

Andrew Ferguson 1 Jan 14, 2022
This is an incredible led matrix simulation using the ultimate mosaik co-simulation framework.

This project uses the mosaik co-simulation framework, developed by the brilliant developers at the high-ranked Offis institue for computer science, Oldenburg, Germany, to simulate multidimensional LED matrices.

Felix 1 Jan 28, 2022
Code and build instructions for Snap, a simple Raspberry Pi and LED machine to show you how expensive the electricyty is at the moment

Code and build instructions for Snap, a simple Raspberry Pi and LED machine to show you how expensive the electricyty is at the moment. On row of LEDs shows the cost of the hour, the other row the cost of the day.

Johan Jonk Stenström 3 Sep 8, 2022
Xmas-Tree-GIF-Tool - Convert any given animated gif file into an animation in GIFT CSV format

This repo is made to participate in Matt Parker's XmasTree 2021 event. Convert a

Aven Zitzelberger 2 Dec 30, 2021
Build Xmas cards with user inputs

Automatically build Xmas cards with user inputs

Anand 9 Jan 25, 2022
Christmas face app for Decathlon xmas coding party!

Christmas Face Application Use this library to create the perfect picture for your christmas cards! Done by Hasib Zunair, Guillaume Brassard and Samue

Hasib Zunair 4 Dec 20, 2021
Fixes 500+ mislabeled MURA images

In this repository, new csv files are provided that fixes 500+ mislabeled MURA x-rays for all categories. The mislabeled x-rays mainly had hardware in them. This project only fixes the false negatives for now.

Pieter Zeilstra 4 May 18, 2022
SUPPORTS 500 GROUPS NO NEED OF BOT 😉

LOVELY RADIO SUPPORTS 500 GROUPS NO NEED OF BOT ?? Requirements Telegram API_ID , API_HASH and SESSION_NAME HEROKU Get YouTube live stream link instal

null 6 Nov 24, 2021
A simple port scanner for Web/ip scanning Port 0/500 editable inside the .py file

Simple-Port-Scanner a simple port scanner for Web/ip scanning Port 0/500 editable inside the .py file Open Cmd/Terminal Cmd Downloads Run Command: pip

YABOI 1 Nov 22, 2021
Web scraped S&P 500 Data from Wikipedia using Pandas and performed Exploratory Data Analysis on the data.

Web scraped S&P 500 Data from Wikipedia using Pandas and performed Exploratory Data Analysis on the data. Then used Yahoo Finance to get the related stock data and displayed them in the form of charts.

Samrat Mitra 3 Sep 9, 2022
Product-Review-Summarizer - Created a product review summarizer which clustered thousands of product reviews and summarized them into a maximum of 500 characters, saving precious time of customers and helping them make a wise buying decision.

Product-Review-Summarizer - Created a product review summarizer which clustered thousands of product reviews and summarized them into a maximum of 500 characters, saving precious time of customers and helping them make a wise buying decision.

Parv Bhatt 1 Jan 1, 2022
Bootstrapping your personal Web3 info hub from more than 500 RSS Feeds.

RSS Aggregator for Web3 (or ?? RAW for short) Bootstrapping your personal Web3 info hub from more than 500 RSS Feeds. What is RSS or Reader Services?

ChainFeeds 1.8k Dec 29, 2022
The Official Twilio SendGrid Led, Community Driven Python API Library

The default branch name for this repository has been changed to main as of 07/27/2020. This library allows you to quickly and easily use the SendGrid

Twilio SendGrid 1.4k Jan 7, 2023
LedFx is a network based LED effect controller with support for advanced real-time audio effects

Welcome to LedFx ✨ -Making music come alive! LedFx website: https://ledfx.app/ What is LedFx? What LedFx offers is the ability to take audio input, an

null 786 Jan 2, 2023