Forked from: sakef's マウスから逃げる diff:68 AS?? chinkurosanb.. forked:2favorite:2lines:43license : All rights reserved modified : 2009-03-04 19:53:02 Embed Tweet package { import flash.display.BlendMode; import flash.display.Shape; import flash.display.Sprite; import flash.events.Event; import flash.filters.BlurFilter; [SWF(width="500", height="500", backgroundColor="0xffffff", frameRate="40")] public class RunAwayFromMouse extends Sprite { private var num:int=100; private var firstPointX:Array=new Array(); private var firstPointY:Array=new Array(); public function RunAwayFromMouse() { for(var i:int=0; i < num; i++) { var circle:Shape=new Shape(); circle.graphics.beginFill(Math.random() * 0x111111); circle.graphics.drawCircle(0, 0, 30); circle.graphics.endFill(); circle.blendMode=BlendMode.MULTIPLY; circle.x=Math.round(Math.random() * stage.stageWidth); circle.y=Math.round(Math.random() * stage.stageHeight); circle.name="circle" + i.toString(); addChild(circle); firstPointX[i]=circle.x; firstPointY[i]=circle.y; } addEventListener(Event.ENTER_FRAME, onFrame); } public function onFrame(e:Event):void { for(var i:int=0; i < num; i++) { var circle:Shape=getChildByName("circle" + i.toString())as Shape; var theta:Number=Math.atan2((circle.y - mouseY), (circle.x - mouseX)); var d:Number=1000 / Math.sqrt(Math.pow(mouseX - circle.x, 2) + Math.pow(mouseY - circle.y, 2)); circle.x+=d * Math.cos(theta) + (firstPointX[i] - circle.x) * 0.08; //circle.y+=d * Math.sin(theta) + (firstPointY[i] - circle.y) * 0.08; } } } } Code Fullscreen Preview Fullscreen xxxkurosukex.. Angelo : kolieska toString mouseY mouseX Math.round Math.pow getChildByName blendMode name Math.atan2 Math.sqrt addEventListener addChild Math.cos Array Event.ENTER_FRAME Math.random Event Sprite int Number sort new page view favorite forked pv173 forked from: AS?? sato2 forked:3 favorite:1lines:44 (diff:2) pv62 forked from: AS?? mitand forked:0 favorite:0lines:44 (diff:5)