How can i specify end of big bang

hi all i am working through the hdtp book,currenyly creating a simple animation which a moves car from left to right at a rate of three pixles per clock tick.i am not sure but i have tried to but not sure how to piece it all together.my objective is to end the program when the car dissapears out of the background image.i have used this code from a previous chapter

(define car-end
(image-width CAR))

;WorldState -> Boolean
; after each event, big-bang evaluates (end? cw)

;stops program when the car touches the right hand side
(define (end? cw)
(> cw car-end))

this is all i could come to ,how can i find the distance from when i run the main program depending on the input for the number pixels,the program shuts down.

here is my full code

(require 2htdp/image)

(require 2htdp/batch-io)

(require 2htdp/universe)

;physical constants
(define WIDTH-OF-WORLD 20)

(define WHEEL-RADIUS 5)
(define WHEEL-DISTANCE (* WHEEL-RADIUS 5))
(define Y-TREE 15)
(define X-CAR 20)

(define TREE
(underlay/xy (circle 10 "solid" "green")
9 15
(rectangle 2 20 "solid" "brown")))
(define BACKGROUND (rectangle 400 200 "solid" "green"))

(define background1 (place-image TREE 50 Y-TREE BACKGROUND))

(define body (rectangle 40 20 "solid" "red"))

(define Y-CAR 10) ;this chnages how high or low the car is

;grpahical constants

(define WHEEL
(circle WHEEL-RADIUS "solid" "black"))

(define SPACE
(rectangle WIDTH-OF-WORLD WHEEL-RADIUS WHEEL-DISTANCE "white"))
(define BOTH-WHEELS
(beside WHEEL SPACE WHEEL))

(define CAR (above (rectangle 40 20 "solid" "red") (beside WHEEL SPACE WHEEL)))

;A WorldState is a Number.
; interpretation the number of pixels between
; the left border of the scene and the car

; WorldState -> WorldState
; launches the program from some initial state
(define (main ws)
(big-bang ws
[on-tick tock]
[to-draw render]
[stop-when end?]))

; WorldState -> WorldState
; moves the car by 3 pixels for every clock tick
; examples:
; given: 20, expect 23
; given: 78, expect 81
(define (tock cw)
(+ cw 3))

(define car-end
(image-width CAR))

; WorldState -> Image
; places the car into the BACKGROUND scene,
; according to the given world state
(define (render cw)
(place-image CAR cw Y-CAR background1))

  ;WorldState -> Boolean

; after each event, big-bang evaluates (end? cw)

;stops program when the car touches the right hand side
(define (end? cw)
(> cw car-end))

I like seeing the data definitions, purpose statements and examples!
Please use three backticks at the beginning and end of code sections like this:

```
your example code here
```

This formats the code in your message and makes it easier to read.

1 Like

WorldState -> Boolean

this checks wether the car which animated that moves from the left to the right has passed/dissapeared past the right hand side and which it should return true and abort the program

e,g the background image has a width of 200 ,depending on which state the car spawns at it should caulcate the distance between the start state and the number of pixels from left to right

(define (end? cw)
(> cw car-end))

this code is what i could think but im trying to find a predicate which i can use to dermine when the car gone past the right hand side

“Examples” means “working thru examples”.

Take a piece of graph paper. Draw the situation on the paper when (end? ws) should return #true. You don’t have to be artistic about it. Translate this scene into a formula in terms of ws (world state) by marking car-length and width [of big-bang image], etc. And finally make this formula conform with BSL.

2 Likes

i just dont know how to create a boolean formula for finding the distance of (image-width car) and (image-width BACKGROUND) do i need to subtract the width of the car from the background or from the main function

Subtraction of two numbers yields a number. A comparison yields a boolean. Your big-bang expression was correct (quick glance).

[ I do not know what it means to subtract the width of the car from the main function. ]