# Multiple loops in an animation?

I want to use two loops to produce an animation of some gridlines changing gradient.

Essentially making all these lines:

t=var('t')
p1=Graphics()
p2=Graphics()
for i in range(-5,5,1):
p1 +=parametric_plot((t,i),(t,-5,5),color="red")
p2 +=parametric_plot((i,t),(t,-5,5),color="blue")
show(p1+p2)


Move like these lines all at once:

t=var('t')
p1=Graphics()
p2=Graphics()
v = []
for a in srange(-5,5,1):
p1 =parametric_plot((t,t*a),(t,-5,5),color="red")
p2 =parametric_plot((t*a,t),(t,-5,5),color="blue")
v.append(p1+p2)
j = animate (v, xmin=-2,ymin=-2,xmax=2,ymax=2,figsize=[2,2])
j.show()


How can I combine these two into one animation?

edit retag close merge delete

Sort by ยป oldest newest most voted

Does this give you a clue?

def move(a):
t=var('t')
p1=Graphics()
p2=Graphics()
v = []
p1 =parametric_plot((t,t*a),(t,-5,5),color="red")
p2 =parametric_plot((t*a,t),(t,-5,5),color="blue")
v.append(p1+p2)
return v

animate([move(a) for a in srange(-5,5,1)], xmin=-2,ymin=-2,xmax=2,ymax=2,figsize=[2,2]).show()


Is this what you want to achieve? I'm not sure.

def move(i):
p1=Graphics()
p2=Graphics()
p1 += parametric_plot((t,i),(t,-5,5),color="red")
p2 += parametric_plot((i,t),(t,-5,5),color="blue")
return p1+p2

animate([move(i) for i in srange(-5,5,1)]).show()

more