topical media & game development
actionscript-book-GeometricShapes-com-example-programmingas3-geometricshapes-RegularPolygon.ax
actionscript-book-GeometricShapes-com-example-programmingas3-geometricshapes-RegularPolygon.ax
[swf]
flex
package
{
A regular polygon is equilateral (all sides are the same length)
and equiangular (all interior angles are the same).
public class @ax-actionscript-book-GeometricShapes-com-example-programmingas3-geometricshapes-RegularPolygon implements actionscript_book_GeometricShapes_com_example_programmingas3_geometricshapes_IPolygon
{
public var numSides:Number
public var sideLength:Number;
public function @ax-actionscript-book-GeometricShapes-com-example-programmingas3-geometricshapes-RegularPolygon(len:Number = 100, sides:Number = 3):void
{
this.sideLength = len;
this.numSides = sides;
}
public function getArea():Number
{
// this method should be overridden in subclasses
return 0;
}
public function getPerimeter():Number
{
return sideLength * numSides;
}
public function getSumOfAngles():Number
{
if (numSides >= 3)
{
return ((numSides - 2) * 180);
}
else
{
return 0;
}
}
public function describe():String
{
var desc:String = "Each side is " + sideLength + " pixels long.\n";
desc += "Its area is " + getArea() + " pixels square.\n";
desc += "Its perimeter is " + getPerimeter() + " pixels long.\n";
desc += "The sum of all interior angles in this shape is " + getSumOfAngles() + " degrees.\n";
return desc;
}
}
}
(C) Æliens
27/08/2009
You may not copy or print any of this material without explicit permission of the author or the publisher.
In case of other copyright issues, contact the author.