home *** CD-ROM | disk | FTP | other *** search
Text File | 1995-06-22 | 2.5 KB | 68 lines | [TEXT/X_#9] |
- ; Tutorial 4: Transformations
- ;
- animate 30 ; this file defines a 30-frame animation
- ;
- ; Geometric transformations include the operations of
- ; rotation, scaling, and translation that were introduced
- ; in previous tutorials. However, there is quite a bit
- ; more to say.
- ;
- ; First of all, the scale transformation can optionally take
- ; a second parameter, as in "scale 2,5". The first parameter,
- ; 2, specifies a scaling factor in the horizontal direction, and
- ; the second parameter, 5, specifies a scaling factor in the
- ; vertical direction. "Scale 2" is equivalent to "scale 2,2".
- ; For example:
-
- graysquare scale 2,5 ; a 2-by-5 RECTANGLE
-
- ; Note that scaling a square by different factors in the
- ; horizontal and veritcal directions produces a rectangle.
- ; Applying the same transformation to a circle gives an ellipse.
- ;
- ; Besides the basic "translate" command, two other commands
- ; are provided for convenience: "xtranslate" and "ytranslate".
- ; "Xtranslate" does horizontal translation and "ytranslate" does
- ; vertical translation:
-
- circle scale 2,5 xtranslate 3
- ; equivalent to: circle scale 2,5 translate 3,0
- blackcircle scale 5,2 ytranslate 5
- ; equivalent to: blackcircle scale 5,2 translate 0,5
-
- ; (There are also "xscale" and "yscale" commands, which take
- ; one parameter and perform the obvious operations.)
- ;
- ; As for rotation, it is important to understand that "rotate"
- ; specifies a rotation about the point (0,0). So, in
-
- line scale 5 ytranslate -8 rotate 0:180
-
- ; the line rotates around the center of the window, not about is
- ; own center. You can specify a different center of rotation
- ; like this:
-
- line scale 3 xtranslate -8 rotate 0:180 about -8,0
-
- ; This line rotates about the point (-8,0), which happens
- ; to be its center.
- ;
- ; I have used examples of scaling and rotation in which the
- ; parameters were positive. Negative numbers are also allowed.
- ; Scaling by a negative number implies a reflection. Rotation
- ; by a negative number implies a clockwise rotation, while a
- ; positive rotation is counterclockwise.
- ;
- ; xModels-2D supports two additional transformations: xskew
- ; and yskew. For example:
-
- square scale 3
- xskew 0:2 ; apply a varying "horizontal slant"
- translate -6,6 ; move it so it can be seen easily
-
- blacksquare scale 3
- yskew 0:2 ; apply a varying "vertical slant"
- translate -6,-6 ; and move it
-
- ; ("Xskew a" moves the point (x,y) to (x+ay,y), and "yskew b"
- ; moves the point (x,y) to (x,y+bx).)