2. • The drawing API is the name for the functionality built into ActionScript that allows you to create vector
graphics—lines, curves, shapes, fills, and gradients—and display them on the screen using ActionScript.
• The following reference list contains important terms that you will encounter in this chapter:
– Anchor point: One of the two end points of a quadratic Bézier curve.
– Control point: The point that defines the direction and amount of curve of a quadratic Bézier
curve. The curved line never reaches the control point; however, the line curves as though being
drawn toward the control point.
– Coordinate space: The graph of coordinates contained in a display object, on which its child
elements are positioned.
– Fill: The solid inner portion of a shape that has a line filled in with color, or all of a shape that has no
outline.
– Gradient: A color that consists of a gradual transition from one color to one or more other colors
(as opposed to a solid color).
– Point: A single location in a coordinate space. In the 2-d coordinate system used in ActionScript, a
point is defined by its location along the x axis and the y axis (the point’s coordinates).
– Quadratic Bézier curve: A type of curve defined by a particular mathematical formula. In this type
of curve, the shape of the curve is calculated based on the positions of the anchor points (the end
points of the curve) and a control point that defines the amount and direction of the curve.
– Scale: The size of an object relative to its original size. When used as a verb, to scale an object
means to change its size by stretching or shrinking the object.
– Stroke: The outline portion of a shape that has a line filled in with color, or the lines of an un-filled
shape.
– Translate: To change a point’s coordinates from one coordinate space to another.
– X axis: The horizontal axis in the 2-d coordinate system used in ActionScript.
– Y axis: The vertical axis in the 2-d coordinate system used in ActionScript.
3. Drawing straight lines
var triangleHeight:uint = 100;
var triangle:Shape = new Shape();
// red triangle, starting at point 0, 0
triangle.graphics.beginFill(0xFF0000);
triangle.graphics.moveTo(triangleHeight/2, 0);
triangle.graphics.lineTo(triangleHeight, triangleHeight);
triangle.graphics.lineTo(0, triangleHeight);
triangle.graphics.lineTo(triangleHeight/2, 0);
// green triangle, starting at point 200, 0
triangle.graphics.beginFill(0x00FF00);
triangle.graphics.moveTo(200 + triangleHeight/2, 0);
triangle.graphics.lineTo(200 + triangleHeight, triangleHeight);
triangle.graphics.lineTo(200, triangleHeight);
triangle.graphics.lineTo(200 + triangleHeight/2, 0);
this.addChild(triangle);