53 lines
1.1 KiB
Python
53 lines
1.1 KiB
Python
import math
|
|
from pixel import Pixel
|
|
|
|
def main(pixel: Pixel, resolution: tuple, frag_coord: tuple, time: float):
|
|
uv = (frag_coord[0] / resolution[0], frag_coord[1] / resolution[1])
|
|
|
|
def hsv2rgb(h, s, v) -> tuple:
|
|
r,g,b = 0,0,0
|
|
|
|
i = int(h * 6)
|
|
f = h * 6 - i
|
|
p = v * (1 - s)
|
|
q = v * (1 - f * s)
|
|
t = v * (1 - (1 - f) * s)
|
|
|
|
o = i % 6
|
|
|
|
if o == 0:
|
|
r,g,b = v,t,p
|
|
elif o == 1:
|
|
r,g,b = q,v,p
|
|
elif o == 2:
|
|
r,g,b = p,v,t
|
|
elif o == 3:
|
|
r,g,b = p,q,v
|
|
elif o == 4:
|
|
r,g,b = t,p,v
|
|
else:
|
|
r,g,b = v,p,q
|
|
|
|
return r, g, b
|
|
|
|
def step(edge: float, value: float) -> float:
|
|
return 1.0 if value > edge else 0.0
|
|
|
|
def strip(h: float, thickness: float, y: float) -> float:
|
|
return step(y + h - thickness, step(1., y + h + thickness))
|
|
|
|
col = [0.0, 0.0, 0.0]
|
|
|
|
f = 0.0
|
|
while f < math.pi * 2:
|
|
a = strip(.5 + math.cos(uv[0] * 2. + time * 3.) * .15,
|
|
.005,
|
|
uv[1] + math.cos(uv[0] * 3. + time * 2. + f) * .25)
|
|
|
|
_col = hsv2rgb(f / math.pi / 2., 1., 1.)
|
|
for i in range(3):
|
|
col[i] += a * _col[i]
|
|
|
|
f += math.pi / 4.
|
|
|
|
pixel.background_color.set(*col) |