Moved mathpixel to new repo and added new default animation

This commit is contained in:
Andreas Völker
2019-01-01 12:20:54 +01:00
parent 8c5b24207a
commit cc732a519d
6 changed files with 25 additions and 290 deletions

View File

@@ -1,80 +0,0 @@
#!/usr/local/bin/python3.6
import numpy as np
import os
import sys
import time
import colorsys
Nx = int(sys.argv[1])
Ny = int(sys.argv[2])
iterations = 10
class Slider:
def __init__(self, lo, hi, step, pos=0):
self.lo = lo
self.hi = hi
self.stepSize = step
self.pos = 0
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
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)
x, y = np.meshgrid(
np.linspace(-4, 4, Nx),
np.linspace(-4, 4, Ny))
color = 1.0
img = np.zeros( [Ny, Nx, 3] )
cr = 1.0
cg = 0.5
cb = 0.25
step = 0
while True:
a = Sa.step()
b = Sb.step()
c = Sc.step()
d = Sd.step()
e = Se.step()
f = Sf.step()
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])
step += 1
if step % iterations == 0:
out = img.reshape((Nx*Ny*3,)).astype(np.uint8)
os.write(1, out.tobytes())
time.sleep(0.01)
color = (color+0.01/iterations ) % 1
cb = (cb + 0.05) % 1