Added two easy sine-based animations

This commit is contained in:
lep 2019-01-01 13:40:17 +01:00
parent 2bf13f3448
commit 09d90b6479
5 changed files with 156 additions and 14 deletions

View File

@ -4,4 +4,6 @@ Apps = [
{"guiname": "Quadratisch", "name": "quadratic", "cmd": "apps/quadratic.py"},
{"guiname": "Pendel", "name": "pendulum", "cmd": "apps/pendlum.py"},
{"guiname": "Konvergenz", "name": "convergence", "cmd": "apps/convergence.py"},
]
{"guiname": "Sinic", "name": "sinic", "cmd": "apps/sinic.py"},
{"guiname": "Sinic 2", "name": "sinic2", "cmd": "apps/sinic2.py"},
]

View File

@ -15,7 +15,7 @@ class Slider:
self.lo = lo
self.hi = hi
self.stepSize = step
self.pos = 0
self.pos = pos
self.dir = 1
def step(self):
@ -27,12 +27,12 @@ class Slider:
self.pos += self.dir * self.stepSize
return self.pos
Sa = Slider(-10, 10, 0.1/iterations, 0) #1.1
Sb = Slider(-10, 10, 0.2/iterations, 1) #-2.1
Sc = Slider(-10, 10, 0.2/iterations, 2) #-0.33
Sd = Slider(-10, 10, 0.1/iterations, 3) #1.7
Se = Slider(-10, 10, 0.2/iterations, 4)
Sf = Slider(-10, 10, 0.01/iterations, 5)
Sa = Slider(-10, 10, 0.1/iterations, np.random.uniform(-2, 2))
Sb = Slider(-10, 10, 0.2/iterations, np.random.uniform(-2, 2))
Sc = Slider(-10, 10, 0.2/iterations, np.random.uniform(-2, 2))
Sd = Slider(-10, 10, 0.1/iterations, np.random.uniform(-2, 2))
Se = Slider(-10, 10, 0.2/iterations, np.random.uniform(-2, 2))
Sf = Slider(0, 6, 0.05/iterations, 0)
x, y = np.meshgrid(
np.linspace(-4, 4, Nx),
@ -55,14 +55,17 @@ while True:
e = Se.step()
f = Sf.step()
Sa.pos += b*0.001
Sb.pos += c*0.001
Sc.pos += d*0.001
Sd.pos += e*0.001
Se.pos += f*0.001
Sf.pos += a*0.001
curve = (np.abs(a*x**2 + b*x*y + c*y**2 + d*x + e*y + f) <= 1.5)*1
cr, cg, cb = colorsys.hsv_to_rgb(color, 1, 1)
s = np.shape(curve)
#img[:,:,0] = curve
img[:,:,0] = np.where(curve > 0, curve*cr*255, img[:,:,0])
img[:,:,1] = np.where(curve > 0, curve*cg*255, img[:,:,1])
img[:,:,2] = np.where(curve > 0, curve*cb*255, img[:,:,2])
@ -75,6 +78,5 @@ while True:
color = (color+0.01/iterations ) % 1
cb = (cb + 0.05) % 1

View File

@ -4,9 +4,13 @@ cp -f quadratic.py ../../apps/
cp -f pendlum.py ../../apps/
cp -f convergence.py ../../apps/
cp -f swifthohenberg.py ../../apps/
cp -f sinic.py ../../apps/
cp -f sinic2.py ../../apps/
chmod +x ../../apps/quadratic.py
chmod +x ../../apps/pendlum.py
chmod +x ../../apps/convergence.py
chmod +x ../../apps/swifthohenberg.py
cp -f mathpixelconf.py ../../configs/
chmod +x ../../apps/sinic.py
chmod +x ../../apps/sinic2.py
cp -f mathpixelconf.py ../../configs/

67
sinic.py Executable file
View File

@ -0,0 +1,67 @@
#!/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, -0.5)
Sb = Slider(-3, 3, 0.01, 0.5)
Sc = Slider(0, 1, 0.005, 0)
Scolor = Slider(0, 1, 0.01/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 = 1*(np.sin(c) + np.sin(np.sin(a*x) + np.cos(b*y)) - np.cos(np.sin(b*x*y) + np.cos(b*x)) <= 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)

67
sinic2.py Executable file
View File

@ -0,0 +1,67 @@
#!/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, -0.5)
Sb = Slider(-3, 3, 0.01, 0.5)
Sc = Slider(0, 1, 0.005, 0)
Scolor = Slider(0, 1, 0.01/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 = 1*(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)