From MHCGraphics
; Mead example file -- stack some poker chips, but not
; perfectly -- have some random "noise" in the stacking
;
; Jim Teresco
; Computer Science 110
; Mount Holyoke College
;
; $Id: PokerChipStack.scm 603 2008-04-02 04:38:31Z terescoj $
;
(require (lib "Defs.ss" "Mead"))
; our rand function from previous examples
(define (rand low high)
(+ low (* (random) (- high low)))
)
; a brand new function: imperfectStack
; stacks up a collection of objects
; parameters:
; n - how many objects to stack
; obj - the objects to stack
; group - the group where copies of obj are added
; initialXform - a transformation to apply to obj to get
; it to its initial position
; deltaY - the distance in the y dimension to translate
; successive objects as they're stacked
; jitter - the amount in the x and z directions that each
; object can randomly be translated to make our
; stacks imperfect
(define (imperfectStack n obj group initialXform deltaY jitter)
(if (<= n 0) group ; nothing more to add
(begin
(tell group
(add obj
; to add this instance of obj, we apply
; the initialXform then translate by
; small random amounts in x and z
(compose
initialXform
(translate (rand (- jitter) jitter)
0
(rand (- jitter) jitter))
)
)
)
; to add the rest, we have n-1 to go, and we apply
; a translation by deltaY in the y dimension to
; the initialXform to get the starting position
; for the next item we'll add -- other parameters
; just come along for the ride
(imperfectStack (- n 1) obj group
(compose initialXform
(translate 0 deltaY 0))
deltaY jitter)
)
)
)
; we'll stack some poker chips, 100x10x100 cylinders
(define chipDiameter 100)
(define chipThickness 10)
(object chip Cylinder
(scale .01 .01 .01)
(scale chipDiameter chipThickness chipDiameter)
(translate 0 (/ chipThickness 2) 0)
)
; create a group of 10 chips to be red
(object redStack Group)
(imperfectStack 10 chip redStack
(translate 0 0 0) chipThickness 5)
; and a group of 15 that we'll color black
(object blackStack Group)
(imperfectStack 15 chip blackStack
(translate 0 0 0) chipThickness 7)
(tell scene
(add redStack redPlastic
(translate -100 0 0))
(add blackStack blackPlastic
(translate 100 0 0))
(add bulb (translate 0 500 -700))
)
(tell image
(background white)
)
(tell camera
(pos '(0 300 -500))
(shoot))