<html><head></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><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 _moz_dirty=""><br _moz_dirty="">I have tried to make a function which display a car running on a empty-screen.<br _moz_dirty="">When the car is at the end. The car has to begin at the beginning.<br _moz_dirty=""><br _moz_dirty="">I have made this : <br _moz_dirty=""><br _moz_dirty="">(define wheel-radius 5)<br _moz_dirty="">(define cab (beside (rectangle (* 6 wheel-radius)(* 4 wheel-radius) "solid" "red")(right-triangle (* 2 wheel-radius) (* 4 wheel-radius) "solid" "red")))<br _moz_dirty="">(define body (rectangle (* 20 wheel-radius) (* 6 wheel-radius) "solid" "red"))<br _moz_dirty="">(define top (above/align "right" cab body))<br _moz_dirty="">(define tire (circle wheel-radius "solid" "black"))<br _moz_dirty="">(define bot (beside tire (rectangle (* 5 wheel-radius) (* 2 wheel-radius) "solid" "white") tire))<br _moz_dirty="">(define auto (above top bot))<br _moz_dirty=""><br _moz_dirty="">(define Y-CAR 50)<br _moz_dirty="">(define BACKGROUND (empty-scene 1000 200))<br _moz_dirty=""><br _moz_dirty="">; CarState -> CarState<br _moz_dirty="">; the clock ticked; move the car by three pixels<br _moz_dirty="">; example:<br _moz_dirty="">; given: 20, expected 23<br _moz_dirty="">; given: 78, expected 81<br _moz_dirty="">(define (tock ws) <br _moz_dirty=""> (if (< ws (-(image-width BACKGROUND)(* 0.54 (image-width auto))))(+ ws 3) ( - ws (image-width BACKGROUND))))<br _moz_dirty=""><br _moz_dirty="">; CarState -> Image<br _moz_dirty="">; place the car into a scene, according to the given world state<br _moz_dirty="">(define (render ws)<br _moz_dirty=""> (place-image auto ws Y-CAR BACKGROUND))<br _moz_dirty=""><br _moz_dirty="">; main : CarState -> CarState<br _moz_dirty="">; launch the program from some initial state<br _moz_dirty="">(define (main ws)<br _moz_dirty=""> (big-bang ws (on-tick tock) (to-draw render)))<br _moz_dirty=""><br _moz_dirty="">But now I wonder if I can do the same with setting the variable ws to zero.<br _moz_dirty="">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 _moz_dirty=""><br _moz_dirty="">Regards,<br _moz_dirty=""><br _moz_dirty="">Roelof<br _moz_dirty=""><br _moz_dirty=""><br _moz_dirty=""><br _moz_dirty=""><br _moz_dirty=""><br _moz_dirty=""> <br _moz_dirty=""><br _moz_dirty=""><br _moz_dirty=""><br></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>