Ask Your Question
1

Multiple loops in an animation?

asked 2012-08-04 12:53:38 +0100

Insaneg33k gravatar image

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 flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2012-08-23 18:30:59 +0100

oldbrad gravatar image

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()
edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2012-08-04 12:53:38 +0100

Seen: 468 times

Last updated: Aug 23 '12