[オブジェクトの再作成]噴水
右向きの初期ベクトル(ball.vx = Math.random()*5-1;)と、左向きの風(wind:Number = -0.13; // ball.vx+=wind;)を使ってそれっぽく?なっている。?
/**
* Copyright Nowloading_ ( http://wonderfl.net/user/Nowloading_ )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/5F4u
*/
// forked from ton_'s 領域外に出たスプライトの削除
package {
import flash.display.Sprite;
import flash.display.StageAlign;
import flash.display.StageScaleMode;
import flash.events.Event;
public class Removal extends Sprite{
private var count:int=100;
private var balls:Array;
private var gravity:Number = 0.5;
private var wind:Number = -0.13;
//領域の設定
private var top:Number = 50;
private var bottom:Number = 365;
private var left:Number = 50;
private var right:Number =365;
public function Removal(){
init();
}
private function init():void{
stage.scaleMode = StageScaleMode.NO_SCALE;
stage.align = StageAlign.TOP_LEFT;
balls = new Array();
for(var i:int=0;i<count;i++){
var color:uint = Math.random()*0xff0000;
var ball:Ball = new Ball(2,color);
ball.x = right/2;
ball.y = bottom;
ball.vx = Math.random()*5-1;
ball.vy = Math.random()*-10-7;
addChild(ball);
balls.push(ball);
}
addEventListener(Event.ENTER_FRAME,onEnterFlame);
}
private function onEnterFlame(e:Event):void{
for(var i:Number=0;i<balls.length;i++){
var ball:Ball = Ball(balls[i]);
ball.vx+=wind;
ball.vy+=gravity;
ball.x+=ball.vx;
ball.y+=ball.vy;
if(ball.x-ball.radius>right ||
ball.x+ball.radius<left ||
ball.y-ball.radius>bottom ||
ball.y+ball.radius<top){
ball.x = right/2;
ball.y = bottom;
ball.vx = Math.random()*5-1;
ball.vy = Math.random()*-10-7;
}
}
}
}
}
import flash.display.Sprite;
class Ball extends Sprite{
public var radius:Number;
public var color:uint;
public var vx:Number =0;
public var vy:Number =0;
public function Ball(radius:Number = 40,color:uint = 0xff0000){
this.radius = radius;
this.color = color;
init();
}
public function init():void{
graphics.beginFill(color);
graphics.drawCircle(0,0,radius);
graphics.endFill();
}
}