flash on 2010-4-14
♥0 |
Line 51 |
Modified 2010-04-14 00:15:36 |
MIT License
archived:2017-03-10 15:31:39
ActionScript3 source code
/**
* Copyright kihon ( http://wonderfl.net/user/kihon )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/iiC6
*/
package
{
import flash.display.Sprite;
import flash.events.Event;
public class Main extends Sprite
{
private var balls:Array = new Array();
private const MAX:int = 40;
public function Main()
{
for (var i:int = 0; i < MAX; i++)
{
var ball:Ball = new Ball();
ball.x = Math.random() * 465;
ball.y = Math.random() * 465;
addChild(ball);
balls.push(ball);
}
addEventListener(Event.ENTER_FRAME, onEnterFrame);
}
private function onEnterFrame(event:Event):void
{
for (var i:int = 0; i < MAX; i++)
{
balls[i].move();
}
}
}
}
import flash.display.Sprite;
class Ball extends Sprite
{
public const RADIUS:int = Math.random() * 10 + 5;
public var vx:int = Math.random() * 10 + 5;
public var vy:int = Math.random() * 10 + 5;
public function Ball()
{
graphics.beginFill(int.MAX_VALUE * Math.random());
graphics.drawCircle(0, 0, RADIUS);
graphics.endFill();
}
public function move():void
{
this.x += vx;
this.y += vy;
if (this.x - RADIUS < 0) this.x = RADIUS, vx = Math.random() * 10 + 5;
if (this.y - RADIUS < 0) this.y = RADIUS, vy = Math.random() * 10 + 5;
if (stage.stageWidth <= this.x + RADIUS) this.x = stage.stageWidth - RADIUS, vx = -(Math.random() * 10 + 5);
if (stage.stageHeight <= this.y + RADIUS) this.y = stage.stageHeight - RADIUS, vy = -(Math.random() * 10 + 5);
}
}