forked from: flash on 2010-1-10
new line to hide the Cursor*
/**
* Copyright takun336 ( http://wonderfl.net/user/takun336 )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/jq4V
*/
// forked from hourglasseye's flash on 2010-1-10
package
{
import flash.ui.Mouse; /// new line to hide the Cursor*
import flash.display.Sprite;
import flash.events.Event;
public class FleeingCircles extends Sprite
{
public function FleeingCircles()
{
var circles:Array = [];
for( var row:int = 0; row < 20; row++ )
{
for( var col:int = 0; col < 22; col++ )
{
var circle:FleeingCircle = new FleeingCircle( 50 + 50 * col, 70 + 5 * row, 50, 200 );
addChild( circle );
circles.push( circle );
}
}
var lastIteration:Number = new Date().getTime();
addEventListener( Event.ENTER_FRAME, function( e:Event ) : void {
Mouse.hide();
var thisIteration:Number = new Date().getTime();
var deltaTime:Number = ( thisIteration - lastIteration ) * 0.001;
lastIteration = thisIteration;
var max:int = circles.length;
for( var i:int = 0; i < max; i++ )
{
var circle:FleeingCircle = circles[i];
circle.update( deltaTime );
}
} );
}
}
}
import flash.display.Sprite;
import flash.geom.Point;
class FleeingCircle extends Sprite
{
private var home:Point;
private var mouse:Point;
private var location:Point;
private var direction:Point;
private var speed:Number;
public function FleeingCircle( x:Number, y:Number, radius:Number, speed:Number )
{
graphics.beginFill( 255, 233 );
graphics.drawCircle( 0, 0, radius );
this.x = x;
this.y = y;
home = new Point( this.x, this.y );
mouse = new Point();
location = new Point();
direction = new Point();
this.speed = speed;
}
public function update( deltaTime:Number ) : void
{
mouse.x = stage.mouseX;
mouse.y = stage.mouseY;
location.x = x;
location.y = y;
var displacement:Number;
if( Point.distance( mouse, location ) < 100 )
{
displacement = speed * deltaTime;
direction.x = location.x - mouse.x;
direction.y = location.y - mouse.y;
direction.normalize( 1 );
x += direction.x * displacement;
y += direction.y * displacement;
}
else if( Point.distance( home, location ) > 1 )
{
displacement = speed * deltaTime * 0.1;
direction.x = home.x - location.x;
direction.y = home.y - location.y;
direction.normalize( 1 );
x += direction.x * displacement;
y += direction.y * displacement;
}
}
}