Hello,

I have tried to make a function which display a car running on a empty-screen.
When the car  is at the end. The car has to begin at the beginning.

I have made this :

(define wheel-radius 5)
(define cab (beside (rectangle (* 6 wheel-radius)(* 4 wheel-radius) "solid" "red")(right-triangle (* 2 wheel-radius) (* 4 wheel-radius) "solid" "red")))
(define body (rectangle (* 20 wheel-radius) (* 6 wheel-radius) "solid" "red"))
(define top (above/align "right" cab body))
(define tire (circle wheel-radius "solid" "black"))
(define bot (beside tire (rectangle (* 5 wheel-radius) (* 2 wheel-radius) "solid" "white") tire))
(define auto (above top bot))

(define Y-CAR 50)
(define BACKGROUND (empty-scene 1000 200))

; CarState -> CarState
; the clock ticked; move the car by three pixels
; example:
; given: 20, expected 23
; given: 78, expected 81
(define (tock ws)
  (if (< ws (-(image-width BACKGROUND)(* 0.54  (image-width auto))))(+ ws 3) ( - ws (image-width BACKGROUND))))

; CarState -> Image
; place the car into a scene, according to the given world state
(define (render ws)
  (place-image auto ws Y-CAR BACKGROUND))

; main : CarState -> CarState
; launch the program from some initial state
(define (main ws)
   (big-bang ws (on-tick tock) (to-draw render)))

But now I wonder if I can do the same with setting the variable ws to zero.
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

Regards,

Roelof





                   



____________________
  Racket Users list:
  http://lists.racket-lang.org/users

Reply via email to