<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 -&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 _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&nbsp; 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 -&gt; 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="">&nbsp; (if (&lt; ws (-(image-width BACKGROUND)(* 0.54&nbsp; (image-width auto))))(+ ws 3) ( - ws (image-width BACKGROUND))))<br _moz_dirty=""><br _moz_dirty="">; CarState -&gt; 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="">&nbsp; (place-image auto ws Y-CAR BACKGROUND))<br _moz_dirty=""><br _moz_dirty="">; main : CarState -&gt; CarState<br _moz_dirty="">; launch the program from some initial state<br _moz_dirty="">(define (main ws)<br _moz_dirty="">&nbsp;&nbsp; (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="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br _moz_dirty=""><br _moz_dirty=""><br _moz_dirty=""><br></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>