Animating a continous loop, or rather a set of points, point for point #866
Answered
by
marcomusy
HafeezHaidari
asked this question in
Q&A
-
Hi guys, ive recently started a project in python but im already stuck. from vedo import *
def createPoints(n):
pts = np.empty((1, 3))
a = 10
b = 28
c = 8 / 3
x = 0.01
y = 0
z = 0
iterations = 0
while iterations < n:
dt = 0.01
dx = (a * (y - x)) * dt
dy = (x * (b - z)) * dt
dz = (x * y - c * z) * dt
x = x + dx
y = y + dy
z = z + dz
pts = np.append(pts, np.array([[x, y, z]]), axis=0)
iterations += 1
return pts
points = Points(createPoints(1000), r=2)
show(points, __doc__, axes=1) |
Beta Was this translation helpful? Give feedback.
Answered by
marcomusy
May 24, 2023
Replies: 1 comment 2 replies
-
Excellent choice LOL You can do something like: from vedo import *
def create_points(n):
pts = np.empty((1, 3))
a = 10
b = 28
c = 8 / 3
x = 0.01
y = 0
z = 0
iterations = 0
while iterations < n:
dt = 0.01
dx = (a * (y - x)) * dt
dy = (x * (b - z)) * dt
dz = (x * y - c * z) * dt
x = x + dx
y = y + dy
z = z + dz
pts = np.append(pts, np.array([[x, y, z]]), axis=0)
iterations += 1
return pts
pts = create_points(1000)
line = Line(pts)
pt = Point(pts[0], c='red5', r=15)
comment = Text2D(font="Calco")
plt = Plotter(axes=1, interactive=False)
plt.show(line, pt, comment, viewup='z')
# Solution1 ######################
# Animate the point along the curve
# (but cannot interact with the plot)
# for i, p in progressbar(enumerate(pts)):
# pt.pos(p)
# comment.text(f"Iteration: {i}")
# plt.render()
# Solution2 ######################
# can interact with the plot
def loop_func(event):
global i
i += 1
if i >= len(pts):
plt.timer_callback('stop', tid)
return
pt.pos(pts[i])
comment.text(f"Iteration: {i}")
plt.render()
i = 0
plt.add_callback("timer", loop_func)
tid = plt.timer_callback("start")
# stay interactive until user presses q or close the window
plt.interactive() |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
vedo
has a built in feature to draw trailing lines, (you can setn=1000
to get the full trajectory):