forked from: OilPainting
/**
* Copyright tepe ( http://wonderfl.net/user/tepe )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/f9cr
*/
// forked from k3lab's OilPainting
package {
import flash.display.Sprite;
import flash.events.MouseEvent;
import flash.display.CapsStyle;
import flash.display.LineScaleMode;
public class FlashTest extends Sprite {
private var paint:oil_paint;
public function FlashTest() {
paint = new oil_paint();
addChild(paint);
}
}
}
//-------------------------------------
// oil_paint
//-------------------------------------
import flash.display.Sprite;
import flash.display.Shape;
import flash.events.MouseEvent;
import flash.display.CapsStyle;
import flash.display.LineScaleMode;
class oil_paint extends Sprite {
private var jackson:Shape;
public var s:Sprite;
private var prevX:int;
private var prevY:int;
private var startPosX:int;
private var startPosY:int;
private var disX:Number;
private var disY:Number;
private var color:uint;
public function oil_paint() {
jackson = new Shape();
addChild(jackson);
s = new Sprite();
s.graphics.lineStyle(2,0xff0000,0.5,true);
s.graphics.beginFill(0xffffff,0);
s.graphics.drawRoundRect(0,0,400,350,10);
s.graphics.endFill();
addChild(s);
s.addEventListener(MouseEvent.MOUSE_DOWN,_down);
s.addEventListener(MouseEvent.MOUSE_UP,_up);
}
public function clear():void {
jackson.graphics.clear();
}
private function _down(event:MouseEvent):void {
color = Math.random() * 0xFFFFFF;
prevX = event.localX;
prevY = event.localY;
startPosX = event.localX;
startPosY = event.localY;
s.addEventListener(MouseEvent.MOUSE_MOVE, _move);
}
private function _up(event:MouseEvent):void{
s.removeEventListener(MouseEvent.MOUSE_MOVE, _move);
}
private function _move(e:MouseEvent):void {
var distance:Number = Math.sqrt(Math.pow(prevX - startPosX, 2) + Math.pow(prevY - startPosY, 2))
var a:Number = distance * 10 * (Math.pow(Math.random(), 2) - 0.5)
var r:Number = Math.random() - 0.5
var size:Number = Math.random() * 15 / distance
disX = (prevX - startPosX) * Math.sin(0.5) + startPosX;
disY = (prevY - startPosY) * Math.cos(0.5) + startPosY;
startPosX = prevX;
startPosY = prevY;
prevX = mouseX
prevY = mouseY
jackson.graphics.moveTo(startPosX, startPosY);
jackson.graphics.curveTo(disX,disY,prevX,prevY)
jackson.graphics.lineStyle(((Math.random()+20/10-0.5)*size+(1-Math.random()+30/20-0.5)*size), color,1, false, LineScaleMode.NONE, CapsStyle.ROUND);
jackson.graphics.moveTo(startPosX + a, startPosY + a);
jackson.graphics.lineTo(startPosX+r+a, startPosY+r+a);
jackson.graphics.endFill();
}
}