# [Tutor] Livewires

christopher.henk at allisontransmission.com christopher.henk at allisontransmission.com
Mon Sep 10 15:33:39 CEST 2007

```tutor-bounces at python.org wrote on 09/10/2007 07:29:24 AM:

> Hi all
>
> just learning python really and been using the livewires tutorial /
worksheets to get some experience.
>
> I have hit an issue which is just my lack of understanding around
looping concepts and execution.
>
> My issue:
>
> in worksheet 5-robots.pdf attached, page 4 the challenge
>
> "Challenge: Write a loop that makes the circle move smoothly from (0,0)
to (640,480): in other words, from the bottom left
> to the top right of the screen."
>
> this has got me a bit stumped because its an (x,y) co-ordinate pair that
I want to update.
> I think in a loop i need to draw a circle, move a circle, remove the
circle.
>
> I thought I needed to for loops to iterate through two ranges but this
is wrong, here is my code though!
>
> from livewires import *
> begin_graphics()
>
> allow_moveables()
> x=range(10,640,10)
> y=range(10,480,10)
> for xco in x:
>     for yco in y:
>         c = circle(xco,yco,5)
>         move_to(c, xco,yco)
> #        remove_from_screen(c) /*commented this out to see output on
graphics window */
> end_graphics()
>

If I understand the requirements correctly: you are moving along the
diagonal of the map.
So say 100 time steps to move the distance.

time step: 0    position:  (0,0)
time step: 1    position: (64,48)
time step: 2    position: (128,96)
...

so the new x and y move together with a different delta so that they reach
their max at the same time.
Your only loop would be what time step you are on.

timesteps=100
x,y =0,0
deltax=640/timesteps
deltay=480/timesteps
for time in range (timesteps):
c=circle(x,y,5)
x+=deltax
y+=deltay
move_to(c,x,y)
remove_from_screen(c)

I would think that would do the trick.
But I haven't had any coffee yet this morning, so if I missed something,
let me know.

Chris

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20070910/d2da35b1/attachment.htm
```