forked from: forked from: 泡
クリックで泡発生
// forked from hacker_9lgcya8a's forked from: 泡
// forked from matsu4512's 泡
//クリックで泡発生
package {
import __AS3__.vec.Vector;
import flash.display.BlendMode;
import flash.display.Sprite;
import flash.display.StageAlign;
import flash.display.StageScaleMode;
import flash.events.Event;
import flash.events.MouseEvent;
import flash.geom.Point;
[SWF(backgroundColor="#000000", frameRate="30", width="512", height="512")]
public class Bubble extends Sprite
{
private const GRAVITY:Number = 0.1; //重力
private var particles:Vector.<Particle>;
private var w:Number;
private var h:Number;
public function Bubble()
{
if(stage)
addEventListener(Event.ADDED_TO_STAGE, init);
else
init();
}
private function init(event:Event = null):void{
stage.scaleMode = StageScaleMode.NO_SCALE;
stage.align = StageAlign.TOP_LEFT;
removeEventListener(Event.ADDED_TO_STAGE, init);
w = stage.stageWidth;
h = stage.stageHeight;
particles = new Vector.<Particle>();
stage.addEventListener(MouseEvent.CLICK, click);
addEventListener(Event.ENTER_FRAME, loop);
}
private function click(event:MouseEvent):void{ //円を飛び散らせる
var pos:Point = new Point(mouseX, mouseY); //クリックした座標
var p:Particle;
p = new Particle(pos.x, pos.y, 0, -Math.random()*5-2, Math.random()*30+20, Math.random()*(0x3366ff-0x3366cc) + 0x3366CC, true);
particles.push(p);
addChild(p);
}
private function func(item:Particle, index:int, vec:Vector.<Particle>):Boolean{
if(item.bubble){
if(item.visible==false){
removeChild(item);
return false;
}
}else{
if(item.x < 0 || item.x > w || item.y > h){
removeChild(item);
item.visible = false;
return false;
}
}
return true;
}
private function loop(event:Event):void{
particles = particles.filter(func);
for each(var p:Particle in particles){
if(p.bubble){
p.y += p.vy;
p.x +=Math.sin(Math.random()*2*Math.PI)*2;
if(p.y < 0 && p.visible){
var pp:Particle;
for(var i:uint = 0; i < p.size; i++){
pp = new Particle(p.x, p.y, Math.random()*10-5, Math.random()*10-5, Math.random()*15+5, Math.random()*(0x3366ff-0x3366cc) + 0x3366CC, false);
particles.push(pp);
addChild(pp);
}
p.visible = false;
}
}else{
p.x += p.vx;
p.y += p.vy;
p.vy += GRAVITY;
}
}
}
}
}
import flash.display.Shape;
import flash.display.BlendMode;
import flash.filters.BlurFilter;
class Particle extends Shape{
public var vx:Number;
public var vy:Number;
public var size:Number;
public var color:uint;
public var bubble:Boolean;
public function Particle(x:Number=0, y:Number=0, vx:Number=0, vy:Number=0, size:Number=5, color:uint=0xFFFFFF, bubble:Boolean=false){
this.bubble = bubble;
this.x = x;
this.y = y;
this.vx = vx;
this.vy = vy;
this.size = size;
this.color = color;
this.blendMode = BlendMode.ADD;
this.filters = [new BlurFilter(10, 10, 1)];
graphics.beginFill(color);
graphics.drawCircle(0, 0, size);
graphics.endFill();
}
}