forked from pvx/litsimaja
parent
6edc15e4af
commit
8750b4d9f0
1 changed files with 63 additions and 0 deletions
@ -0,0 +1,63 @@ |
||||
#!/usr/bin/env python3 |
||||
# MegaMix |
||||
# Mis m6tted tulevad kui kuuled "MegaMix"? |
||||
# m6tlen et millal jooma saaks hakata |
||||
|
||||
from lib.Program import Program |
||||
import time |
||||
import random |
||||
|
||||
|
||||
def name(): |
||||
return 'MegaMix' |
||||
|
||||
|
||||
class MegaMix(Program): |
||||
|
||||
preset_colors = ["ffa500", "e56717", "e18b6b", "c36241", "ed9121", "f5deb3", "c35817", "ff8400", "efb261", |
||||
"c78023", "cc6600", "e66c2c", "ff8040", "ff7f50", "ffc594", "f88158", "e67451", "fc7f03", |
||||
"deaa88", "f87217", "db4200", "ff7e75"] |
||||
current_colors = [] |
||||
|
||||
# from https://chase-seibert.github.io/blog/2011/07/29/python-calculate-lighterdarker-rgb-colors.html |
||||
# edited to my own liking |
||||
def color_variant(self, hex_color, brightness_offset = 1): |
||||
""" takes a color like #87c95f and produces a lighter or darker variant """ |
||||
if len(hex_color) != 6: |
||||
print("Passed %s into color_variant(), needs to be in 87c95f format." % hex_color) |
||||
return "000000" |
||||
rgb_hex = [hex_color[x:x+2] for x in [0, 2, 4]] |
||||
new_rgb_int = [int(hex_value, 16) + brightness_offset for hex_value in rgb_hex] |
||||
new_rgb_int = [min([255, max([0, i])]) for i in new_rgb_int] # make sure new values are between 0 and 255 |
||||
# hex() produces "0x88", we want just "88" |
||||
new_hex_list = [hex(i)[2:].zfill(2) for i in new_rgb_int] |
||||
new_hex = "".join(new_hex_list) |
||||
return new_hex |
||||
|
||||
def disco(self, wait_ms): |
||||
total_length = self._lm.count_pixels() |
||||
for p in range(total_length): |
||||
if len(self.current_colors) == total_length: |
||||
color = self.current_colors[p] |
||||
color = int(self.color_variant(color, random.randint(1, 10)), 16) |
||||
if color >= 16777215: |
||||
color = int(random.choice(self.preset_colors), 16) |
||||
self.current_colors[p] = hex(color)[2:] |
||||
else: |
||||
color = int(random.choice(self.preset_colors), 16) |
||||
self.current_colors.append(hex(color)[2:]) |
||||
self._lm.set_pixel_color(p, color) |
||||
self._lm.show() |
||||
time.sleep(wait_ms / 1000.0) |
||||
|
||||
# Main program logic follows: |
||||
def run(self, args=None): |
||||
loop = False |
||||
if 'loop' in args and args['loop']: |
||||
loop = args['loop'] |
||||
|
||||
while self.get_loop().status(): |
||||
self.disco(300) |
||||
|
||||
if not loop: |
||||
break |
Loading…
Reference in new issue