Notes to Lesson 4

The radius parameter for the circle function is the width and height of the circle x2. The radius draws a circle with a radius of 40 around the center point of the circle (so ends up being 80 pixels across). The placement of the circle in this lesson is centered on the page. Looking at the size of the page and the placement of the circle:


You can see that the center of the page is at 230, 40, but since the circle is 80x80, you would have to center it at 190,0 (230-40=190).

You can further reduce coding by adding the circle function codes into a function as follows:

function circle($red, $gr, $bl, $ra){
$a = $ra * 0.414213562; // = tan(22.5 deg)
$b = $ra * 0.707106781; // = sqrt(2)/2 = sin(45 deg)
$circ=new SWFShape();
$circ->movePenTo($x+$ra, $y);
$circ->drawCurveTo($x+$ra, $y-$a, $x+$b, $y-$b);
$circ->drawCurveTo($x+$a, $y-$ra, $x, $y-$ra);
$circ->drawCurveTo($x-$a, $y-$ra, $x-$b, $y-$b);
$circ->drawCurveTo($x-$ra, $y-$a, $x-$ra, $y);
$circ->drawCurveTo($x-$ra, $y+$a, $x-$b, $y+$b);
$circ->drawCurveTo($x-$a, $y+$ra, $x, $y+$ra);
$circ->drawCurveTo($x+$a, $y+$ra, $x+$b, $y+$b);
$circ->drawCurveTo($x+$ra, $y+$a, $x+$ra, $y);
return $circ;

Then you can call the function with the following code: $LilacCircle=$myMovie->add(circle(red,green,blue,size));

This way, you do not have to rewrite all those lines for every different color circle you want to use on one page.

Additionally, Ming has codes for a circle shape that is simpler, but some people complained that the results were not always as expected, and prefer the circle function instead. The code is as follows:

$myMovie = new SWFMovie();
$myMovie->setBackground(0x00, 0x00, 0xff);
$myMovie->setDimension(46, 46);
$circleshape = new SWFShape();
header('Content-type: application/x-shockwave-flash');
Below is the simpler circle code:

Again, looking at the above code, the width and height are 46, 46. The size of the circle is 20 (which results in a circle of 40 pixels). The setline is 5 (in white), which adds another 5 pixels around the circle. Therefore, to accommodate the added pixels and to center it on the background, I needed to make the background 46, 46, and center it at 23, 23. Looking at the result, you'll notice a background that is approximately 1/2 pixel wide around the circle.