<br>
<br><font size=2><tt>tutor-bounces@python.org wrote on 09/10/2007 07:29:24
AM:<br>
<br>
&gt; Hi all<br>
&gt; &nbsp;<br>
&gt; just learning python really and been using the livewires tutorial
/ worksheets to get some experience.<br>
&gt; &nbsp;<br>
&gt; I have hit an issue which is just my lack of understanding around
looping concepts and execution.<br>
&gt; &nbsp;<br>
&gt; My issue:<br>
&gt; &nbsp;<br>
&gt; in worksheet 5-robots.pdf attached, page 4 the challenge<br>
&gt; &nbsp;<br>
&gt; &quot;Challenge: Write a loop that makes the circle move smoothly
from (0,0) to (640,480): in other words, from the bottom left<br>
&gt; to the top right of the screen.&quot;<br>
&gt; &nbsp;<br>
&gt; this has got me a bit stumped because its an (x,y) co-ordinate pair
that I want to update.<br>
&gt; I think in a loop i need to draw a circle, move a circle, remove the
circle.<br>
&gt; &nbsp;<br>
&gt; I thought I needed to for loops to iterate through two ranges but
this is wrong, here is my code though!<br>
&gt; &nbsp;<br>
&gt; from livewires import *<br>
&gt; begin_graphics()<br>
&gt; &nbsp;<br>
&gt; allow_moveables()<br>
&gt; x=range(10,640,10)<br>
&gt; y=range(10,480,10)<br>
&gt; for xco in x:<br>
&gt; &nbsp; &nbsp; for yco in y:<br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp; c = circle(xco,yco,5)<br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp; move_to(c, xco,yco)<br>
&gt; # &nbsp; &nbsp; &nbsp; &nbsp;remove_from_screen(c) /*commented this
out to see output on graphics window */<br>
&gt; end_graphics()<br>
&gt; </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 &nbsp; &nbsp; &nbsp; &nbsp;position:
&nbsp;(0,0)</font>
<br><font size=2 face="sans-serif">time step: 1 &nbsp; &nbsp; &nbsp; &nbsp;position:
(64,48)</font>
<br><font size=2 face="sans-serif">time step: 2 &nbsp; &nbsp; &nbsp; &nbsp;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">&nbsp; &nbsp; &nbsp; &nbsp; c=circle(x,y,5)</font>
<br><font size=2 face="sans-serif">&nbsp; &nbsp; &nbsp; &nbsp; x+=deltax</font>
<br><font size=2 face="sans-serif">&nbsp; &nbsp; &nbsp; &nbsp; y+=deltay</font>
<br><font size=2 face="sans-serif">&nbsp; &nbsp; &nbsp; &nbsp; move_to(c,x,y)</font>
<br><font size=2 face="sans-serif">&nbsp; &nbsp; &nbsp; &nbsp; 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>