-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlayer.py
67 lines (58 loc) · 2 KB
/
layer.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
#!/usr/bin/python
# -*- coding: utf-8 -*-
from cartesian_wave import CartesianWave
from polar_wave import PolarWave
import math
from vector import Vector
class Layer(object):
numWaves = None
rounding = None
perWave = None
myDebug = None
waves = []
def __init__(self, debug):
self.myDebug = debug
pass
def initBasic(self, numWaves, colorType, tD, coords, speed, len, width, height):
start = 0
stop = math.pi * 3
step = stop / numWaves
self.myDebug.dprint("Creating basic layer waves")
while start < stop:
vec = Vector(math.cos(start), math.sin(start))
wave = None
if coords == 'cartesian':
wave = CartesianWave(self.myDebug, vec, 0, tD, width / 2,
height / 2, len, (255, 255, 255), speed)
else:
wave = PolarWave(self.myDebug, vec, 0, tD, width / 2,
height / 2, len, (255, 255, 255), speed)
self.waves.append(wave)
start += step
def getValue(self, x, y):
"""
Get the value of the layer at that particular pixel
@param x: the x coordinate
@param y: the y coordinate
@return: the value of this layer's color in a list between 0 and 256 for RGB
"""
nWaves = len(self.waves)
perWave = 1.0 / nWaves
color = [0.0, 0.0, 0.0]
for i in range(nWaves):
wave = self.waves[i]
col = wave.getColor()
val = wave.getValue(x, y)
#print col[0] , val , perWave
color[0] += col[0] * val * perWave
color[1] += col[1] * val * perWave
color[2] += col[2] * val * perWave
#print col
#print color
return color
def update(self):
"""
Updates the waves one iteration
"""
for i in range(len(self.waves)):
self.waves[i].update()