; this is a Racket comment. It's ignored by the computer,
;     and is for the human reader!

; this makes the functions in the image and universe
;     teachpacks available for use

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

; examples of simple expressions
3
4.67
3.4e5
"Howdy"
true

; once you give a name a value, that name is a simple expression,
;     too

(define FLOATY floating penguin)
FLOATY

; a compound expression is always:
; (operator expression ... expression)

(+ 3 5)
(* (+ 3 5) (- 3 5))
(/ 3 5)
(sqrt 2)
(circle 30 "solid" "black")
(rectangle 50 20 "outline" "green")

; in math:   f(x) = 3x
; in Racket:

(define (f x)
  (* 3 x)
)

; once you have defined a function, you can use it

(f 7)
(f 10)
(f (f (f 4)))

; Racket has a function that adds 1 to a given number

(add1 4)

; Racket's universe provides a scene type

; get an empty scene, 300 pixels wide and 300 pixels high

(empty-scene 300 300)

; get a scene with an image in it
; place-image: image x y scene 

(place-image FLOATY 150 150 
             (empty-scene 300 300))

; create a function to get a sine-based y coordinate, given
;     the current world-value

(define (wavy-y world-value)
  (+ 150 (* 75 
            (sin (/ world-value (/ 180 
                                   pi)))))
)

; for a given world-value, create a scene with a penguin
;    whose location is based on that world-value

(define WIDTH 720)
(define HEIGHT 300)

(define (draw-scene world-value)
  (place-image FLOATY
               (modulo world-value WIDTH)
               (wavy-y world-value)
               (empty-scene WIDTH HEIGHT)))

; example of a Racket test

(check-expect (draw-scene 0)
              (place-image FLOATY
                           0
                           (wavy-y 0)
                           (empty-scene
                              WIDTH
                              HEIGHT)))

; start up an animation!
; big-bang expects:
; *   an initial world value (here, 0)
; *   call on-tick with a function that expects a world-value and produces
;     the next world-value (big-bang calls this with the current world-value
;     at each clock-tick) -- that 1/100 is how fast the clock should
;     tick, here every 1/100th of a second. (if no speed given, default
;     is 1/28, 28 times per second)
; *   call on-draw with a function that expects a world-value and produces
;     the scene that should be shown for that world-value
; *   the record? is optional, if you'd like to try to create an animated
;     gif

(big-bang 0
          (on-tick add1 1/100)
          (on-draw draw-scene)
          (record? true))