Please send questions to
st10@humboldt.edu .
; CS 131 - Week 3, Lecture 2
; modulo "prelude" example
; (a variation from Week 2, Lecture 2 posted examples)
(require 2htdp/universe)
(require 2htdp/image)
; named constants for this animation
(define WIDTH 200)
(define HEIGHT 150)
(define BACKDROP
(place-image (circle 30 "solid" "gold")
(- WIDTH 50)
(/ HEIGHT 3)
(empty-scene WIDTH HEIGHT)))
;----------------------
; let's say I want MANY purple stars of many sizes
; SO -- I'm going to write a function to do so
; signature: purple-star: number -> image
; purpose: expects a desired enclosing pentagon side length
; in pixels, and produces a purple star of that size
(check-expect (purple-star 27)
(star 27 "solid" "purple"))
(check-expect (purple-star 46)
(star 46 "solid" "purple"))
(define (purple-star size)
(star size "solid" "purple")
)
(purple-star 30)
(purple-star 4)
;---------------
; signature: get-1-bigger: number -> number
; purpose: expects a number, and produces the number
; that is 1 bigger
(define (get-1-bigger a-number)
(+ a-number 1)
)
(check-expect (get-1-bigger 15) 16)
(get-1-bigger 45)
;---------------
; what would happen if just the star's x-coordinate
; is determined by the current state?
; now it would be nice to have a named constant for
; the star's size...
(define STAR-SIZE 30)
; signature: draw-star-scene3: number -> scene
; purpose: expects the current state of the universe,
; and produces a scene with a purple star
; centered at ((modulo state WIDTH), HEIGHT/2)
(define (draw-star-scene3 a-number)
(place-image
(purple-star STAR-SIZE)
(modulo a-number WIDTH)
(/ HEIGHT 2)
BACKDROP)
)
(check-expect (draw-star-scene3 15)
(place-image
(purple-star STAR-SIZE)
15
(/ HEIGHT 2)
BACKDROP))
(check-expect (draw-star-scene3 47)
(place-image
(purple-star STAR-SIZE)
47
(/ HEIGHT 2)
BACKDROP))
(check-expect (draw-star-scene3 (+ WIDTH 5))
(place-image
(purple-star STAR-SIZE)
5
(/ HEIGHT 2)
BACKDROP))
(draw-star-scene3 15)
(big-bang 0
(on-tick get-1-bigger 1/56)
(on-draw draw-star-scene3))