SnowMan

From MHCGraphics

Jump to: navigation, search
; Class example: Snowmen!  (fairly simple ones)
;
; Jim Teresco with the Spring 2008 CS110 class
; Mount Holyoke College
; February 10, 2008
;
; $Id: SnowMan.scm 472 2008-02-13 00:37:34Z terescoj $
;
(require (lib "Defs.ss" "Mead"))

; We define an object to use as the snowman's
; eyes -- since it has just a single spherical
; component, we define it as an instance of a "Sphere"
; and give it a material and resize it
;
; For now, we leave it at the origin so it can easily be
; moved into an appropriate place when we add eyes
; to our snowman's head
(object snowmanEye Sphere
        (material blackPlaster)
        (scale .1 .1 .1)
        )

; Now, a "Group" object to define the snowman's head.
; To construct a group, we send the group "add" messages
; in the same way we did in our "tell scene" constructs.
(object snowmanHead Group
        (add sphere whitePlaster
             )
        ; left eye (which we see on the right)
        (add snowmanEye
             (translate 0 0 -50)
             (yRot -30)
             (xRot 30)
             )
        ; right eye (which we see on the left)
        (add snowmanEye
             (translate 0 0 -50)
             (yRot 30)
             (xRot 30)
             )
        ; carrot nose
        (add cone redPlaster
             (xform
              (scale .2 .3 .2)
              (xRot -90)
              (translate 0 0 -60)
              )
             )
        )

; One more object to define the whole snowman.  Our
; snowman is a "Group" object, and it sits at the origin
(object snowman Group
        ; base snowball
        (add sphere whitePlaster
             (xform
              (scale 1.4 1.4 1.4)
              (translate 0 70 0)
              )
             )
        ; middle snowball
        (add sphere whitePlaster
             (xform
              (scale 1.2 1.2 1.2)
              (translate 0 190 0)
              )
             )
        ; the snowman's head, as defined above
        (add snowmanHead
             (translate 0 290 0)
             )
        )

; Let's add some snowmen to our scene, standing apart
; looking toward each other
(tell scene 
      (add snowman
           (xform
            (yRot 60)
            (translate 300 0 0)
            )
           )
      (add snowman
           (xform
            (yRot -60)
            (translate -300 0 0)
            )
           )
      
      )

; some extra lighting - a very bright light from the top right
(object newLight Light
        (intensity 1)
        (pos '(-200 -200 -200))
        )

(tell scene (add newLight))

; request a light gray background for our image
(tell image (background ltGray))

; move the camera back, and take a picture
(tell camera 
      (pos '(0 500 -1000))
      (shoot))
Personal tools