QuadraticMorphReplication

From MHCGraphics

Jump to: navigation, search
; Mead example file -- using morph with a Bezier curve
; to add objects -- this time, a quadratic curve
;
; Jim Teresco
; Computer Science 110
; Mount Holyoke College
;
; $Id: QuadraticMorphReplication.scm 616 2008-04-08 21:30:21Z terescoj $
;
(require (lib "Defs.ss" "Mead"))

; Create a morph of 20 positions from (-200,0,0) to (200,0,0)
; this time, quadratic -- a parabolic path
(define twentySpotsOnParabola
  (morph 19 '(-200 0 0) '(0 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 twentySpotsOnParabola littleRedSphere scene)

(tell image
      (background white)
      )

(tell camera
      (shoot))
Personal tools