splatter(s)
private var togsplat:int = 0;
private function change_color(event:MouseEvent):void{
var h:Number = systemManager.stage.height;
var w:Number = systemManager.stage.width;
if (mouseY < h-50 && mouseY > 50 &&
mouseX < w-50 && mouseX > 50) {
//color = Math.random() * 0xFFFFFF;
//txt.text = "Color: 0x" + color.toString();
//if (togsplat == 1) {
toggle_painting();
//}
}
}
private function start_painting():void{
dopaint = 1;
addEventListener(Event.ENTER_FRAME, paint);
}
private function stop_painting():void{
dopaint = 0;
removeEventListener(Event.ENTER_FRAME, paint);
}
private function toggle_painting():void{
if (dopaint == 0) start_painting(); else stop_painting();
}
public function paint(event:Event):void {
//counter++;
//txt.text = counter.toString();
//if (with_wii == 0) {
//vpX = mouseX;
//vpY = mouseY;
//}
splat = Math.random() * 0xFFFFFF;
//AE
//graphics.lineTo(mouseX, mouseY);
The code for the paint function was ported and adapted from:
"Splatter", by Stamen Design
http://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);
splatter(painting.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 splatter(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, splat, 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_, splat, 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
}