Last active
January 29, 2024 17:17
-
-
Save aykevl/0b4031c95575a4674772216e4b0f3b64 to your computer and use it in GitHub Desktop.
FastLED animations for MicroPython, see: https://forum.micropython.org/viewtopic.php?f=15&t=3749
This file contains hidden or 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
import machine | |
import pixels | |
import array | |
import urandom | |
import time | |
# Source: | |
# https://github.com/FastLED/FastLED/blob/master/examples/Fire2012WithPalette/Fire2012WithPalette.ino | |
heatColors = array.array('L', [0x000000, | |
0x330000, 0x660000, 0x990000, 0xCC0000, 0xFF0000, | |
0xFF3300, 0xFF6600, 0xFF9900, 0xFFCC00, 0xFFFF00, | |
0xFFFF33, 0xFFFF66, 0xFFFF99, 0xFFFFCC, 0xFFFFFF]) | |
COOLING = 55 | |
SPARKING = 120 | |
l = pixels.Pixels(machine.Pin(15), 150, pixels.GRB) | |
cells = pixels.Array(len(l), 16) | |
vals = pixels.Array(len(l), 16) | |
while True: | |
start = time.ticks_us() | |
# Step 1. Cool down every cell a little | |
vals.random((((COOLING * 10) / len(l)) + 2) / 255.0) | |
cells -= vals | |
# Step 2. Heat from each cell drifts 'up' and diffuses a little | |
vals[:] = cells[:] # copy contents | |
vals.itruediv(3) | |
cells.fill(0) | |
cells[1:] += vals | |
cells[2:] += vals | |
cells[2:] += vals | |
# Step 3. Randomly ignite new 'sparks' of heat near the bottom | |
if urandom.getrandbits(8) < SPARKING: | |
y = urandom.getrandbits(3) | |
cells[y] = min(0.62, urandom.getrandbits(8)/255) | |
# Step 4. Map from heat cells to LED colors | |
l.fill_palette_array(heatColors, cells, 0.25); | |
l.write() | |
stop = time.ticks_us() | |
print('fps:', 1000000/(stop-start)) | |
time.sleep(0.10) |
This file contains hidden or 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
import machine | |
import pixels | |
import time | |
# Source: | |
# https://gist.github.com/kriegsman/964de772d64c502760e5 | |
l = pixels.Pixels(machine.Pin(15), 150, pixels.GRB) | |
hues = pixels.Array(len(l), 16) | |
sats = pixels.Array(len(l), 16) | |
vals = pixels.Array(len(l), 16) | |
hue = 0 | |
lastMillis = 0 | |
pseudoTime = 0 | |
while True: | |
start = time.ticks_us() | |
# https://gist.github.com/kriegsman/964de772d64c502760e5 | |
hue = (hue + pixels.beatsin(1.56, 0.00007, 0.00013)) % 1; | |
hues.range(hue, pixels.beatsin(1.57, 0.0001, 0.046)) | |
sats.fill(pixels.beatsin(0.34, 0.86, 0.98)) # almost invisible | |
ms = time.ticks_ms() | |
deltams = ms - lastMillis | |
lastMillis = ms | |
pseudoTime += deltams + pixels.beatsin(0.58, 0.09, 0.24) | |
vals.range((pseudoTime / 1024) % 1, pixels.beatsin(0.8, 0.097, 0.16)) | |
vals.sin() | |
vals.imul(vals) | |
brightdepth = pixels.beatsin(1.34, 0.38, 0.88) | |
vals.scale(brightdepth) | |
vals += (1 - brightdepth) | |
vals.scale(0.50) | |
l.fill_rainbow_array(hues, sats, vals) | |
l.reverse() | |
l.write() | |
stop = time.ticks_us() | |
#print('fps:', 1000000/(stop-start)) | |
time.sleep(0.01) |
This file contains hidden or 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
import pixels | |
import machine | |
import time | |
l = pixels.Pixels(machine.Pin(15), 150, pixels.GRB) | |
hue = 0 | |
while True: | |
hue = (hue + 0.005) % 1 | |
l.fill_rainbow(hue, -0.02) | |
l.write() | |
time.sleep(0.01) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment