Skip to content

Instantly share code, notes, and snippets.

@k-ye
Last active August 31, 2021 01:51
Show Gist options
  • Save k-ye/0d93120043709a54bbb52c0b1a854816 to your computer and use it in GitHub Desktop.
Save k-ye/0d93120043709a54bbb52c0b1a854816 to your computer and use it in GitHub Desktop.
A Lissajous demo, produced by the intersection of two sinusoidal curves
import taichi as ti
ti.init(ti.gpu)
A = 0.2
B = 0.3
PI = 3.141592653
TWO_PI = PI * 2
alpha = 5.0 * TWO_PI
beta = 3.0 * TWO_PI
phase_diff = PI * 0.5
CYCLE = 10000
pos = ti.Vector.field(2, dtype=float, shape=(1,))
@ti.kernel
def run(t: float):
for i in range(40000): # Silly way to slow down FPS
pos[0][0] = A * ti.sin(alpha * t + phase_diff) + 0.5
pos[0][1] = B * ti.sin(beta * t) + 0.5
gui = ti.GUI("Lissajous", res=(512, 512))
t = 0
gui.clear(0x112F41)
gui.show()
while True:
run(float(t) / CYCLE)
t += 1
if t == CYCLE:
t = 0
gui.clear(0x112F41)
gui.circles(pos.to_numpy(), color=0xffffff)
gui.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment