<html><head></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><div><br></div><div>(modulo (+ position speed-for-one-step) WIDTH)&nbsp;</div><div><br></div><div>evaluates to&nbsp;(+ position speed-for-one-step) &nbsp;if it is less than WIDTH&nbsp;</div><div>and (-&nbsp;(+ position speed-for-one-step) &nbsp;WIDTH) if it is larger [roughly,&nbsp;</div><div>but definitely in your case]&nbsp;</div><div><br></div><div>Does this help?&nbsp;</div><div><br></div><br><div><div>On Mar 12, 2012, at 2:25 PM, ROELOF WOBBEN wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><div style="font-family: 'Times New Roman'; font-size: 16px;">Sorry, <br _moz_dirty=""><br _moz_dirty="">But I don't understand what the modulo and my solution work together.<br _moz_dirty=""><br _moz_dirty="">Roelof<br _moz_dirty=""><br><br><span>On 12/03/12, <b class="name">Matthias Felleisen </b> &lt;<a href="mailto:matthias@ccs.neu.edu">matthias@ccs.neu.edu</a>&gt; wrote:</span><blockquote cite="mid:A9D3FD8E-D250-4C13-8FC5-BAC05D191C75@ccs.neu.edu" class="iwcQuote" style="border-left: 1px solid rgb(0, 0, 255); padding-left: 13px; margin-left: 0pt;" type="cite"><div class="mimepart text html"><span><p><table><tbody><tr><td style="word-wrap: break-word;"><p></p><div><br></div><div>#lang racket</div><div><br></div><div>(require 2htdp/image 2htdp/universe)</div><div><br></div><div>; main : CarState -&gt; CarState</div><div>; launch the program from some initial state</div><div>(define (main r)</div><div>&nbsp; &nbsp;(big-bang 0 (on-tick tock r) (to-draw render)))</div><div><br></div><div>(define wheel-radius 5)</div><div>(define cab</div><div>&nbsp; (beside (rectangle (* 6 wheel-radius)(* 4 wheel-radius) "solid" "red")&nbsp;</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; (right-triangle (* 2 wheel-radius) (* 4 wheel-radius) "solid" "red")))</div><div>(define body</div><div>&nbsp; (rectangle (* 20 wheel-radius) (* 6 wheel-radius) "solid" "red"))</div><div>(define top</div><div>&nbsp; (above/align "right" cab body))</div><div>(define tire</div><div>&nbsp; (circle wheel-radius "solid" "black"))</div><div>(define bot</div><div>&nbsp; (beside tire</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; (rectangle (* 5 wheel-radius) (* 2 wheel-radius) "solid" "white")</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; tire))</div><div>(define auto</div><div>&nbsp; (above top bot))</div><div><br></div><div>(define WIDTH 1000)</div><div>(define SPEED (* 0.54 (image-width auto)))</div><div>(define Y-CAR 50)</div><div>(define BACKGROUND (empty-scene WIDTH 200))</div><div><br></div><div><br></div><div>; CarState -&gt; CarState</div><div>; the clock ticked; move the car by three pixels</div><div>; example:</div><div>; given: 20, expected 23</div><div>; given: 78, expected 81</div><div>(define (tock ws)&nbsp;</div><div>&nbsp; (modulo (+ ws SPEED) WIDTH)</div><div>&nbsp; #;</div><div>&nbsp; (if (&lt; ws (-(image-width BACKGROUND) (* 0.54 (image-width auto))))</div><div>&nbsp; &nbsp; &nbsp; (+ ws 3)</div><div>&nbsp; &nbsp; &nbsp; ( - ws (image-width BACKGROUND))))</div><div><br></div><div>; PositiveNumber -&gt; Image</div><div>; run the animation at the specified rate [1/28 is decent, try 1/100 too]</div><div>(define (render ws)</div><div>&nbsp; (place-image auto ws Y-CAR BACKGROUND))</div><div><br></div><div><br></div><div><div>On Mar 12, 2012, at 10:24 AM, ROELOF WOBBEN wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><div style="font-family: 'Times New Roman'; font-size: 16px;">Hello, <br><br>I have tried to make a function which display a car running on a empty-screen.<br>When the car&nbsp; is at the end. The car has to begin at the beginning.<br><br>I have made this : <br><br>(define wheel-radius 5)<br>(define cab (beside (rectangle (* 6 wheel-radius)(* 4 wheel-radius) "solid" "red")(right-triangle (* 2 wheel-radius) (* 4 wheel-radius) "solid" "red")))<br>(define body (rectangle (* 20 wheel-radius) (* 6 wheel-radius) "solid" "red"))<br>(define top (above/align "right" cab body))<br>(define tire (circle wheel-radius "solid" "black"))<br>(define bot (beside tire (rectangle (* 5 wheel-radius) (* 2 wheel-radius) "solid" "white") tire))<br>(define auto (above top bot))<br><br>(define Y-CAR 50)<br>(define BACKGROUND (empty-scene 1000 200))<br><br>; CarState -&gt; CarState<br>; the clock ticked; move the car by three pixels<br>; example:<br>; given: 20, expected 23<br>; given: 78, expected 81<br>(define (tock ws) <br>&nbsp; (if (&lt; ws (-(image-width BACKGROUND)(* 0.54&nbsp; (image-width auto))))(+ ws 3) ( - ws (image-width BACKGROUND))))<br><br>; CarState -&gt; Image<br>; place the car into a scene, according to the given world state<br>(define (render ws)<br>&nbsp; (place-image auto ws Y-CAR BACKGROUND))<br><br>; main : CarState -&gt; CarState<br>; launch the program from some initial state<br>(define (main ws)<br>&nbsp;&nbsp; (big-bang ws (on-tick tock) (to-draw render)))<br><br>But now I wonder if I can do the same with setting the variable ws to zero.<br>So like this : If ws is smaller then the image-width increase with the half width of the car. then ws = ws+ 3 else ws = 0 <br><br>Regards,<br><br>Roelof<br><br><br><br><br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br><br><br><br></div>
____________________<br> &nbsp;Racket Users list:<br> &nbsp;<a href="http://lists.racket-lang.org/users" target="_blank">http://lists.racket-lang.org/users</a><br></blockquote></div><br></td></tr></tbody></table></p></span></div></blockquote></div>
____________________<br> &nbsp;Racket Users list:<br> &nbsp;<a href="http://lists.racket-lang.org/users">http://lists.racket-lang.org/users</a><br></blockquote></div><br></body></html>