I’m new to Taichi and I wrote this dummy code for getting experience with taichi:
import taichi as ti ti.init(arch=ti.gpu) n = 640 pixels = ti.field(dtype=float, shape=(n * 2, n)) d = 0.001 goback = False @ti.kernel def paint(t: float): if((not goback) and pixels[0, 0] >= 1): goback = True elif(goback and pixels[0, 0] <= 0): goback = False for i, j in pixels: # Parallelized over all pixels if(goback): pixels[i, j] = pixels[i, j] - d else: pixels[i, j] = pixels[i, j] + d gui = ti.GUI("Test", res=(n * 2, n)) for i in range(1000000): paint(i * 0.03) gui.set_image(pixels) gui.show()
and I got a “local variable ‘goback’ referenced before assignment” for
goback, but if I remove the
goback and keep d I don’t get any exception. n and pixels also don’t cause any problem. So am I doing something wrong?
Thank you for reading,
Have a nice day!
Edit: looks like the code part is unreadable, is there a way to render it as python code?