Mandelbrot分形展示


import taichi as ti

ti.init(arch=ti.gpu)

n = 600
data = ti.Vector(3, dt=ti.f32,shape=(n, n))
@ti.func
def complex_sqr(z):
    return ti.Vector([z[0]**2 - z[1]**2, z[1] * z[0] * 2])

@ti.kernel
def paint(t: ti.f32):
    for i, j in data:  # Parallized over all pixels
        t2=0.002*t
        zoo=0.62+ti.sin(t2) * 0.38
        zoo=zoo**8
        coa=ti.cos( 0.1*(1.0-zoo)*t2 )
        sia=ti.sin( 0.1*(1.0-zoo)*t2 )
        x=(i / n - 0.5)*3
        y=(j / n - 0.5)*3
        xy = ti.Vector([x*coa-y*sia, x*sia+y*coa])
        c = ti.Vector([-.745,.186]) + xy*zoo
        z = ti.Vector([0.0, 0.0])
        iterations = 0
        while z.norm() < 4 and iterations < 200:
            z = complex_sqr(z) + c
            iterations += 1
        r=1-iterations * 0.005
        g=(r*3.0)%1.0
        b=(r*7.0)%1.0
        data[i, j] = ti.Vector([r,g,b])#1 - iterations * 0.02

gui = ti.GUI("Mandbrot", res=(n , n))
for i in range(100000):
    paint(i)
    gui.set_image(data.to_numpy())
    gui.show()

mand

3 个赞

厉害!现在Taichi有一个录制video的功能,有时间也可以试试看!
export_results

1 个赞