半年前,同事说,他可以用几何画板做出“勾股树”,而用FLASA就不能做,我当时很有信心地说:只要用几何画板可以做的东西,用FLASH一定可以做。为此我费了好长时间没有做成,很有点惭愧,直到今天,我终于做成了,真是高兴。
源代码如下:
var a:Number=-1;
var w:Number=100;
var n:Number=4;
var i,j:Number;
var p:Array=new Array();
var t:Number=0;
for (i=0;i<n+1;i++)
{
p.push(new Array(2));
}
//trace(t);
var rgb1:Number=0xff0000;
var rgb2:Number=0x00ff00;
var rgb3:Number=0x0000ff;
p[1][1]=_root.createEmptyMovieClip("p11",1);
with(p[1][1])
{
beginFill(rgb1,100);
lineStyle(0,rgb1,100);
moveTo(0,0);
lineTo(w,0);
lineTo(w,-w);
lineTo(0,-w);
lineTo(0,0);
endFill();
}
p[1][1]._x=200;
p[1][1]._y=400;
p[1][1].w=p[1][1]._width;
onEnterFrame=function()
{
if(t==0||t==90)
{
a=-a;
}
t+=a;
for(i=1;i<n;i++)
{
for(j=1;j<Math.pow(2,(i-1))+1;j++)
{
drawmc(p,t,i,j);
}
}
}
//FUNCTION
function drawmc(q:Object,k:Number,ii:Number,jj:Number)
{
q[ii+1][2*jj-1]=q[ii][jj].createEmptyMovieClip("p"+((ii+1)*1000+(2*jj-1)),1);
q[ii+1][2*jj]=q[ii][jj].createEmptyMovieClip("p"+((ii+1)*1000+(2*jj)),2);
q[ii+1][2*jj-1].w=q[ii][jj].w*Math.cos(k*Math.PI/180);
q[ii+1][2*jj].w=q[ii][jj].w*Math.sin(k*Math.PI/180);
with(q[ii+1][2*jj-1])
{
beginFill(rgb2,100);
lineStyle(0,rgb1,100);
moveTo(0,0);
lineTo(q[ii+1][2*jj-1].w,0);
lineTo(q[ii+1][2*jj-1].w,-q[ii+1][2*jj-1].w);
lineTo(0,-q[ii+1][2*jj-1].w);
lineTo(0,0);
endFill();
}
with(q[ii+1][2*jj])
{
beginFill(rgb3,100);
lineStyle(0,rgb1,100);
moveTo(0,0);
lineTo(-q[ii+1][2*jj].w,0);
lineTo(-q[ii+1][2*jj].w,-q[ii+1][2*jj].w);
lineTo(0,-q[ii+1][2*jj].w);
lineTo(0,0);
endFill();
}
q[ii+1][2*jj-1]._rotation=-k;
q[ii+1][2*jj]._rotation=90-k;
if(Math.floor(jj/2)==jj/2)
{
q[ii+1][2*jj-1]._x=-q[ii][jj].w;
q[ii+1][2*jj-1]._y=-q[ii][jj].w;
q[ii+1][2*jj]._x=0;
q[ii+1][2*jj]._y=-q[ii][jj].w;
}
else
{
q[ii+1][2*jj-1]._x=0;
q[ii+1][2*jj-1]._y=-q[ii][jj].w;
q[ii+1][2*jj]._x=q[ii][jj].w;
q[ii+1][2*jj]._y=-q[ii][jj].w;
}
}
用FLASH做勾股树
最新推荐文章于 2022-07-23 16:13:34 发布