BezierMorphReplication

From MHCGraphics

Jump to: navigation, search
; Mead example file -- using morph with a Bezier curve
; to add objects
;
; Jim Teresco
; Computer Science 110
; Mount Holyoke College
;
; $Id: BezierMorphReplication.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 twentySpotsOnBezier
  (morph 19 '(-200 0 0) '(-100 200 0) '(100 -200 0) '(200 0 0)))

; 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 (addAtPositions positions 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)])
        ; add one copy, at the first position specified
        (tell group
              (add obj
                   (translate (car pos) (cadr pos) (caddr pos))
                   )
              )
        (addAtPositions (cdr positions) obj group)
        )
      )
  )

; make a little red sphere
(object littleRedSphere Sphere
        (scale .1 .1 .1)
        (material redPlaster)
        )

; let's add them
(addAtPositions twentySpotsOnBezier littleRedSphere scene)

(tell image
      (background white)
      )

(tell camera
      (shoot))
Personal tools