forked from Blinkenbunt/blup
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
63 lines
1.4 KiB
63 lines
1.4 KiB
#!/usr/bin/python3 |
|
|
|
import colorsys |
|
import random |
|
|
|
import blup.frame |
|
import blup.output |
|
import blup.animation |
|
|
|
# thanks to |
|
# http://quiteuseful.co.uk/post/96424751/beautiful-algorithms-1-fire-part-2 |
|
|
|
|
|
dim = blup.frame.FrameDimension(22,16,256,3) |
|
anim = blup.animation.Animation(dim) |
|
|
|
def getRandomColor(maxval): |
|
return list(map(lambda x: int(round(x*maxval)), colorsys.hsv_to_rgb(random.random() % 0.16666666, 1, 1))) |
|
|
|
def colorAvg(colors): |
|
r = 0 |
|
g = 0 |
|
b = 0 |
|
for c in colors: |
|
r += c[0] |
|
g += c[1] |
|
b += c[2] |
|
avg = (r,g,b) |
|
avg = list(map(lambda x: int(round(x / (len(colors) * 1.0))), avg)) |
|
return avg |
|
|
|
|
|
for i in range(100): |
|
randRow = [ getRandomColor(dim.depth - 1) for i in range(dim.width) ] |
|
print(randRow) |
|
|
|
f = blup.animation.AnimationFrame(dim, 60) |
|
|
|
for y in range(dim.height - 1, -1, -1): |
|
for x in range(dim.width): |
|
colors = [] |
|
if x >=1 : |
|
colors.append(f.getPixel(x-1,y)) |
|
if x < dim.width - 1: |
|
pass |
|
colors.append(f.getPixel(x+1,y)) |
|
if y < dim.height - 1: |
|
colors.append(f.getPixel(x, y+1)) |
|
else: |
|
#colors.append(randRow[y]) |
|
colors.append(getRandomColor(dim.depth - 1)) |
|
#colors = [randRow[x]] |
|
c = colorAvg(colors) |
|
f.setPixel(x, y, c) |
|
anim.addFrame(f) |
|
|
|
#out = blup.output.getOutput('e3blp:bbunt:4242') |
|
out = blup.output.getOutput('colorfulshell') |
|
player = blup.animation.AnimationPlayer() |
|
player.play(anim, out) |
|
|
|
|
|
|
|
|