[plt-scheme] Re: [plt-edu] Moving curves are lovely, thanks!

From: David Van Horn (dvanhorn at ccs.neu.edu)
Date: Tue May 25 16:11:18 EDT 2010

On 5/22/10 10:56 AM, John Clements wrote:
> Reading through your image docs today; I really love the white curve on the black square, and after making them swim around a bit, I'm actually having trouble focusing because I'm kind of entranced by watching and fiddling.  (Well, maybe that's has something to do with the squarepusher I'm listening to ...)
>
> Anyhow: thanks!
>
> John
>
> (require 2htdp/universe)
> (require 2htdp/image)
>
> (define (draw-world t)
>    (add-curve
>     (add-curve (rectangle 500 500 "solid" "black")
>                (+ (* 50 (cos (/ t 50))) 120) 120 (modulo t 360) 1/3
>                380 (+ (* 50 (sin (/ t 100))) 380) (modulo (- t) 360) 1/3
>                "white")
>     80 (+ (* 50 (sin (/ t 100))) 380) (modulo t 360) 1/3
>     (+ (* 50 (cos (/ t 50))) 170) 30 (modulo (- t) 360) 1/3
>     "yellow"))
>
> (animate draw-world)

Now available in typed flavor:

#lang typed/scheme
(require (planet dvanhorn/typed/2htdp/image)
          (planet dvanhorn/typed/2htdp/universe)
          (planet dvanhorn/typed/util))

(: draw-world (Integer -> Image))
(define (draw-world t)
   (add-curve
    (add-curve (rectangle 500 500 "solid" "black")
               (+ (* 50 (cast real? (cos (/ t 50)))) 120)
               120
               (modulo t 360)
               1/3
               380
               (+ (* 50 (cast real? (sin (/ t 100)))) 380)
               (modulo (- t) 360)
               1/3
               "white")
    80
    (+ (* 50 (cast real? (sin (/ t 100)))) 380)
    (modulo t 360)
    1/3
    (+ (* 50 (cast real? (cos (/ t 50)))) 170)
    30
    (modulo (- t) 360)
    1/3
    "yellow"))

(animate draw-world)



Posted on the users mailing list.