Last active
January 2, 2018 22:47
-
-
Save Paulchen-Panther/628ac68be06f3b169cec0740c0ab1eb8 to your computer and use it in GitHub Desktop.
Fire2012 for Hyperion
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
{ | |
"name" : "Fire 2012", | |
"script" : "fire2012.py", | |
"args" : | |
{ | |
"fps" : 60, | |
"cooling" : 55, | |
"sparking" : 120 | |
} | |
} |
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
import hyperion, time, random | |
def HeatColor(temperature): | |
t192 = (temperature*192)>>8 | |
heatramp = t192 & 0x3F # 0..63 | |
heatramp <<= 2 # scale up to 0..252 | |
# now figure out which third of the spectrum we're in: | |
if t192 & 0x80: | |
# we're in the hottest third | |
r = 255 # full red | |
g = 255 # full green | |
b = heatramp # ramp up blue | |
elif t192 & 0x40: | |
# we're in the middle third | |
r = 255 # full red | |
g = heatramp # ramp up green | |
b = 0 # no blue | |
else: | |
# we're in the coolest third | |
r = heatramp # ramp up red | |
g = 0 # no green | |
b = 0 # no blue | |
return [r,g,b] | |
# Get the parameters | |
framesPerSecond = int(hyperion.args.get('fps', 60)) | |
cooling = int(hyperion.args.get('cooling', 55)) | |
sparking = int(hyperion.args.get('sparking', 120)) | |
ledCount = hyperion.ledCount | |
# Initialize the led data | |
heat = [0] * hyperion.ledCount | |
# Start the write data loop | |
while not hyperion.abort(): | |
for i in range(ledCount): | |
heat[i] = max(0, heat[i] - random.randint(0, ((cooling * 10) / ledCount) + 2)) | |
for k in range(ledCount-3, 1, -1): | |
heat[k] = (heat[k - 1] + heat[k - 2] + heat[k - 2]) / 3 | |
if random.randint(0, 255) < sparking: | |
y = random.randint(0, min(6, ledCount-1)) | |
heat[y] = min(255, heat[y] + random.randint(160, 254)) | |
leds = [] | |
for j in range(ledCount): | |
leds += [ (255*i)>>8 for i in HeatColor(heat[j]) ] | |
ledData = bytearray(leds) | |
hyperion.setColor(ledData) | |
time.sleep(1 / framesPerSecond) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment