Blob


1 ;; The first three lines of this file were inserted by DrScheme. They record metadata
2 ;; about the language level of this file in a form that our tools can easily process.
3 #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 (define-struct ball (radius x y delta-x delta-y color))
6 ;A ball is a structure
7 ;(make-ball number number number number number symbol)
9 ;draw-and-clear-ball : ball -> true
10 (define (draw-and-clear-ball a-ball)
11 (and (draw-solid-disk (make-posn (ball-x a-ball)
12 (ball-y a-ball))
13 (ball-radius a-ball)
14 (ball-color a-ball))
15 (sleep-for-a-while DELAY)
16 (clear-solid-disk (make-posn (ball-x a-ball)
17 (ball-y a-ball))
18 (ball-radius a-ball)
19 (ball-color a-ball))))
22 ;move-ball : ball -> ball
23 (define (move-ball a-ball)
24 (make-ball (ball-radius a-ball)
25 (+ (ball-x a-ball) (ball-delta-x a-ball))
26 (+ (ball-y a-ball) (ball-delta-y a-ball))
27 (ball-delta-x a-ball)
28 (ball-delta-y a-ball)
29 (ball-color a-ball)))
31 out-of-bounds? : ball -> boolean
32 (define (out-of-bounds? a-ball)
33 (not (and (<= 0 (ball-x a-ball) WIDTH)
34 (<= 0 (ball-y a-ball) HEIGHT))))
36 ;(define VOLLEYBALL (make-ball 20 0 0 5 2 'black))
38 (define WIDTH 500)
39 (define HEIGHT 0.05)
40 (define DELAY 5)
41 (start WIDTH HEIGHT)