rubberband
♥0 |
Line 62 |
Modified 2012-10-03 05:27:53 |
MIT License
archived:2017-03-20 07:26:42
ActionScript3 source code
/**
* Copyright russ ( http://wonderfl.net/user/russ )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/rA7g
*/
package
{
import flash.display.*;
import flash.events.MouseEvent;
import flash.utils.*;
import flash.text.*;
public class rubberband extends Sprite
{
private var _shapes:Vector.<Shape> = new Vector.<Shape>;
private var _MouseDown:Boolean;
private var _box:Shape = new Shape(); // the rubber band
private var _StartX:Number, _StartY:Number;
public function rubberband()
{
stage.align = StageAlign.TOP_LEFT;
stage.scaleMode = StageScaleMode.NO_SCALE;
_DrawShapes();
stage.addEventListener(MouseEvent.MOUSE_DOWN, onMouseDown);
stage.addEventListener(MouseEvent.MOUSE_MOVE, onMouseMove);
stage.addEventListener(MouseEvent.MOUSE_UP, onMouseUp);
this.addChild(_box);
_box.blendMode = BlendMode.NORMAL; //DIFFERENCE; // gets set color on white (or black) background
_box.x = _box.y = 0;
stage.color = 0;//0xFFFFFF;
}
private function onMouseDown(e:MouseEvent):void {
_MouseDown = true;
_box.graphics.clear();
_StartX = e.localX;
_StartY = e.localY;
}
private function onMouseMove(e:MouseEvent):void {
if (!_MouseDown) {
return;
}
with (_box.graphics) {
clear();
lineStyle(0, 0xFFFFFF); // for red line on given background (with 'DIFFERENCE' blendmode)
beginFill(0, 0.4);
drawRect(_StartX, _StartY, e.localX - _StartX, e.localY - _StartY);
}
}
private function onMouseUp(e:MouseEvent):void {
_MouseDown = false;
}
private function _DrawShapes():void {
var shape:Shape;
for(var i:uint = 0; i < 200; i++) {
shape = new Shape();
shape.graphics.clear();
shape.graphics.beginFill((Math.random() < 0.75) ? 0x000000 : Math.random() * 0xFFFFFF);
shape.graphics.drawRect(0, 0, Math.random() * 50, Math.random() * 50);
shape.graphics.endFill();
shape.x = Math.random() * 300;
shape.y = Math.random() * 300;
shape.rotation = Math.random() * 90;
_shapes.push(shape);
this.addChild(shape);
}
}
}
}