<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) </div><div><br></div><div>evaluates to (+ position speed-for-one-step) if it is less than WIDTH </div><div>and (- (+ position speed-for-one-step) WIDTH) if it is larger [roughly, </div><div>but definitely in your case] </div><div><br></div><div>Does this help? </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> <<a href="mailto:matthias@ccs.neu.edu">matthias@ccs.neu.edu</a>> 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 -> CarState</div><div>; launch the program from some initial state</div><div>(define (main r)</div><div> (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> (beside (rectangle (* 6 wheel-radius)(* 4 wheel-radius) "solid" "red") </div><div> (right-triangle (* 2 wheel-radius) (* 4 wheel-radius) "solid" "red")))</div><div>(define body</div><div> (rectangle (* 20 wheel-radius) (* 6 wheel-radius) "solid" "red"))</div><div>(define top</div><div> (above/align "right" cab body))</div><div>(define tire</div><div> (circle wheel-radius "solid" "black"))</div><div>(define bot</div><div> (beside tire</div><div> (rectangle (* 5 wheel-radius) (* 2 wheel-radius) "solid" "white")</div><div> tire))</div><div>(define auto</div><div> (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 -> 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) </div><div> (modulo (+ ws SPEED) WIDTH)</div><div> #;</div><div> (if (< ws (-(image-width BACKGROUND) (* 0.54 (image-width auto))))</div><div> (+ ws 3)</div><div> ( - ws (image-width BACKGROUND))))</div><div><br></div><div>; PositiveNumber -> 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> (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 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 -> 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> (if (< ws (-(image-width BACKGROUND)(* 0.54 (image-width auto))))(+ ws 3) ( - ws (image-width BACKGROUND))))<br><br>; CarState -> Image<br>; place the car into a scene, according to the given world state<br>(define (render ws)<br> (place-image auto ws Y-CAR BACKGROUND))<br><br>; main : CarState -> CarState<br>; launch the program from some initial state<br>(define (main ws)<br> (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> <br><br><br><br></div>
____________________<br> Racket Users list:<br> <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> Racket Users list:<br> <a href="http://lists.racket-lang.org/users">http://lists.racket-lang.org/users</a><br></blockquote></div><br></body></html>