flash on 2013-3-18
♥0 |
Line 84 |
Modified 2013-04-13 13:51:38 |
MIT License
archived:2017-03-20 05:28:13
ActionScript3 source code
/**
* Copyright J.J ( http://wonderfl.net/user/J.J )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/4NuC
*/
package {
import flash.filters.ConvolutionFilter;
import flash.filters.BlurFilter;
import flash.events.Event;
import flash.display.MovieClip;
import flash.events.MouseEvent;
import flash.text.TextFieldAutoSize;
import flash.text.TextField;
import flash.display.BitmapData;
import flash.display.Bitmap;
import flash.display.Sprite;
public class FlashTest extends Sprite {
private var w:uint,h:uint
private var mainbmp:Bitmap
private var txt:TextField
private var particles:Vector.<Particle>
private var num_particle:uint
private var container:MovieClip
private var cf:ConvolutionFilter
public function FlashTest() {
stage.frameRate=60
w=stage.stageWidth,h=stage.stageHeight;
mainbmp=new Bitmap;
mainbmp.bitmapData=new BitmapData(w,h,false,0xffffff);
stage.addChild(mainbmp)
txt=new TextField;
txt.textColor=0xff0000;
txt.autoSize=TextFieldAutoSize.LEFT
stage.addChild(txt)
particles=new Vector.<Particle>()
container=new MovieClip;
cf=new ConvolutionFilter(3,3,
[.5,1,.5,
1,0,1,
.5,1,.5],5)
stage.addEventListener(Event.EXIT_FRAME,loop)
stage.addEventListener(MouseEvent.MOUSE_MOVE,onMouse_Move)
// write as3 code here..
}
private function loop(e:Event):void{
var l:uint=particles.length
for(var i:uint;i<l;i++){
particles[i].vy+=particles[i].g
particles[i].x+=particles[i].vx
particles[i].y+=particles[i].vy
if(particles[i].y>h) particles[i].vy*=-1
if(particles[i].x>w) particles[i].vx*=-1
if(particles[i].x<2) particles[i].vx*=-1
}
mainbmp.bitmapData.applyFilter(
mainbmp.bitmapData,
mainbmp.bitmapData.rect,
mainbmp.bitmapData.rect.topLeft,
cf)
mainbmp.bitmapData.draw(container)
}
private function onMouse_Move(e:MouseEvent):void{
num_particle++
txt.text=''+num_particle
var p:Particle=new Particle(0);
p.x=stage.mouseX
p.y=stage.mouseY
p.scaleX=p.scaleY=1+Math.random()/2
p.vx=3+Math.random()*-6
p.vy=Math.random()
p.g=Math.random()/2
container.addChild(p)
particles.push(p);
}
}
}
import flash.display.Shape;
class Particle extends Shape{
public var vx:Number;
public var vy:Number;
public var g:Number;
public var rad:Number=2;
public var color:uint;
public function Particle(c:uint=0):void{
color=c
this.graphics.beginFill(color)
this.graphics.drawCircle(0,0,rad)
this.graphics.endFill()
}
}