Hi there,
I am trying to construct an equilateral triangle with the following code, but I am not seeing what I would expect to.
I would expect to see a triangle drawn to the stage, but I don't see one.
I think there must be something wrong in terms of the location of the tri sprite on the screen.
public class test_drawing_triangle extends Sprite
{
public function test_drawing_triangle()
{
var tri:Sprite = new Sprite;
var nextx:int;
var nexty:int;
var prevx:int;
var prevy:int;
var angle:Number;
var radius:Number;
var deg:int;
var i:int;
radius = 10;
// tri.x = stage.stageWidth / 2;
tri.y = 50;
tri.graphics.clear();
tri.graphics.beginFill(0x000000, 0.5);
tri.graphics.moveTo(0,0);
for(deg = 0; deg < 360; deg += 120)
{
angle = deg * Math.PI / 180;
nextx = Math.cos(angle) * radius;
nexty = Math.sin(angle) * radius;
tri.graphics.lineTo(nextx, nexty);
}
tri.graphics.endFill();
addChild(tri);
}
}
UPDATE:
I can now see the triangle but it is not filled in. It seems to have the generally-correct shape, but I would expect for it be 3 sided, rather than 4. If anyone could take a sec to compile this and look at what I am describing it would really help.