From MHCGraphics
; Mead example file -- A whole bunch of doughnuts
;
; Jim Teresco
; Computer Science 110
; Mount Holyoke College
;
; $Id: MoreDoughnuts.scm 594 2008-03-31 01:06:20Z terescoj $
;
(require (lib "Defs.ss" "Mead"))
; Some size parameters for our doughnuts
(define doughnutThickness 30)
(define doughnutSize 90)
; First, we create a doughnut object
; We can do this with a Mead Torus object
; For a Torus, we specify the major radius and minor radius.
; The minor radius determines the thickness of the cross
; section, the major radius how big a circle is traced out
; with the cross section.
; In this case, it means our doughnuts occupy a space
; that is 90x30x90, centered above the origin
(object doughnut Torus
(major (/ (- doughnutSize doughnutThickness) 2))
(minor (/ doughnutThickness 2))
(material yellowPlaster)
(translate 0 (/ doughnutThickness 2) 0)
)
; We'll put a bunch of doughnuts in a line, lined
; up sitting on the xz-plane atop the x-axis.
; To do this, we write a function:
; This function adds multiple objects to a group (often
; the scene). The "initialXform" is a transformation that
; is applied to the "prototype" object, obj,
; to place the first instance in the scene.
; The "deltaXform" takes us from one to the next.
(define (multiAdd n obj group initialXform deltaXform)
(if (<= n 0) group ; return the group, if nothing to be added
(begin ; if something, add one, then the rest
(tell group
(add obj initialXform)
)
(multiAdd (- n 1) obj group
(compose initialXform deltaXform)
deltaXform)
)
)
)
(define numDoughnuts 12)
(define doughnutSpacing (* 1.1 doughnutSize))
; now, instead of adding a row of doughnuts right to the
; scene, we'll put them in a group, and add groups
; of doughnuts to the scene instead.
(object doughnutRow Group)
(multiAdd numDoughnuts doughnut doughnutRow
(translate (- (* (/ numDoughnuts 2) doughnutSpacing))
0 0)
(translate doughnutSpacing 0 0))
; adding the rows
(define numRows 100)
(multiAdd numRows doughnutRow scene
(translate 0 0 (- (* (/ numRows 2) doughnutSpacing)))
(translate 0 0 doughnutSpacing))
(tell image
(background white))
(tell camera
(pos '(0 300 -500))
(shoot))