forked from: マウスから逃げる
package
{
import flash.display.* ;
import flash.events.* ;
import flash.filters.* ;
[SWF(width="500", height="500", backgroundColor="0xFFFFFF", frameRate="40")]
public class RunAwayFromMouse extends Sprite
{
private var num:int = 300 ;
private var firstPointX:Array = new Array( ) ;
private var firstPointY:Array = new Array( ) ;
public function RunAwayFromMouse( )
{
stage.scaleMode = StageScaleMode.NO_SCALE ;
//stage.align = StageAlign.TOP_LEFT ;
for ( var i:int=0; i < num; i++ )
{
var circle:Shape=new Shape( ) ;
circle.graphics.beginFill( 0xFFFFFF ) ;
circle.graphics.drawCircle( 0, 0, Math.random() * 40 + 5 ) ;
circle.graphics.endFill( ) ;
var theta:Number = Math.PI * 2 * Math.random( ) ;
var d:Number=stage.stageWidth / 8 ;
circle.x= stage.stageWidth / 2 + Math.random( ) * d * Math.cos( theta ) + 100 * Math.cos( theta ) ;
circle.y= stage.stageHeight / 2 + Math.random( ) * d * Math.sin( theta ) + 100 * Math.sin( theta ) ;
circle.name = "circle" + i.toString( ) ;
circle.filters= [ new BlurFilter( 10, 10, 1 ), new GlowFilter( 0xAABB33, 1, 15, 15, 15 ) ] ;
addChild( circle ) ;
filters = [ new DropShadowFilter( 50, 45, 0xDDDDAA, 1, 0, 0, 5 ) ] ;
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 = 3500 / Math.sqrt( Math.pow( mouseX - circle.x, 2 ) + Math.pow( mouseY - circle.y, 2 ) ) ;
circle.x += d * Math.cos( theta ) + ( firstPointX[i] - circle.x ) * .1;
circle.y += d * Math.sin( theta ) + ( firstPointY[i] - circle.y ) * .1;
}
}
}
}