-
Notifications
You must be signed in to change notification settings - Fork 6
/
cascade.py
73 lines (51 loc) · 1.7 KB
/
cascade.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
from ._baseclass import ArtBaseClass
import numpy as np
from opc.colors import BLACK
from opc.hue import hsvToRgb
from math import fmod, sin, cos, sqrt
class ClearTrain(object):
def __init__(self, length):
self.length = length
self.points = [(0, 0) for i in range(length)]
self.head = 0
def add(self, matrix, x, y):
x0, y0 = self.points[self.head]
matrix.drawPixel(x0, y0, BLACK)
self.points[self.head] = (x, y)
self.head = (self.head + 1) % self.length
DELTA_AMP = 0.09
DELTA_ANG = 0.033
DELTA_HUE = 0.006
TRAIN_LEN = 16
class Art(ArtBaseClass):
description = "Color cascade (needs tuning for > 32x32)"
def __init__(self, matrix, config):
self.hue = 0
self.ang = 0
self.amp = 0
self.mult = 1+sqrt(matrix.numpix/32)/90
self.train = ClearTrain(TRAIN_LEN)
def start(self, matrix):
matrix.clear()
def refresh(self, matrix):
# this relies on the fact that the pixels we seed get multiplied and
# overfow the uint8 in intresting ways
matrix.blur(3)
matrix.buf.buf = (self.mult*matrix.buf.buf).astype(np.uint8)
self.amp += DELTA_AMP
if self.amp >= 1 and False:
self.amp = 0
self.hue += DELTA_HUE
self.ang += DELTA_ANG
xcenter = matrix.width / 2.0
ycenter = matrix.height / 2.0
amp = sin(self.amp)
tx = amp * sin(self.ang)
ty = amp * cos(self.ang)
x = xcenter + xcenter * tx
y = ycenter + ycenter * ty
color = hsvToRgb(fmod(self.hue, 1), 1, 1)
matrix.drawPixel(x, y, color)
self.train.add(matrix, x, y)
def interval(self):
return 40