From MHCGraphics
; Mead example file -- a circle of marble objects that use
; very very random materials
;
; Jim Teresco
; Computer Science 110
; Mount Holyoke College
;
; $Id: RandomMaterialMarbles.scm 601 2008-04-01 16:02:12Z terescoj $
;
(require (lib "Defs.ss" "Mead"))
; These functions add multiple objects, each with a very
; random material
(define (rand low high)
(+ low (* (random) (- high low)))
)
(define (veryRandomMatAdd n obj group initialXform deltaXform)
(if (<= n 0) group
(let* ([m (new Material)]
)
; now we can give our material the properties we want
(tell m
; a completely random color
(color (list (random) (random) (random)))
(ambient (rand 0 .4))
(diffuse (rand .2 1))
(roughness (rand 0 1.5))
(specularity (rand 0 .5))
(reflection (rand 0 .5))
(transparency (rand 0 .5))
(refraction (rand .75 1.6))
)
; add one instance of our object to the group, but
; also specify our brand new material
(tell group (add obj initialXform m))
; now add the other n-1 copies
(veryRandomMatAdd (- n 1) obj group
(compose initialXform deltaXform)
deltaXform)
)
)
)
; we'll use this to place a bunch of marbles in a circle
; about the y-axis
; our marble is just a 50x50x50 sphere, that by default
; sits atop the origin, no material specified yet
(object marble Sphere
(scale .5 .5 .5)
(translate 0 25 0)
)
; define names for the number or marbles and how far
; around we'll need to rotate each to get a nice circle of
; marbles
(define numMarbles 24)
(define angleSpacing (/ 360 numMarbles))
(define layoutRadius 300)
(veryRandomMatAdd numMarbles marble scene
; our first marble is translated out
; by some amount along x
(translate layoutRadius 0 0)
; subsequent marbles are each rotated around
; the y-axis by an appropriate amount
(yRot angleSpacing)
)
; put in a floor and a few lights
(object dimBulb Light
(intensity .25)
)
(tell scene
(add dimBulb (translate 500 800 500))
(add dimBulb (translate -500 800 500))
(add dimBulb (translate 500 800 -500))
(add dimBulb (translate -500 800 -500))
(add (new Plane) whitePlastic))
(tell image
(background white)
(antiAlias 1)
(dimensions 800 600)
(quality 11)
)
(tell camera
(pos '(0 300 -600))
(angle 60)
(shoot))