Wednesday, October 3, 2012

Draw a tree only using actionscript

There are two ways to create a flash:
Draw in Flash CS5 or Create flash using Actionscript.
I am a programmer rather than an artisit. I tend to create flash only using actionscript.
Draw a tree only using actionscript demo:
1) Open new document in Flash CS5, select actionscript 3.0
2) Press F9, paste the following code:
var sec:Sprite=new Sprite();
var mc =;
function dl(ax, ay, bx, by) {
mc.moveTo(ax, ay);
mc.lineStyle(0, 0x008000, 100);
mc.lineTo(bx, by);
function lzh(x, y, l, angle, n) {
if (n>0) {

var a_l, a_r, x1, x1_l, x1_r, y1, y1_l, y1_r, x2, x2_l, y2, y2_l, x2_r, y2_r;
x1 = x+0.5*l*Math.cos(angle*Math.PI/180);
y1 = y-0.5*l*Math.sin(angle*Math.PI/180);
x2 = x+l*Math.cos(angle*Math.PI/180);
y2 = y-l*Math.sin(angle*Math.PI/180);
dl(x, y, x2, y2);
a_l = angle+30;
a_r = angle-30;
l = l*2/3;
lzh(x2, y2, l, angle-Math.random()*10, n-1);
lzh(x1, y1, l*2/3, a_l, n-1);
lzh(x1, y1, l*2/3, a_r, n-1);
lzh(x2, y2, l*2/3, a_l, n-1);
lzh(x2, y2, l*2/3, a_r, n-1);
lzh(300, 400, 120, 90, 6);
var AuthorInfo:TextField=new TextField();
 AuthorInfo.text="@Jiansen Lu";

No comments:

Post a Comment