More fun with sampleImage(): Ascii animation in After Effects

More experimentation with sampleImage(). This one relies on this expression.


target = thisComp.layer("layerToSample.mov");
samples = new Array();

var spacing = 10;
var w = target.width / spacing ;
var layerOrder = 1;
var h = 10 * layerOrder;

letters = "   .,:!-+=;iot76x0s&8%#@$";

for(x= 0; x < w; x++){
	samples[x] = target.sampleImage([x* spacing ,h],[spacing , spacing], false, time);
}

var string = '';

for(z = 0; z < samples.length; z++){
	var y = Math.round((0.299 * samples[z][0] + 0.587 * samples[z][1] + 0.114* samples[z][2]) * 100)/ 4;
	string = string + letters.substring(y,y + 1);

}

We loop through the row of pixels and place the sampled RGB pixels in the samples array, convert the RGB samples to YUV and grab the Y or brightness value for comparison against a rough gradient of ASCII values. For best results, use a monospace font to retain proper spacing. A more complete script/expression and breakdown to come.

4 Comments »

  1. Jeff Almasol said,

    August 27, 2007 at 6:29 pm

    hey dale… it’s cool you’re pursuing this effect. i’ve wanted to recreate the rd_Characterize script i wrote a few years back for UT (http://www.redefinery.com/ut/view.php?item=rd_Characterize) as an AE script/expression, but you’re further along than i am. i’m glad the AE community is digging sampleImage().

  2. Dale said,

    August 27, 2007 at 6:45 pm

    Hey Jeff,

    Thanks for the link. I don’t know, in a lot of ways,rd_Characterize is cooler then what I’ve got started here. I love the way the image is holding together. It definitely gives me some inspiration of possible directions to take. sampleimage() is definitely way cool.

    Dale

  3. Alexandre Teles said,

    August 31, 2007 at 5:52 pm

    very cool
    i´ll start making some tests with that

    AT

  4. Jonas Hummelstrand said,

    September 9, 2007 at 4:31 pm

    Dale,

    Great stuff as always! I’ve been playing with using sampleImage() to create a flicker stabilizer by driving the Levels (Individual) effect, but being a very modest scripter I can’t say I’ve had much success yet.

RSS feed for comments on this post · TrackBack URL

Leave a Comment