From MHCGraphics
; Mead example file -- adding lots of salt coming out of
; a salt shaker
;
; Jim Teresco
; Computer Science 110
; Mount Holyoke College
;
; $Id: SaltShaker.scm 577 2008-03-25 19:24:44Z terescoj $
;
(require (lib "Defs.ss" "Mead"))
; This function computes a random value between low
; and high (low is possible, high is not).
; The (random) call returns a random number in [0,1).
(define (rand low high)
(+ low (* (random) (- high low))))
; define an individual salt crystal, a 5x5x5 cube
(object saltCrystal Cube
(material whitePlaster)
(scale .05 .05 .05)
)
; put in a red floor for some reason
(object floor Plane)
; the salt "pours in" from above from a circular source,
; leading to a cylindrical area filled with salt crystals.
; to achieve this, we will place grains of salt in random
; orientations and at random positions within this cylindrical
; region, which we define as 300 in height, and 50x50 above the
; xz-plane
(define saltStreamHeight 300)
(define saltStreamRadius 50)
; our function to add the salt grains
(define (addSalt grain n group)
(if (<= n 0) group ; if we're done adding grains, just
; return the group
(begin ; more to do, everything inside the
; begin will happen when n>0
(tell group
(add grain ; add a new grain
(compose ; and transform it appropriately
(xRot (rand 0 360))
(yRot (rand 0 360))
(zRot (rand 0 360)) ; any orientation
(translate
(rand 0 saltStreamRadius) ; move along x
(rand 0 saltStreamHeight) ; move up
0) ; no y - this is taken care of below
(yRot (rand 0 360)) ; rotate about y
)
)
)
(addSalt grain (- n 1) group) ; add remaining grains
)
)
)
; we define an empty Group, to which we will add our grains
; of salt
(object saltGrains Group)
; add our grains using the function defined above
(addSalt saltCrystal 250 saltGrains)
(object scene Group)
(tell scene
(add floor redPlaster)
(add saltGrains)
(add (new Light) (translate 0 300 -500))
(add (new Light) (translate 200 300 -500))
(add (new Light) (translate -200 300 -500))
)
(tell camera
(pos '(0 300 -500))
(coi '(0 100 0))
(shoot))