code on 2009-1-10
// write as3 code here..
package {
import flash.display.Sprite;
import flash.events.MouseEvent;
public class Main extends Sprite{
private var cc:uint; //color
private var lastx:int;
private var lasty:int;
private var splatThreshhold:Number = 0.1;
private var sizeconst:int = 50;
public function Main(){
cc = randomColor();
lastx = stage.mouseX;
lasty = stage.mouseY;
stage.addEventListener(MouseEvent.MOUSE_MOVE, mmove);
stage.addEventListener(MouseEvent.CLICK, mclick);
mclick();
}
private function randomColor():uint{
return uint(Math.random()*0xffffff);
}
private function mmove(evt:MouseEvent):void{
setStyle();
graphics.moveTo(lastx, lasty);
graphics.lineTo(evt.stageX, evt.stageY);
lastx = evt.stageX;
lasty = evt.stageY;
if (Math.random() < splatThreshhold){
splat();
}
}
private function mclick(evt:MouseEvent = null):void{
cc = randomColor();
}
private function setStyle():void{
var sqdist:Number = (lastx - stage.mouseX)*(lastx - stage.mouseX) + (lasty - stage.mouseY)*(lasty - stage.mouseY);
graphics.lineStyle(sizeconst/Math.sqrt(sqdist), cc);
//graphics.lineStyle(0.1, cc);
}
private function splat():void{
graphics.beginFill(cc);
var xoff:int = int(Math.random()*30) - 15;
var yoff:int = int(Math.random()*30) - 15;
graphics.drawCircle(stage.mouseX + xoff, stage.mouseY + yoff, 3)
graphics.endFill();
}
}
}