pixelserver2/apps/sinic2.py
2024-10-28 18:10:03 +01:00

69 lines
1.4 KiB
Python
Executable File

#!/usr/bin/env python3
import numpy as np
import os
import sys
import time
import colorsys
Nx = int(sys.argv[1])
Ny = int(sys.argv[2])
iterations = 2
class Slider:
def __init__(self, lo, hi, step, pos=0):
self.lo = lo
self.hi = hi
self.stepSize = step
self.pos = pos
self.dir = 1
def step(self):
if self.pos >= self.hi:
self.dir = -1
elif self.pos <= self.lo:
self.dir = 1
self.pos += self.dir * self.stepSize
return self.pos
x, y = np.meshgrid(
np.linspace(-2, 2, Nx),
np.linspace(-2, 2, Ny))
img = np.zeros( [Ny, Nx, 3] )
Sa = Slider(-3, 3, 0.01, np.random.uniform(-1, 1))
Sb = Slider(-3, 3, 0.01, np.random.uniform(-1, 1))
Sc = Slider(0, 1, 0.005, np.random.uniform(-1, 1))
Scolor = Slider(0, 1, 0.001/iterations, 0)
step = 0
while True:
a = Sa.step()
b = Sb.step()
c = Sc.step()
Sa.pos += b*0.001
Sb.pos += c*0.001
Sc.pos += a*0.001
curve = np.clip(c+np.sin(a*x*x-b*y*y)-np.sin(a*x+b*y)-np.cos(a*b*x*y), 0, 1)
cr, cg, cb = colorsys.hsv_to_rgb(Scolor.step(), 1, 1)
img[:,:,0] = curve*cr*255
img[:,:,1] = curve*cg*255
img[:,:,2] = curve*cb*255
step += 1
if step % iterations == 0:
out = img.reshape((Nx*Ny*3,)).astype(np.uint8)
os.write(1, out.tobytes())
time.sleep(0.01)