Wednesday, 24 October 2012

Fun with Big Bang

In last week's lecture we continued our development of the barracuda clock, adding more functions to the big bang model. It's fascinating seeing all the concepts we've learned over the weeks slowly coming together as we try to develop very basic working programs.

As I worked through the Picturing Program exercises, I was intrigued by other ways in which you can use the Big Bang model. For example, suppose you want to create a square that starts at width length 10 and gets larger by the second.

; square-of-width : number (width) -> image

(check-expect (square-of-width 7)
                       (square 7 "solid" "red"))

(define square-of-width (square n "solid" "red"))

(big bang 15
       (check-with number?)
       (on-draw square-of-width 100 100)
       (on-tick add1 1))

This program creates a red square with side width 15 on a 100 by 100 window, and the square gets larger by the second!

I realize Dr. Racket is much more versatile than I originally thought. When you're willing to explore, the possibilities are endless. I'll be taking more time this week to play around with big bang.

No comments:

Post a Comment