热门

最新

红包

立Flag

投票

同城

我的

发布
billythe
书香度年华
3 年前
truebillythe

【20238217】第三章拆解完成

程序员必备的软技能-金字塔原理拆解

码友杂谈区
CSDN App 扫码分享
分享
评论
4
打赏
  • 复制链接
  • 举报
下一条:
import taichi as titi.init(arch=ti.cpu)n = 320pixels = ti.field(dtype=float, shape=(n * 2, n))@ti.funcdef complex_sqr(z): return ti.Vector([z[0]**2 - z[1]**2, z[1] * z[0] * 2])@ti.kerneldef paint(t: float): for i, j in pixels: # Parallelized over all pixels c = ti.Vector([-0.8, ti.cos(t) * 0.2]) z = ti.Vector([i / n - 1, j / n - 0.5]) * 2 iterations = 0 while z.norm() < 20 and iterations < 50: z = complex_sqr(z) + c iterations += 1 pixels[i, j] = 1 - iterations * 0.02def main(): gui = ti.GUI("Julia Set", res=(n * 2, n)) t = 0.0 while not gui.get_event(ti.GUI.ESCAPE, ti.GUI.EXIT): paint(t) t += 0.03 gui.set_image(pixels) gui.show()if __name__ == '__main__': main()
立即登录