Painter 1
♥0 |
Line 40 |
Modified 2013-05-10 14:11:30 |
MIT License
archived:2017-03-09 18:36:14
ActionScript3 source code
/**
* Copyright Saqoosha ( http://wonderfl.net/user/Saqoosha )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/qSd0
*/
package
{
import flash.display.Bitmap;
import flash.display.BitmapData;
import flash.display.Shape;
import flash.display.Sprite;
import flash.display.StageScaleMode;
import flash.events.MouseEvent;
/**
* @author Saqoosha
*/
[SWF(backgroundColor="#000000", frameRate="60", width="475", height="475")]
public class Painter1 extends Sprite
{
private var _canvasData:BitmapData = new BitmapData(475, 475, false, 0xffffff);
private var _canvas:Bitmap = new Bitmap(_canvasData);
private var _brush:Shape = new Shape();
public function Painter1() {
stage.scaleMode = StageScaleMode.NO_SCALE;
stage.addEventListener(MouseEvent.MOUSE_DOWN, _mouseDownHandler);
addChild(_canvas);
_brush.graphics.beginFill(0xff0000);
_brush.graphics.drawCircle(0, 0, 2);
_brush.graphics.endFill();
}
private function _mouseDownHandler(event:MouseEvent):void
{
stage.addEventListener(MouseEvent.MOUSE_MOVE, _mouseMoveHandler);
stage.addEventListener(MouseEvent.MOUSE_UP, _mouseUpHandler);
}
private function _mouseMoveHandler(event:MouseEvent):void
{
_brush.x = event.stageX;
_brush.y = event.stageY;
_canvasData.draw(_brush, _brush.transform.matrix);
}
private function _mouseUpHandler(event:MouseEvent):void
{
stage.removeEventListener(MouseEvent.MOUSE_MOVE, _mouseMoveHandler);
stage.removeEventListener(MouseEvent.MOUSE_UP, _mouseUpHandler);
}
}
}