home *** CD-ROM | disk | FTP | other *** search
/ MacWorld 1995 November / Macworld Nov ’95.toast / Education / xModels 2D and 3D / Tutorial Examples / Tutorial 5. Defining Objects < prev    next >
Encoding:
Text File  |  1995-06-20  |  2.3 KB  |  69 lines  |  [TEXT/X_#9]

  1. ; Tutorial 5: Defining Objects
  2. ;
  3.       animate 20  ; This file defines a 20-frame animation
  4. ;
  5. ; In xModels-2D and xModels-3D, it is possible to define
  6. ; new "composite" objects which can then be used in exactly
  7. ; the same way as basic objects like line and circle.
  8. ; For example:
  9.  
  10.       define wheel ; Begin definition of an object named "wheel".
  11.           [        ; The definition is between a "[" and a "]".
  12.             circle     ; List of objects that make up a "wheel".
  13.             line
  14.             line rotate 60
  15.             line rotate 120
  16.           ]        ; End of definition of wheel
  17.  
  18. ; This definition just defines what is meant by a "wheel".
  19. ; It doesn't add anything to the scene.  But once a wheel
  20. ; has been defined, you can add a wheel to a scene in the
  21. ; same way you would add a basic object:  just list its
  22. ; name.  Furthermore, you can apply transformations to a
  23. ; wheel.  The transformation applies to the wheel as a whole.
  24.  
  25.         wheel  ; a wheel (consisting of a circle of diameter
  26.                ; one and three lines of length 1) is shown
  27.                ; in its standard position at the center of
  28.                ; the screen
  29.  
  30.         wheel scale 6       ; a wheel of diameter 6
  31.               rotate 0:60   ; rotating
  32.               translate 5,5 ; and moved so its center is (5,5)
  33.  
  34.         wheel scale 8,3      ; an elliptical "wheel"!
  35.               rotate 0:60
  36.               translate -5,5
  37.  
  38.         wheel rotate 0:60     ; another elliptical "wheel",
  39.               scale 8,3       ; but here the rotation is done
  40.               translate -5,-5 ; before the scaling
  41.  
  42.  
  43. ; Once an object has been defined, it can even be used in
  44. ; the definitions of other objects.  Also note that an
  45. ; object can have moving parts, as in this example:
  46.  
  47.       define pinwheel [  ; a spinning bow at the end of a stick
  48.          graypolygon 0,0 1,1 1,-1 -1,1 -1,-1
  49.             rotate 0:-180
  50.             xtranslate 5
  51.          square scale 5.2,0.2 xtranslate 2.5
  52.        ]
  53.  
  54.       define multipin [  ; six pinwheels at various angles
  55.          pinwheel
  56.          pinwheel rotate 60
  57.          pinwheel rotate 120
  58.          pinwheel rotate 180
  59.          pinwheel rotate 240
  60.          pinwheel rotate 300
  61.         ;circle scale 7
  62.       ]
  63.  
  64.       multipin
  65.         scale 0.5
  66.         rotate 0:60
  67.         translate 5,-5
  68.  
  69.