flash on 2016-3-3
/**
* Copyright mutantleg ( http://wonderfl.net/user/mutantleg )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/s0so
*/
package {
import flash.events.MouseEvent;
import flash.events.Event;
import flash.display.Sprite;
public class FlashTest extends Sprite {
public function FlashTest() {
stage.addEventListener(MouseEvent.CLICK, onClick);
stage.addEventListener(Event.ENTER_FRAME, onEnter);
}//ctor
public function onClick(e:MouseEvent):void
{
xrad=Math.random()*32+16; yrad=Math.random()*32+16;
axrad=Math.random()*64+16; ayrad=Math.random()*64+16;
}//onclick
public var cx:Number = 0;
public var cy:Number = 0;
public var xrad:Number = 32;
public var yrad:Number = 32;
public var axrad:Number = 64;
public var ayrad:Number = 64;
public function onEnter(e:Event):void
{
var ix:Number; var iy:Number;
var r:Number; var ms:Number;
var ax:Number; var ay:Number;
var mx:Number; var my:Number;
var vx:Number; var vy:Number;
graphics.clear();
graphics.lineStyle(2,0);
mx = stage.mouseX; my = stage.mouseY;
vx = mx-cx; vy =my-cy;
ms = 8;
if (vx>ms){vx=ms;}else if(vx<-ms){vx=-ms;}
if (vy>ms){vy=ms;}else if(vy<-ms){vy=-ms;}
cx +=vx; cy+=vy;
ax= 230; ay =230;
graphics.drawRect(ax-axrad,ay-ayrad,axrad*2,ayrad*2);
r = 16;
axrad-=r; ayrad-=r;
if (cx+xrad < ax-axrad) { ix = ax-axrad; }
else if (cx -xrad > ax+axrad) { ix = ax+axrad;}
else { if (cx<ax-axrad) { ix = ax-axrad;}
else if (cx > ax+axrad) { ix =ax+axrad;}
else {ix = cx; } }
if (cy+yrad < ay-ayrad) { iy = ay-ayrad; }
else if (cy -yrad > ay+ayrad) { iy = ay+ayrad;}
else { if (cy<ay-ayrad) { iy = ay-ayrad;}
else if (cy > ay+ayrad) { iy =ay+ayrad;}
else {iy = cy; } }
//graphics.drawCircle(ix, ay, 4);
//graphics.drawCircle(ax, iy, 4);
graphics.drawCircle(ix, iy, 4);
axrad+=r; ayrad+=r;
ax= ix; ay =iy;
//ax = 230; ay = 230;
graphics.drawCircle(ax,ay, r);
if (ax < cx-xrad) { ix = cx-xrad;}
else if (ax > cx+xrad) { ix = cx+xrad; }
else { ix = ax; }
if (ay < cy-yrad) { iy = cy-yrad;}
else if (ay > cy+yrad) { iy = cy+yrad; }
else { iy = ay; }
graphics.drawCircle(ix,iy,4);
var nx:Number; var ny:Number; var mag:Number;
nx = ix-ax; ny = iy-ay;
mag = Math.sqrt(nx*nx+ny*ny);
if (mag <= r)
{
if (mag == 0) { mag = 0.0001; }
nx/=mag; ny/=mag;
cx += nx * (r-mag);
cy += ny * (r-mag);
}//endif
graphics.drawRect(cx-xrad,cy-yrad,xrad*2,yrad*2);
graphics.moveTo(mx,my); graphics.lineTo(cx,cy);
}//onenter
}//classend
}