Ming the Tutorial
Drawing
The fundamental object in a flash movie is a shape. Or, in Ming, an SWFShape. In php, you instantiate an SWFShape with the simple expression
Even though the Ming library is written in plain C code, it's designed to be used in an object-oriented environment; therefore, in PHP you access Ming's drawing functions through the SWFShape object. To draw a red square 400 units on each side with a line width of 20 units:new SWFShape();First, a note about units: the flash specification indicates a scale of twenty units per pixel, so the square generated with the above code would be 20 pixels square and have a line with of one pixel. However, this scale is nowhere enforced; the actual rendered scale depends only on the size you specify when you embed the movie in your html code and the frame size listed inside the movie (more on that later). We might as well have drawn the square at 20 units with a line with of 1 unit. Either way, we get the same square if we scale the movie along with it.$s = new SWFShape(); $s->setLine(20, 0xff, 0, 0); $s->drawLineTo(400, 0); $s->drawLineTo(400, 400); $s->drawLineTo(0, 400); $s->drawLineTo(0, 0);Now, you probably noticed that the drawLineto method only takes two arguments whereas a general line has four parameters, both an x and y coordinate for both endpoints. And you likely concluded (clever you) that this means drawing in Ming is pen-based; that is, the shape object keeps track of an imaginary pen's location on the drawing surface, and drawing commands implicitly reference and affect the pen's location. This should be even more apparent when you learn that drawLineTo has a related function drawLine which uses relative positioning instead of absolute coordinates. In other words, the drawing functions above could be replaced with
and we'd have the same red square.$s->drawLine(400, 0); $s->drawLine(0, 400); $s->drawLine(-400, 0); $s->drawLine(0, -400);The setLine method takes four (or five) arguments: the line width, and the red, green, and blue (and optionally alpha) components of the line's color. When you set the line style, it applies to all subsequent drawing commands until you change the line style again with setLine. To have no line style (which, by the way, is the default for shapes), just set the width to zero.
Finally, there are two more useful drawing commands:
moves the pen to coordinates (x,y) without drawing a line (and movePen is its relativistic cousin), while$s->movePenTo(x,y);draws a simple quadratic bezier curve from the current pen location to point (ax,ay) using the point (cx,cy) as a control point. As expected, drawCurve does the same thing, but uses coordinates relative to the current pen position.$s->drawCurveTo(cx, cy, ax, ay);Macromedia(r) and Flash(tm) are trademarks or registered trademarks of Macromedia, Inc. in the United States and/or other countries.
Macromedia(r) does not sponsor, affiliate, or endorse this product and/or services.