A Simple Tutorial
TaichiZoo supports a subset of the Taichi APIs. Here we list the supported Taichi features:
32-bits scalar data types
ti.i32: A 32-bit signed integer
ti.f32: A 32-bit single precision floating point
Taichi internal functions
GUI draw functions:
GUI key alias
More details can be found on and .
Here, we will walkthrough how code is organized in TaichiZoo using the
Initialize the Taichi runtime. Note that for TaichiZoo, the kernel will always run on the CPU backend (via WebAssembly), regardless of the specified
Allocate a field,
pixels, to record the results.
shapeneed to be specified during this process. In taichi,
fieldis a core notion representing a multi-dimensional array.
Define a Taichi function,
complex_sqr(), to do the real computation. The types of the parameters are inferred from the calling kernel scope.
complex_sqr()accepts a single parameter
z, which represents a complex number:
z + z * i. The function returns
z * z.
Define a Taichi kernel,
paint(). This kernel simplify fills in each entry in
Initialize the GUI system. The size of the canvas in the browser is determined by the
Finally, we have some control flow code to invoke the Taichi kernels. TaichiZoo allows for control flows like
while. From python scope, we can call into Taichi kernels and GUI-related methods.
gui.set_image()directly set each pixel color. We only support grayscale for this.
gui.show()will update the canvas in the browser.
Please make sure that all kernels are defined before calling any of them.