MoreMorphReplication

From MHCGraphics

Jump to: navigation, search
; Mead example file -- using morph to add objects
;
; Jim Teresco
; Computer Science 110
; Mount Holyoke College
;
; $Id: MoreMorphReplication.scm 612 2008-04-06 01:19:20Z terescoj $
;
(require (lib "Defs.ss" "Mead"))

; Create a morph of 20 positions from (-200,0,0) to (200,0,0)
(define twentySpotsOnXAxis
  (morph 19 '(-200 0 0) '(200 0 0)))
; and a morph of 20 scaling factors
(define scalingFactors
  (morph 19 .1 2.0))
; and a morph of 20 greyscale colors
(define greyColors
  (morph 19 white black))

; A function to add some number of copies of an object
; to a group at positions specified by a list passed
; as a parameter
(define (addAtPosScaleColor positions scales colors obj group)
  ; a new type of condition for our if -- is the
  ; given list empty?
  (if (null? positions) 'done ; if empty just say 'done
      (let* ([pos (car positions)]
             [s (car scales)]
             [c (car colors)]
             [m (new Material)])
        ; add one copy, at the first position specified
        ; with appropriate color and scale
        (tell m (color c) (type 'plaster))
        (tell group
              (add obj m
                   (compose
                    (scale s s s)
                    (translate (car pos) (cadr pos) (caddr pos))
                    )
                   )
              )
        (addAtPosScaleColor (cdr positions)
                            (cdr scales)
                            (cdr colors) obj group)
        )
      )
  )

; make a little sphere
(object littleSphere Sphere
        (scale .1 .1 .1)
        )

; let's add them
(addAtPosScaleColor twentySpotsOnXAxis scalingFactors greyColors
                    littleSphere scene)

(tell image
      (background '(1 .5 1))
      )

(tell camera
      (shoot))
Personal tools