Sunday, May 1, 2011

How to draw lines, curves and shapes in Action Scripting 3.0

For drawing a blue line we will write code:

var sp:Sprite = new Sprite();
addChild(sp);
var g:Graphics = sp.graphics;
g.lineStyle(3, 0x1c2fba);
g.moveTo(80, 100);
g.lineTo(420, 100);

For drawing yellow and red lines we will write code:

var sp:Sprite = new Sprite();

addChild(sp);
var g:Graphics = sp.graphics;
g.lineStyle(3, 0xfaf100);
g.moveTo(80, 80);
g.lineTo(420, 150);
g.lineTo(400, 120);
g.lineTo(200, 120);
g.lineStyle(4, 0xFF0000);
g.moveTo(150, 175);
g.lineTo(400, 175);

For drawing curve we will write code;

var sp:Sprite = new Sprite();
addChild(sp);
var g:Graphics = sp.graphics;
g.lineStyle(2, 0x467608);
g.moveTo(150, 100);
g.curveTo(275, 0, 400, 100);
g.moveTo(0, 0);

For drawing a triangle and fill it with color we will write code:

var triangle:Sprite = new Sprite();
with (triangle.graphics) {
lineStyle(0);
beginFill(0x9e0fa3,1);
moveTo(50, 0);
lineTo(120, 120);
lineTo(0, 100);
lineTo(50, 0);
endFill();
}
triangle.x = 50;
triangle.y = 250;
addChild(triangle);

For drawing a Circle and fill it with color we will write code:

var shapes:Sprite = new Sprite();
var gr:Graphics = shapes.graphics;
gr.lineStyle(4, 0x068843, .5);
gr.beginFill(0x330066, .2);
gr.drawCircle(50,50,50);
gr.endFill();
shapes.x = 150;
shapes.y = 250;
addChild(shapes);

For drawing a Circle and fill it with color we will write code:

var shapes:Sprite = new Sprite();
var gr:Graphics = shapes.graphics;
gr.lineStyle(4, 0x330066, .5);
gr.beginFill(0x330066, .2);
gr.drawRect(125,0,100,100);
gr.endFill();
shapes.x = 150;
shapes.y = 250;
addChild(shapes);

Thanks. Looking for feedback.

No comments:

Post a Comment