cmplx.py

Created by schraf

Created on May 04, 2023

921 Bytes


from cmath import *
from kandinsky import *
from time import sleep

def f0(z): return z
def f1(z): return z / (1 - z)
def f2(z): return (z - 1) / (z ** 2 + z + 1)
def f3(z): return  (1 + 1j) * z / (z ** 2 + 1)


eq0 = ((-.2, 1.2, -1, .5), f0, (), 1024)
eq1 = ((-.2, 1.2, -1, .5), f1, ((1, 0)), 510)
eq2 = ((-1, 3, -2, 2), f2, (), 255)
eq3 = ((-.8, .8, -1.2, 1.2), f3, ((0, 1), (0, -1)), 800)

w, h = 320, 222
n = 0

while True:
    (xmin, xmax, ymin, ymax), f, bad, coeff = eval('eq'+str(n))
    for i in range(w):
        x = xmin + (xmax - xmin) * i / w    
        for j in range(h):
            y = ymin + (ymax - ymin) * j / h
            if (x, y) not in bad:
                z = x + 1j * y
                z_theta = phase(f(z))
                c = int(coeff * z_theta / 2 / pi % 256)
                set_pixel(i, j, (c, c, c))
    sleep(2)
    fill_rect(0, 0, 320, 222, (255,) * 3)
    n = (n + 1) % 4