Blame


1 12687dd9 2023-08-04 jrmu ;; The first three lines of this file were inserted by DrScheme. They record metadata
2 12687dd9 2023-08-04 jrmu ;; about the language level of this file in a form that our tools can easily process.
3 12687dd9 2023-08-04 jrmu #reader(lib "htdp-intermediate-lambda-reader.ss" "lang")((modname |25.1|) (read-case-sensitive #t) (teachpacks ((lib "draw.ss" "teachpack" "htdp") (lib "arrow.ss" "teachpack" "htdp") (lib "gui.ss" "teachpack" "htdp"))) (htdp-settings #(#t constructor repeating-decimal #f #t none #f ((lib "draw.ss" "teachpack" "htdp") (lib "arrow.ss" "teachpack" "htdp") (lib "gui.ss" "teachpack" "htdp")))))
4 12687dd9 2023-08-04 jrmu (define-struct ball (radius x y delta-x delta-y color))
5 12687dd9 2023-08-04 jrmu
6 12687dd9 2023-08-04 jrmu ;A ball is a structure
7 12687dd9 2023-08-04 jrmu ;(make-ball number number number number number symbol)
8 12687dd9 2023-08-04 jrmu
9 12687dd9 2023-08-04 jrmu ;draw-and-clear-ball : ball -> true
10 12687dd9 2023-08-04 jrmu (define (draw-and-clear-ball a-ball)
11 12687dd9 2023-08-04 jrmu (and (draw-solid-disk (make-posn (ball-x a-ball)
12 12687dd9 2023-08-04 jrmu (ball-y a-ball))
13 12687dd9 2023-08-04 jrmu (ball-radius a-ball)
14 12687dd9 2023-08-04 jrmu (ball-color a-ball))
15 12687dd9 2023-08-04 jrmu (sleep-for-a-while DELAY)
16 12687dd9 2023-08-04 jrmu (clear-solid-disk (make-posn (ball-x a-ball)
17 12687dd9 2023-08-04 jrmu (ball-y a-ball))
18 12687dd9 2023-08-04 jrmu (ball-radius a-ball)
19 12687dd9 2023-08-04 jrmu (ball-color a-ball))))
20 12687dd9 2023-08-04 jrmu
21 12687dd9 2023-08-04 jrmu
22 12687dd9 2023-08-04 jrmu ;move-ball : ball -> ball
23 12687dd9 2023-08-04 jrmu (define (move-ball a-ball)
24 12687dd9 2023-08-04 jrmu (make-ball (ball-radius a-ball)
25 12687dd9 2023-08-04 jrmu (+ (ball-x a-ball) (ball-delta-x a-ball))
26 12687dd9 2023-08-04 jrmu (+ (ball-y a-ball) (ball-delta-y a-ball))
27 12687dd9 2023-08-04 jrmu (ball-delta-x a-ball)
28 12687dd9 2023-08-04 jrmu (ball-delta-y a-ball)
29 12687dd9 2023-08-04 jrmu (ball-color a-ball)))
30 12687dd9 2023-08-04 jrmu
31 12687dd9 2023-08-04 jrmu out-of-bounds? : ball -> boolean
32 12687dd9 2023-08-04 jrmu (define (out-of-bounds? a-ball)
33 12687dd9 2023-08-04 jrmu (not (and (<= 0 (ball-x a-ball) WIDTH)
34 12687dd9 2023-08-04 jrmu (<= 0 (ball-y a-ball) HEIGHT))))
35 12687dd9 2023-08-04 jrmu
36 12687dd9 2023-08-04 jrmu ;(define VOLLEYBALL (make-ball 20 0 0 5 2 'black))
37 12687dd9 2023-08-04 jrmu
38 12687dd9 2023-08-04 jrmu (define WIDTH 500)
39 12687dd9 2023-08-04 jrmu (define HEIGHT 0.05)
40 12687dd9 2023-08-04 jrmu (define DELAY 5)
41 12687dd9 2023-08-04 jrmu (start WIDTH HEIGHT)