painter
private function onMouseDown(event:MouseEvent):void
{
canvas.graphics.moveTo(mouseX, mouseY);
addEventListener(MouseEvent.MOUSE_MOVE, onMouseMove);
}
private function onMouseUp(event:MouseEvent):void
{
removeEventListener(MouseEvent.MOUSE_MOVE, onMouseMove);
}
private function onMouseMove(event:MouseEvent):void
{
canvas.graphics.lineTo(mouseX, mouseY);
//paint(event);
}
private function onMouseClick(event:MouseEvent):void{
color = Math.random() * 0xFFFFFF;
//txt.text = "Color: 0x" + color.toString();
}
public function paint(event:Event):void {
//counter++;
//txt.text = counter.toString();
//if (with_wii == 0) {
//vpX = mouseX;
//vpY = mouseY;
//}
//AE
//graphics.lineTo(mouseX, mouseY);
The code for the paint function was ported and adapted from:
"Splatter", by Stamen Design
stamen.com/projects/splatter
mid_x = ((end_x - start_x) * (1 + mid_point_push)) + start_x;
mid_y = ((end_y - start_y) * (1 + mid_point_push)) + start_y;
start_x = end_x;
start_y = end_y;
//end_x = vpX;// = mouseX;
//end_y = vpY;// = mouseY;
end_x = mouseX;
end_y = mouseY;
distance = Math.sqrt(Math.pow((end_x - start_x), 2) + Math.pow((end_y - start_y), 2));
new_size = max_line_width / distance;
size = aggression*new_size;//(new_size_influence * new_size) + ((1 - new_size_influence) * size);
splat(canvas.graphics, start_x, start_y, end_x, end_y, mid_x, mid_y, size);
parity = false;
/*
_parent.new_size_influence += ((Math.random() * 0.1) - 0.05);
_parent.mid_point_push += ((Math.random() * 0.1) - 0.05);
_parent.max_line_width += ((Math.random() * 4) - 2);
*/
new_size_influence += ((Math.random() * 0.1) - 0.05);
mid_point_push += ((Math.random() * 0.1) - 0.05);
max_line_width += ((Math.random() * 4) - 2);
}
private function splat(obj:Graphics, x1:Number, y1:Number, x2:Number, y2:Number, x3:Number, y3:Number, d:Number):void {
//var obj:Graphics = painting.graphics;
obj.lineStyle(d, color, 100);
//txt.text = d.toString();
obj.moveTo(x1, y1);
obj.curveTo(x3, y3, x2, y2);
//curves.push([x1, y1, x3, y3, x2, y2, d]);
// splotch
var dd:Number = Math.sqrt(Math.pow((x2 - x1), 2) + Math.pow((y2 - y1), 2));
for (var i:uint = 0; i<Math.floor(5*Math.pow(Math.random(), 4)); i++) {
// positioning of splotch varies between ±4dd, tending towards 0
var splat_range:Number = 1;
var x4:Number = dd * 1 * (Math.pow(Math.random(), splat_range) - (splat_range/2));
var y4:Number = dd * 1 * (Math.pow(Math.random(), splat_range) - (splat_range/2));
// direction of splotch varies between ±0.5
var x5:Number = Math.random() - 0.5;
var y5:Number = Math.random() - 0.5;
var d_:Number = d*(0.5+Math.random());
obj.lineStyle(d_, color, 100);
obj.moveTo((x1+x4), (y1+y4));
obj.lineTo((x1+x4+x5), (y1+y4+y5));
//curves.push([(x1+x4), (y1+y4), (x1+x4+x5), (y1+y4+y5), (x1+x4+x5), (y1+y4+y5), d_]);
}
//addChild(obj); //?AE
}