<br>
<br><font size=2><tt>tutor-bounces@python.org wrote on 09/10/2007 07:29:24
AM:<br>
<br>
> Hi all<br>
> <br>
> just learning python really and been using the livewires tutorial
/ worksheets to get some experience.<br>
> <br>
> I have hit an issue which is just my lack of understanding around
looping concepts and execution.<br>
> <br>
> My issue:<br>
> <br>
> in worksheet 5-robots.pdf attached, page 4 the challenge<br>
> <br>
> "Challenge: Write a loop that makes the circle move smoothly
from (0,0) to (640,480): in other words, from the bottom left<br>
> to the top right of the screen."<br>
> <br>
> this has got me a bit stumped because its an (x,y) co-ordinate pair
that I want to update.<br>
> I think in a loop i need to draw a circle, move a circle, remove the
circle.<br>
> <br>
> I thought I needed to for loops to iterate through two ranges but
this is wrong, here is my code though!<br>
> <br>
> from livewires import *<br>
> begin_graphics()<br>
> <br>
> allow_moveables()<br>
> x=range(10,640,10)<br>
> y=range(10,480,10)<br>
> for xco in x:<br>
> for yco in y:<br>
> c = circle(xco,yco,5)<br>
> move_to(c, xco,yco)<br>
> # remove_from_screen(c) /*commented this
out to see output on graphics window */<br>
> end_graphics()<br>
> </tt></font>
<br>
<br>
<br><font size=2 face="sans-serif">If I understand the requirements correctly:
you are moving along the diagonal of the map.</font>
<br><font size=2 face="sans-serif">So say 100 time steps to move the distance.</font>
<br>
<br><font size=2 face="sans-serif">time step: 0 position:
(0,0)</font>
<br><font size=2 face="sans-serif">time step: 1 position:
(64,48)</font>
<br><font size=2 face="sans-serif">time step: 2 position:
(128,96)</font>
<br><font size=2 face="sans-serif">...</font>
<br>
<br><font size=2 face="sans-serif">so the new x and y move together with
a different delta so that they reach their max at the same time.</font>
<br><font size=2 face="sans-serif">Your only loop would be what time step
you are on.</font>
<br>
<br><font size=2 face="sans-serif">timesteps=100</font>
<br><font size=2 face="sans-serif">x,y =0,0</font>
<br><font size=2 face="sans-serif">deltax=640/timesteps</font>
<br><font size=2 face="sans-serif">deltay=480/timesteps</font>
<br><font size=2 face="sans-serif">for time in range (timesteps):</font>
<br><font size=2 face="sans-serif"> c=circle(x,y,5)</font>
<br><font size=2 face="sans-serif"> x+=deltax</font>
<br><font size=2 face="sans-serif"> y+=deltay</font>
<br><font size=2 face="sans-serif"> move_to(c,x,y)</font>
<br><font size=2 face="sans-serif"> remove_from_screen(c)</font>
<br>
<br><font size=2 face="sans-serif">I would think that would do the trick.</font>
<br><font size=2 face="sans-serif">But I haven't had any coffee yet this
morning, so if I missed something, let me know.</font>
<br>
<br><font size=2 face="sans-serif">Chris</font>
<br>
<br><font size=2><tt><br>
</tt></font>