1.构建小球精灵
Ball.as
package
{
import flash.display.Sprite;
public class Ball extends Sprite
{
public var radius:Number;
public var color:uint;
public function Ball (radius:Number,color:uint)
{
this.radius=radius;
this.color=color;
Init ();
}
public function Init ():void
{
graphics.beginFill (color);
graphics.drawCircle (0,0,radius);
graphics.endFill ();
}
}
}
2.构建赛平斯基垫片
Sierpinski.as
package
{
import flash.display.Sprite;
public class Sierpinski extends Sprite
{
private var ball:Ball;
private var balls:Array;
private var numDots:int=1000;
public function Sierpinski()
{
Init();
}
private function Init():void
{
balls=new Array();
for(var i:int=0;i<numDots;i++)
{
var ball=new Ball(1,0xFF0000);
addChild(ball);
balls.push(ball);
}
balls[0].x=10;
balls[0].y=10;
balls[1].x=400;
balls[1].y=30;
balls[2].x=200;
balls[2].y=300;
for(var i:int=0;i<numDots-1;i++)
{
var index:int=Math.random()*3;
balls[i+1].x=(balls[i].x+balls[index].x)/2;
balls[i+1].y=(balls[i].y+balls[index].y)/2;
}
}
}
}
注意:如果显示不对,多ctrl+Enter几次。
posted @
2009-01-05 17:21
HelloCG
阅读(
203)
评论()
编辑
收藏
举报