How To: Apply a Painterly Effect to a Loaded Image.


So, painterly might be a stretch, I realize this… It’s kind of pointilistic, though, maybe, or something… Take a look. Feel free to use the ActionScript after the image…

Sophia Circles.

You can also download the FLA file here. You’ll need to also download Zeh Fernando’s Tweener. Take a look at the somewhat animated Flash file here.


import flash.display.Bitmap;
import caurina.transitions.*;
import flash.display.BitmapData;
import flash.display.Loader;
import flash.display.Sprite;
import flash.display.Shape;
import flash.events.*;
import flash.net.URLRequest;
 
var url:String = "yourImagehere.jpg";
var size:uint = 80;
 
function randRange(min:Number, max:Number):Number {
    var randomNum:Number = Math.floor(Math.random() * (max - min + 1)) + min;
    return randomNum;
}
 
function loadClip():void {
    var loader:Loader = new Loader();
    loader.contentLoaderInfo.addEventListener(Event.COMPLETE, completeHandler);
    loader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, ioErrorHandler);
    var request:URLRequest = new URLRequest(url);
    loader.load(request);
    addChild(loader);
}
 
function completeHandler(event:Event):void {
 var image:Bitmap = Bitmap(event.target.content);
 for(var i:Number=0;i<5000;i++) {
 	var currX:Number = randRange(0, event.target.width);
 	var currY:Number = randRange(0, event.target.height);
 	var currColor:uint = uint(image.bitmapData.getPixel(currX,currY));
 	var child:Shape = new Shape();
    	var halfSize:uint = Math.round(size / 2);
    	child.graphics.beginFill(currColor,0);
   	child.graphics.lineStyle(randRange(0,5), currColor, Math.random());
    	child.graphics.drawCircle(currX, currY, randRange(3,8));
    	child.graphics.endFill();
 	child.alpha = 0;
    	addChild(child);
 	Tweener.addTween(child, {alpha:Math.random(), time:randRange(1,2), delay:randRange(1,5)});
 }
}
 
function ioErrorHandler(event:IOErrorEvent):void {
            trace("Unable to load image: " + url);
}
 
loadClip();

Posted on


Leave a reply