MySQL Conference and Expo April 14-17, 2008, Santa Clara, CA

PHP Powers FreeMovie API for Flash
Pages: 1, 2

### Basic Shape Toolbox

The FreeMovieCompilerToolbox defines the following basic empty shapes:

• Straight line
DefineStraightLine(\$X1, \$Y1, \$X2, \$Y2, \$Width, \$AlphaFlag, \$R, \$G, \$B, \$A)
• Triangle
DefineTriangle(\$X1, \$Y1, \$X2, \$Y2, \$X3, \$Y3, \$Width, \$AlphaFlag, \$R, \$G, \$B, \$A)
• Rectangle
DefineRectangle(\$X1, \$Y1, \$X2, \$Y2, \$Width, \$AlphaFlag, \$R, \$G, \$B, \$A)
• Regular Polygon
DefinePolygon(\$Segments, \$X1, \$Y1, \$Radius, \$Width, \$AlphaFlag, \$R, \$G, \$B, \$A)
DefineBezierQuad(\$Accuracy, \$X1, \$Y1, \$ControlX, \$ControlY, \$X2, \$Y2, \$Width, \$AlphaFlag, \$R, \$G, \$B, \$A)
DefineCurvedLine(\$X1, \$Y1, \$ControlX, \$ControlY, \$X2, \$Y2, \$Width, \$AlphaFlag, \$R, \$G, \$B, \$A)
• Bezier Cubic Curve
DefineBezierCubic(\$Accuracy, \$X1, \$Y1, \$ControlX1, \$ControlY1, \$ControlX2, \$ControlY2, \$X2, \$Y2, \$Width, \$AlphaFlag, \$R, \$G, \$B, \$A)
• Circle
DefineCircle(\$Accuracy, \$X1, \$Y1, \$Radius, \$Width, \$AlphaFlag, \$R, \$G, \$B, \$A)
• Arc
DefineArc(\$Accuracy, \$X1, \$Y1, \$Angle1, \$Angle2, \$Radius, \$Width, \$AlphaFlag, \$R, \$G, \$B, \$A)
• Closed Arc
DefineArcClosed(\$Accuracy, \$X1, \$Y1, \$Angle1, \$Angle2, \$Radius, \$Width, \$AlphaFlag, \$R, \$G, \$B, \$A)

The meanings of the arguments used in these functions are as follows:

• X and Y coordinates control positioning of start, end, or center points of shapes. The numeric index indicates the order in which points are arranged in the shape.
• ControlX and ControlY coordinates control the positioning of curve control points.
• Width controls the width of the shape outline.
• Accuracy defines the number of segments used to construct arcs, circles, or curves.
• Angle controls the from and to angles of arcs (Angle1 and Angle2 respectively).
• R, G, B, and A control the red, green, blue, and alpha channel (transparency) settings for the shape color. The value of A is considered only when AlphaFlag is set to true.
• Segments defines the number of segments used to construct polygons.

Careful readers will notice that there are two functions for drawing second-degree Bezier curves: DefineBezierQuad() and DefineCurvedLine(). DefineCurvedLine() creates curves which are always smooth, while DefineBezierQuad() creates curves with varying degrees of smoothness. Also, the third-degree Bezier curves can be drawn with a varying degree of accuracy.

To see a full set of basic non-filled shapes and learn how they are defined in FreeMovie fashion, the readers are encouraged to study the following example. The results should be similar to the drawing shown in the figure below, after the code listing.

<?php

//-----------------------------------------------------//
// the header() function must _always_ be called first //
//-----------------------------------------------------//

//-------------------------------------------------------
// import the FreeMovieCompilerTollbox

require_once("freemoviecompilertoolbox.php");

//-------------------------------------------------------
// initialize new SWF object.

\$swf = new FreeMovieCompilerToolbox;

//-------------------------------------------------------
// set the global parameters of your movie
// frame size is in twips (1 twip = 20 pixels)

\$swf->SetSWFVersion(5);
\$swf->SetFrameSize(16000, 12000); // = 800 x 20, 600 x 20
\$swf->SetFrameRate(24.0);
\$swf->SetBackgroundColor(255, 255, 255);

//-------------------------------------------------------
// lights! camera! action!

\$swf->BeginMovie();

//-------------------------------------------------------
// frame # 00000

\$CharacterInfo = \$swf->DefineStraightLine(2000, 8000, 4000, 10000, 300, false, 0, 0, 0, 0);
\$CharacterDepth = \$swf->EasyPlaceObject(\$CharacterInfo["CharacterID"]);
\$CharacterInfo = \$swf->DefineStraightLine(2000, 10000, 4000, 8000, 300, true, 255, 0, 0, 128);
\$CharacterDepth = \$swf->EasyPlaceObject(\$CharacterInfo["CharacterID"]);

\$CharacterInfo = \$swf->DefineTriangle(6000, 8000, 8000, 10000, 10000, 8000, 300, false, 0, 0, 0, 0);
\$CharacterDepth = \$swf->EasyPlaceObject(\$CharacterInfo["CharacterID"]);

\$CharacterInfo = \$swf->DefineRectangle(12000, 8000, 14000, 10000, 300, false, 0, 0, 0, 0);
\$CharacterDepth = \$swf->EasyPlaceObject(\$CharacterInfo["CharacterID"]);

\$CharacterInfo = \$swf->DefinePolygon(5, 3000, 6000, 1000, 300, false, 0, 0, 0, 0);
\$CharacterDepth = \$swf->EasyPlaceObject(\$CharacterInfo["CharacterID"]);

\$CharacterInfo = \$swf->DefineBezierQuad(17, 6000, 5000, 8000, 9000, 10000, 5000, 300, false, 0, 0, 0, 0);
\$CharacterDepth = \$swf->EasyPlaceObject(\$CharacterInfo["CharacterID"]);

\$CharacterInfo = \$swf->DefineBezierCubic(17, 12000, 5000, 12000, 7000, 14000, 5000, 14000, 7000, 300, false, 0, 0, 0, 0);
\$CharacterDepth = \$swf->EasyPlaceObject(\$CharacterInfo["CharacterID"]);

\$CharacterInfo = \$swf->DefineCurvedLine(2000, 2000, 3000, 6000, 4000, 2000, 300, false, 0, 0, 0, 0);
\$CharacterDepth = \$swf->EasyPlaceObject(\$CharacterInfo["CharacterID"]);

\$CharacterInfo = \$swf->DefineCircle(17, 6500, 3000, 1000, 300, false, 0, 0, 0, 0);
\$CharacterDepth = \$swf->EasyPlaceObject(\$CharacterInfo["CharacterID"]);

\$CharacterInfo = \$swf->DefineArc(17, 10000, 3000, 0, 1.5 * pi(), 1000, 300, false, 0, 0, 0, 0);
\$CharacterDepth = \$swf->EasyPlaceObject(\$CharacterInfo["CharacterID"]);

\$CharacterInfo = \$swf->DefineArcClosed(17, 13000, 3000, 0, 1.5 * pi(), 1000, 300, false, 0, 0, 0, 0);
\$CharacterDepth = \$swf->EasyPlaceObject(\$CharacterInfo["CharacterID"]);

//-------------------------------------------------------
// end frame # 00000

\$swf->EndFrame();

//-------------------------------------------------------
// That's it, Folks!

\$swf->EndMovie();

//-------------------------------------------------------
// send movie to the browser

print \$swf->GetMovie();

exit;
?>

### Final Thoughts

As you can see, even though FreeMovie is a new kid on the block, it has some powerful abilities. I hope to show you other functions such as solid and gradient fills in a future article.

Jacek Artymiak started his adventure with computers in 1986 with Sinclair ZX Spectrum. He's been using various commercial and Open Source Unix systems since 1991. Today, Jacek runs devGuide.net, writes and teaches about Open Source software and security, and tries to make things happen.