main.ss
;; Whiff.

;; Copyright (c) 2008 David Van Horn
;; Licensed under the Academic Free License version 3.0

;; (at dvanhorn (dot ccs neu edu))

#lang scheme
(require htdp/world)

;; http://list.cs.brown.edu/pipermail/plt-scheme/2008-October/027789.html
(require scheme/runtime-path scheme/gui)
(define-runtime-path whiff-path "whiff.jpg")
(define whiff (make-object image-snip% (make-object bitmap% whiff-path)))

;; I shit you not:
;;
;;    Whiff is a cheery, little tank engine with a very special job:
;;    he collects rubbish! He has a look and smell all his own! Whiff
;;    doesn't care too much about appearance. What matters to Whiff
;;    is getting his job done and getting it done well.
;;
;; http://thomas-tank-engine.com/train/whiff-thomas-wooden-train-p-1892.html

;; A World is a Number.
;; Interpretation: x coordinate of train on a circular track
;; represented using modular arithmetic.

(define train-length (image-width whiff))
(define train-height (image-height whiff))
(define WIDTH (* 4 train-length))
(define HEIGHT (+ 2 train-height))

;; The train takes 5 minutes to loop around the track.
(define TRACK-LENGTH (* 5    ;; minutes
                        60   ;; seconds / minute
                        20)) ;; ticks / second

(big-bang WIDTH HEIGHT 1/20 0)

(on-tick-event
 (lambda (w) 
   (modulo (+ w 3) TRACK-LENGTH)))

(on-redraw 
 (lambda (w)
   (place-image whiff 
                (- (+ WIDTH (* 1/2 train-length)) w)
                (add1 (* 1/2 train-height))
                (empty-scene WIDTH (+ 2  (image-height whiff))))))