Please send questions to st10@humboldt.edu .
; BEWARE -- doggy image appears as a dot below in this text-only version!

; CS 131 - Week 2, Lecture 1
; Starting Animation
; last modified: 08-31-10

; load the universe and image teachpacks

(require 2htdp/universe)
(require 2htdp/image)

; constant definitions (those that don't change) for the 
;    desired scene/world

; the dog image that will move through the scene

(define LITTLE-DOG .)

; the scene's width and height

(define WIDTH 200)
(define HEIGHT 150)

; the sun's radius

(define SUN-RADIUS 30)

; define a backdrop that doesn't change, for the dog to walk
;    through

(define BACKDROP 
     (place-image (circle SUN-RADIUS "solid" "gold")
                  (- WIDTH 50)
                  (/ HEIGHT 3)
                  (empty-scene WIDTH HEIGHT))
)
BACKDROP

; signature: go-to-next: number -> number
; purpose: expects any number, and produces one more than 
;    that number

(define (go-to-next a-number)
  (+ 1 a-number)
)

(check-expect (go-to-next 3) 4)
(check-expect (go-to-next 1000) 1001)

; signature: draw-walking-scene: number -> scene
; purpose: expects a time counter, and produces a scene with
;    a walking dog at (modulo time-counter WIDTH)

(define DOG-Y (- HEIGHT (/ (image-height LITTLE-DOG) 2)))

(define (draw-walking-scene time-counter)
    (place-image LITTLE-DOG
                 (modulo time-counter WIDTH)
                 DOG-Y
                 BACKDROP)
)

(check-expect (draw-walking-scene 0)
    (place-image LITTLE-DOG
                 0
                 DOG-Y
                 BACKDROP)
)

(draw-walking-scene 0)
(draw-walking-scene 75)

; signature: main: number -> number
; purpose: expects an initial time-counter value, and starts
;    up big-bang for this walking-dog scene with that 
;    initial time-counter value. When the animation is
;    ended, it produces the final time-counter value.
; The result will be that big-bang will go-to-next with the
;    initial time-counter value, then the next time-counter
;    value, and so on,
;    each time then calling draw-walking-scene with the next
;    time-counter value

(define (main initial-time-counter)
  (big-bang initial-time-counter
            
            ; can optionally set animation speed
            
            (on-tick go-to-next 1/28)  
            (on-draw draw-walking-scene)
            ;(record? true)
   )
)

; this actually starts up the animation with a time-counter 
;    of 0

(main 0)