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:

$myMovie->setDimension(460,80);
$firstCircle=$myMovie->add($myShape3);
$firstCircle->moveTo(190,0);


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){
$x=$ra/2;
$y=$ra/2;
$ra=$ra/2;
$a = $ra * 0.414213562; // = tan(22.5 deg)
$b = $ra * 0.707106781; // = sqrt(2)/2 = sin(45 deg)
$circ=new SWFShape();
$circ->setLine(1,0,0,0,0);
$circ->setLeftFill($red,$gr,$bl);
$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));
$LilacCircle->moveTo(x,y);


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();
$circleshape->setRIGHTFill($circleshape->addFill(255,0,255,255));
$circleshape->setLine(5,255,255,255,255);
$circleshape->drawCircle(20);
$firstcirc=$myMovie->add($circleshape);
$firstcirc->moveTo(23,23);
header('Content-type: application/x-shockwave-flash');
$myMovie->output();
$myMovie->save("Circle.swf");
?>
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.

Result:



Magnified: