topical media & game development
hush-paint.mx
hush-paint.mx
[swf]
[flash]
flex
<?xml version="1.0" encoding="utf-8"?>
<mx:Application
xmlns:mx="http://www.adobe.com/2006/mxml"
paddingLeft="0" paddingTop="0" paddingBottom="0" paddingRight="0"
width="100%" height="100%"
horizontalAlign="center" verticalAlign="middle"
creationComplete="init()"
>
<mx:Script>
<![CDATA[
import flash.events.MouseEvent;
import flash.display.Sprite;
[Bindable] public var config:String = "@mx-hush-paint.xml";
private var xml:XML;
private var urlLoader:URLLoader = new URLLoader();
[Bindable] public var hello:String = "hello (default) world";
[Bindable] public var message:String = "(default) world";
[Bindable] public var button:String = "(default) click me!";
[Bindable] public var source:String = "../assets/clips/tube/balloon.flv";
[Bindable] public var volume:Number = 0.75;
//private var splat:uint = 0xFF0000;
//private var aggression:Number = 8.4; // 12.4;//3.4;
//private var painting:Sprite;
//private var dopaint:int = 0;
private function init():void {
if (Application.application.parameters.config) {
config = Application.application.parameters.config;
}
urlLoader.addEventListener(Event.COMPLETE,loaded);
urlLoader.load(new URLRequest(config));
}
private function loaded(e:Event):void{
xml = new XML(e.target.data);
button = xml..button.@text;
message = xml..button.@panel;
hello = xml..button;
if (xml..video.@source) { video.source = xml..video.@source; }
if (xml..video.@volume) { video.volume = xml..video.@volume; }
//if (xml..video.@width) { video.width = xml..video.@width; }
//if (xml..video.@height) { video.height = video.height * xml..video.@height; }
//video.volume = xml..video.@volume;
//source = xml..video.@source;
//note.text = video.source + " " + video.volume + " " + video.height;
//video.source = source;
video.play();
painting = new Sprite();
painting.blendMode = BlendMode.NORMAL;
video.addChild(painting);
//trace(xml);
}
private function handler ( event:MouseEvent ):void
{
//field.text = hello;
}
paint(s)
private var new_size_influence:Number = 0.5;
private var mid_point_push:Number = .75;
private var max_line_width:Number = (Math.random() * 10) + 10;
//private var info.visible:Boolean = false;
private var curves:Array;
private var start_x:Number;
private var start_y:Number;
private var mid_x:Number;
private var mid_y:Number;
private var end_x:Number;
private var end_y:Number;
private var distance:Number;
private var new_size:Number;
private var parity:Boolean;
private var size:Number = 0;
private var splat:uint = 0xFF0000;
private var aggression:Number = 8.4; // 12.4;//3.4;
private var painting:Sprite;
private var dopaint:int = 0;
private var on:uint = 0;
private function color() : void {
var red:Number = Math.random() * 255;
var green:Number = Math.random() * 255;
var blue:Number = Math.random() * 255;
if (on == 0) {
on = 1; video.transform.colorTransform = new ColorTransform(-1, -1, -1, 1, red, green, blue, 0);
} else {
on = 0; video.transform.colorTransform = new ColorTransform();
}
}
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
}
]]>
</mx:Script>
<!--
<mx:Panel
title="{message}" horizontalAlign="center"
paddingTop="10" paddingBottom="10" paddingLeft="10" paddingRight="10"
>
<mx:Label id="field" width="180" fontWeight="bold" fontSize="24"/>
<mx:Button label="{button}" click="handler(event);" />
</mx:Panel>
-->
<mx:VideoDisplay id="video" height="100%" width="100%" maintainAspectRatio="false" autoPlay="false"/>
<!--
<mx:Label id="note" width="400" fontWeight="bold" fontSize="24"/>
-->
</mx:Application>
(C) Æliens
04/09/2009
You may not copy or print any of this material without explicit permission of the author or the publisher.
In case of other copyright issues, contact the author.