なんとなく書いてみた。
某アニメのスプレーっぽくみえなくもない?
package { import flash.events.Event; import flash.display.Sprite; import flash.display.Shape; import flash.events.MouseEvent; import flash.ui.Mouse; import flash.display.Graphics; [SWF(backgroundColor=0xffffff,frameRate=60)] public class Spray extends Sprite { public var arr:Array; public var s:Shape; public var i:uint=0; public var j:Number=10; public function Spray() { arr = new Array(); stage.addEventListener(MouseEvent.MOUSE_DOWN,onMouseDown); stage.addEventListener(MouseEvent.MOUSE_UP,onMouseUp); } public function onMouseDown(event:MouseEvent):void{ stage.addEventListener(Event.ENTER_FRAME,onEnterFrame); } public function onMouseUp(event:MouseEvent):void{ stage.removeEventListener(Event.ENTER_FRAME,onEnterFrame); j=10; } public function onEnterFrame(event:Event):void{ s = new Shape; var g:Graphics = s.graphics; g.beginFill(0x000000); g.drawRect(mouseX+MathUtil.randomNum(-j,j),mouseY+MathUtil.randomNum(-j,j), MathUtil.randomInt(1,25),MathUtil.randomInt(1,25)); g.endFill(); arr.push(s); addChild(arr[i]); j+=0.5; if( arr.length > 10000 ) { removeChild(arr[0]); arr.splice(0,1); }else{ i++; } } } }
MathUtil.random*…はしばらく前のエントリで書いてたやつ。名前短くなってるけど。
コメントする