Create fun Ascii Art with this easy to use class…
Download source code: Actionscript ASCII Art Class
Invoke the class like so:
var bitMapData:BMap2 = new BMap2(0,0); // THIS WOULD BE YOUR IMAGE DATA
var art:AsciiArt = new AsciiArt(bitMapData, 4,"#", "*", "."); //after bitMapData are optional fields
// detail:int(pixel sample rate)
// dark:String(dark pixel character),
// medium:String(medium pixel character),
// light :String(light pixel character)
addChild(art);
Here is the class script:
package
{
import flash.display.*;
import flash.text.*;
public class AsciiArt extends Sprite
{
private var detail:int = 5; // This is your pixel sample rate (smaller number means more pixels sampled)
private var imgData:BitmapData;
private var xPos:int = 0;
private var yPos:int = 0;
private var lightPixel:String; // The Character that comes up for light areas
private var mediumPixel:String; // Same for Medium
private var darkPixel:String; // I think you get it by now
private var channel:int = 0; // Channel to sample 0 = Red 1 = Blue 2 = Green
public function AsciiArt(imageData:BitmapData, sampleRate:int = 5, dark:String = "%", medium:String = "*", light:String = ".")
{
detail = sampleRate;
darkPixel = dark;
mediumPixel = medium;
lightPixel = light;
imgData = imageData;
makeArt();
}
private function makeArt()
{
for(var i:int=0; i<imgData.width/detail;i++){
var color:uint= imgData.getPixel(xPos,yPos);
var t:TextField = new TextField();
addChild(t);
var colors:Array = HexToRGB(color);
if(colors[channel]>200){
// LIGHT COLOR
t.x = xPos;
t.y = yPos;
t.text = lightPixel;
}else if(colors[channel]<199 && colors[channel]>60){
// DARK COLOR
t.x = xPos;
t.y = yPos;
t.text = mediumPixel;
}else{
// DARK COLOR
t.x = xPos;
t.y = yPos;
t.text = darkPixel;
}
xPos += detail; // Add detail width to sample position
}
if(yPos<imgData.height){ // if yPos is less than the height of the image, start over again
xPos = 0;
yPos +=detail;
makeArt();
}
}
private function HexToRGB(hex:uint):Array // function lifted from http://blog.mindfock.com/rgb-to-hexadecimal-to-hsv-conversion-in-as3/
{
var rgb:Array = [];
var r:uint = hex >> 16 & 0xFF;
var g:uint = hex >> 8 & 0xFF;
var b:uint = hex & 0xFF;
rgb.push(r, g, b);
return rgb;
}
}
}
and here is a screen cap of the output:



Stumble it!

also easy is the tool Ascgen dotNET. Try it