Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
if (t + 1) % interval == 0 and visualize:
canvas.clear(0x3C733F)
canvas.circle(tc.vec(goal[0], goal[1])).radius(
pixel_radius // 2).color(0x00000).finish()
for i in range(n_balls):
if i == 0:
color = 0xCCCCCC
elif i == n_balls - 1:
color = 0x3344cc
else:
color = 0xF20530
canvas.circle(tc.vec(
x[t, i][0], x[t, i][1])).radius(pixel_radius).color(color).finish()
gui.update()
if output:
gui.screenshot('billiards/{}/{:04d}.png'.format(output, t))
compute_loss(steps - 1)
import taichi as tc
vec = tc.vec
gui = tc.core.GUI("Test GUI", tc.veci(512, 512))
canvas = gui.get_canvas()
canvas.clear(0xFFFFFF)
canvas.rect(vec(0.3, 0.3), vec(0.6,
0.6)).radius(2).color(0x000000).close().finish()
canvas.path(vec(0.3, 0.3), vec(0.6, 0.6)).radius(2).color(0x000000).finish()
canvas.circle(vec(0.5, 0.5)).radius(10).color(0xFF0000)
while True:
gui.update()
# Note that we are now differentiating the total energy w.r.t. the particle position.
# Recall that F = - \partial (total_energy) / \partial x
with ti.Tape(total_energy):
# Do the forward computation of total energy and backward propagation for x.grad, which is later used in p2g
compute_total_energy()
# It's OK not to use the computed total_energy at all, since we only need x.grad
p2g()
grid_op()
g2p()
canvas.circle(ti.vec(0.5, 0.5)).radius(70).color(0x068587).finish()
# TODO: why is visualization so slow?
for i in range(n_elements):
for j in range(3):
a, b = vertices[i, j], vertices[i, (j + 1) % 3]
canvas.path(ti.vec(x[a][0], x[a][1]), ti.vec(
x[b][0], x[b][1])).radius(1).color(0x4FB99F).finish()
for i in range(n_particles):
canvas.circle(ti.vec(x[i][0], x[i][1])).radius(2).color(0xF2B134).finish()
gui.update()
gui.screenshot("tmp/{:04d}.png".format(f))
ti.profiler_print()
def get_pt(x):
return tc.vec(x[0], x[1])
v[i] = [0, -1]
J[i] = 1
for f in range(200):
canvas.clear(0x112F41)
for s in range(150):
clear_grid()
p2g()
grid_op()
print('here')
g2p()
# TODO: why is visualization so slow?
for i in range(n_particles):
canvas.circle(ti.vec(x[i][0], x[i][1])).radius(1).color(0x068587).finish()
gui.update()
ti.profiler_print()
def get_pt(x):
return tc.vec(x[0], x[1])
total_steps = steps if not output else steps * 2
for t in range(1, total_steps):
compute_center(t - 1)
nn1(t - 1)
nn2(t - 1)
apply_spring_force(t - 1)
if use_toi:
advance_toi(t)
else:
advance_no_toi(t)
if (t + 1) % interval == 0 and visualize:
canvas.clear(0xFFFFFF)
canvas.path(tc.vec(0, ground_height),
tc.vec(1, ground_height)).color(0x0).radius(3).finish()
def circle(x, y, color):
canvas.circle(tc.vec(x, y)).color(rgb_to_hex(color)).radius(7).finish()
for i in range(n_springs):
def get_pt(x):
return tc.vec(x[0], x[1])
a = act[t - 1, i] * 0.5
r = 2
if spring_actuation[i] == 0:
a = 0
c = 0x222222
else:
canvas.clear(0xFFFFFF)
for t in range(1, total_steps):
if use_toi:
advance_toi(t)
else:
advance_no_toi(t)
if (t + 1) % interval == 0 and visualize:
color = 0x010101 * min(255, max(0, int(
(1 - t * dt / total_t) * 0.7 * 255)))
canvas.circle(tc.vec(x[t, 0][0],
x[t, 0][1])).radius(80).color(color).finish()
offset = 0.077
canvas.path(
tc.vec(0.05, ground_height - offset),
tc.vec(0.95,
ground_height - offset)).radius(2).color(0x000000).finish()
if output:
gui.screenshot('rigid_body_toi/{}/{:04d}.png'.format(output, i))
gui.update()
total_steps = steps if not output else steps * 2
for t in range(1, total_steps):
compute_center(t - 1)
nn1(t - 1)
nn2(t - 1)
apply_spring_force(t - 1)
if use_toi:
advance_toi(t)
else:
advance_no_toi(t)
if (t + 1) % interval == 0 and visualize:
canvas.clear(0xFFFFFF)
canvas.path(tc.vec(0, ground_height),
tc.vec(1, ground_height)).color(0x0).radius(3).finish()
def circle(x, y, color):
canvas.circle(tc.vec(x, y)).color(rgb_to_hex(color)).radius(7).finish()
for i in range(n_springs):
def get_pt(x):
return tc.vec(x[0], x[1])
a = act[t - 1, i] * 0.5
r = 2
if spring_actuation[i] == 0:
a = 0
c = 0x222222
else:
r = 4
def circle(x, y, color):
canvas.circle(tc.vec(x, y)).color(rgb_to_hex(color)).radius(7).finish()