forked from: SquareLines
// forked from ton's SquareLines
package {
import flash.display.*;
import flash.events.Event;
import flash.events.MouseEvent;
import flash.geom.Point;
import frocessing.color.ColorHSV;
public class SquareLines extends Sprite {
private var _bmd:BitmapData;
private var _prev:Point;
private var _rect:Shape;
private var _canvas:Sprite;
public function SquareLines():void {
_bmd = new BitmapData(465, 465);
addChild(new Bitmap(_bmd));
_canvas = new Sprite();
_rect = new Shape();
_canvas.addChild(_rect);
stage.addEventListener(MouseEvent.MOUSE_MOVE, update);
stage.addEventListener(Event.MOUSE_LEAVE, leave);
}
private function update(e:MouseEvent):void {
if(_prev == null) _prev = new Point(mouseX, mouseY);
var dx:Number = mouseX - _prev.x;
var dy:Number = mouseY - _prev.y;
var dis:Number = Math.sqrt(dx * dx + dy * dy);
var rad:Number = Math.atan2(dy, dx) * 180 / Math.PI;
_prev.x = mouseX;
_prev.y = mouseY;
var h:Number = 120 - (dis * 2);
var baseColor:ColorHSV = new ColorHSV(h);
var lineColor:ColorHSV = new ColorHSV(h, 1, 0.7);
_rect.graphics.clear();
_rect.graphics.beginFill(baseColor.value);
_rect.graphics.lineStyle(0, lineColor.value, 0.5);
_rect.graphics.drawRect( -dis, -dis/4, dis, dis/2);
_rect.rotation = rad;
_rect.x = mouseX;
_rect.y = mouseY;
_bmd.draw(_canvas);
}
private function leave(e:Event):void {
_prev = null;
}
}
}