代码拉取完成,页面将自动刷新
# from numpy import block
import taichi as ti
ti.init(arch=ti.cuda,kernel_profiler = True )
n = 720
# 最简单的定义field方式,dense的数据结构
# pixels = ti.Vector.field(3, ti.f32, shape=(n*3,n))
# 比较高级的定义field的方式,也是dense的数据结构
# pixels = ti.Vector.field(3, ti.f32)
# block = ti.root.dense(ti.ij, (n*3, n)).place(pixels)
#使用pointer的稀疏数据结构
pixels = ti.Vector.field(3, ti.f32)
block = ti.root.pointer(ti.ij, (n*3, n)).place(pixels)
# 使用bitmasked的稀疏数据结构
# pixels = ti.Vector.field(3, ti.f32)
# block = ti.root.bitmasked(ti.ij, (n*3, n)).place(pixels)
#使用复合类型的数据结构
# vec3f = ti.types.vector(3, ti.f32)
# pixels = vec3f.field(shape=(n*3, n))
@ti.kernel
def paint(t: float):
# for i, j in pixels: #此行适用于dense数据结构 以及 一般复合类型数据结构
for i, j in ti.ndrange((0,n*3),(0,n)): #此行适用于pointer bismasked 等底层为指针的稀疏结构
pixels[i, j] = [0,0,0] #clear screen 清屏
r = i * (2.2 / n)
z = 0.9 * ti.cos(ti.random())
iterations = 0
while iterations < 10000:
z = r * z * (1 - z)
iterations += 1
jj = ti.cast(z * n * 0.9, ti.i32)
pixels[i, jj] = [ti.cos(jj*0.03), 20, 90]
gui = ti.GUI("logistic ", pixels.shape)
for i in range(100):
# gui.clear(0x000000)
paint(i * 0.03)
gui.set_image(pixels)
gui.show()
ti.print_kernel_profile_info('count')
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。