Forked from: yd_niku's forked from: Water Particles diff:17 Fire Particles 炎的な感じに yd_niku forked:4favorite:12lines:149license : All rights reserved modified : 2009-02-24 15:12:35 Embed Tweet // forked from yd_niku's forked from: Water Particles // forked from yd_niku's Water Particles // 炎的な感じに package { import flash.display.*; import flash.events.*; import flash.geom.*; import flash.text.*; import flash.filters.*; import caurina.transitions.Tweener; [SWF(backgroundColor="#ffffff", frameRate=40)] public class FlashTest extends Sprite { private var _particles:Array = []; private var _label:TextField; private var _bmp:BitmapData; private var _container:Sprite; private var _filter:BitmapFilter= new ColorMatrixFilter([ 1, 0, 0, 0.1, 0, 0, 1, 0, 0.2, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0.7, 0 ]); private static const O:Point = new Point(); public function FlashTest() { _bmp = new BitmapData( stage.stageWidth, stage.stageHeight, true, 0x00FFFFFF ); addChild( new Bitmap(_bmp) ); _container = new Sprite(); addChild( _container ); var rect :Sprite= new Rect( stage.stageWidth, stage.stageHeight ); addChild( rect ); rect.addEventListener( MouseEvent.MOUSE_DOWN, startWater ); rect.addEventListener( MouseEvent.MOUSE_UP, stopWater ); rect.addEventListener( MouseEvent.CLICK, removeText ); rect.buttonMode = true; rect.useHandCursor = true; addEventListener( Event.ENTER_FRAME, onUpdate ); var t:TextField = new TextField(); t.mouseEnabled = false; t.width = 200; t.defaultTextFormat = new TextFormat("_sans", 12, 0x333366 ); t.text = "Please drag to create particles."; t.x = ( stage.stageWidth - t.width ) *0.5; t.y = ( stage.stageHeight- t.height ) *0.5; t.alpha = 0; _label = t; addChild( t ); Tweener.addTween( t, { alpha : 1, time:2, delay:0.3, transition:"easeInOutSine" } ); } private function removeText( e:Event ):void { e.currentTarget.removeEventListener( e.type, arguments.callee ); if( _label ) Tweener.addTween( _label, { alpha : 0, time:2, delay:0.3, transition:"easeInOutSine", onComplete: onRemoveLabel } ); } private function startWater ( e:Event ):void { addEventListener( Event.ENTER_FRAME, shot ); } private function stopWater ( e:Event ):void { removeEventListener( Event.ENTER_FRAME, shot ); } private function shot( e:Event = null ) :void { var num:uint = 6; var p:Particle; var o:Vector3D = new Vector3D( mouseX, mouseY, -10 ); for( var i:int=0; i<num;++i ) { p = new Fire( Math.random()*6+1, o.x +Math.random()*6-3, o.y+Math.random()*6-3, o.z, Math.random()*50-100, Math.random()*-50-50, 200 ); _container.addChild(p); _particles.push( p ); } } private function onRemoveLabel ():void { removeChild( _label ); _label = null; } private function onUpdate( e:Event ):void { var num:uint = _particles.length; var p:Particle; for( var i:int=0; i<num;++i ) { p = _particles[ i ] as Particle; if( p.checkLife() ) { p.update(); } else { if( contains(p) ) _container.removeChild( p ); } } _bmp.draw( _container ); _bmp.applyFilter( _bmp, _bmp.rect, O, _filter ); } } } import flash.display.*; import flash.geom.*; class Particle extends Sprite { public static const G:Number = 1; public static const FRICTION_X:Number = 0.96; public static const FRICTION_Y:Number = 0.96; public static const FRICTION_Z:Number = 0.96; public var mass:Number=1; public var vx:Number=0; public var vy:Number=0; public var vz:Number=0; public static var LIMIT_Z:Number =300; public function Particle ( smass:Number = 1, sx:Number=0, sy:Number = 0, sz:Number = 0, svx:Number=0, svy:Number=0, svz:Number = 0 ) { mass = smass; x = sx; y = sy; z = sz, vx = svx; vy = svy; vz = svz; } public function update():void { vy += G; vx *= FRICTION_X; vy *= FRICTION_Y; vz *= FRICTION_Z; x += vx*mass; y += vy*mass; z += vz*mass; if( z >= LIMIT_Z ) { vx = Math.random() *200 -100; vy = Math.random() *200 -100; vz = Math.random() * -500; } } public function checkLife() :Boolean { var v:Vector3D = new Vector3D( vx, vy, vz ); return v.length > 1; } } class Fire extends Particle { public function Fire( weight:Number, sx:Number=0, sy:Number = 0, sz:Number = 0, svx:Number=0, svy:Number=0, svz:Number=0 ) { super( 0.1, sx, sy, sz, svx, svy, svz ); graphics.lineStyle( 0, 0xff3300, 0.4+Math.random()*0.2 ); graphics.beginFill( 0xf09977, Math.random()*0.2 + 0.2 ); graphics.drawCircle( 0, 0, weight ); graphics.endFill(); } } class Rect extends Sprite { public function Rect( w:uint= 100, h:uint = 100 ) { graphics.beginFill( 0, 0 ); graphics.drawRect( 0, 0, w, h ); graphics.endFill(); } } Code Fullscreen Preview Fullscreen henoya jyyender Sairge fallen timothyd otias : Particleファンタ(オレンジ) demouth : particle気持ちいい naoto5959 : fireparticle飛び方がここちいい tan_go238 : particle blackwater : 火的艺术 nabe : 爆発 ish_xxxx : particle見てて気持ちいい Fire Particle useHandCursor buttonMode Vector3D mouseEnabled removeEventListener Tweener.addTween contains type endFill ColorMatrixFilter time beginFill callee removeChild mouseY addEventListener MouseEvent.MOUSE_UP mouseX MouseEvent.MOUSE_DOWN MouseEvent.CLICK sort new page view favorite forked pv61 forked from: Fire Particles sct73 forked:0 favorite:0lines:149 (diff:3) pv983 Leaves Particles yd_niku forked:0 favorite:6lines:157 (diff:35) tag: Particle effect particles pv282 forked from: Fire Particles skynet forked:0 favorite:0lines:149 (diff:1) pv611 forked from: Fire Particles coeyes forked:0 favorite:3lines:149 (diff:4) tag: Particle 伪3D