Adobe FLEX 2-PROGRAMMING ACTIONSCRIPT 3.0 Manual page 226

Programming actionscript 3.0
Table of Contents

Advertisement

This code first defines a String instance named
that will be used to build up the
result
ASCII art version of the bitmap image. Next, it loops through individual pixels of the source
bitmap image. Using several color-manipulation techniques (omitted here for brevity), it
converts the red, green, and blue color values of an individual pixel to a single grayscale value
(a number from 0 to 255). The code then divides that value by 4 (as shown) to convert it to a
value in the 0-63 scale, which is stored in the variable
. (The 0-63 scale is used because
index
the "palette" of available ASCII characters used by this application contains 64 values.) The
palette of characters is defined as a String instance in the BitmapToAsciiConverter class:
// The characters are in order from darkest to lightest, so that their
// position (index) in the string corresponds to a relative color value
// (0 = black).
private static const palette:String =
"@#$%&8BMW*mwqpdbkhaoQ0OZXYUJCLtfjzxnuvcr[]{}1()|/?Il!i><+_~-;,. ";
Since the
variable defines which ASCII character in the palette corresponds to the
index
current pixel in the bitmap image, that character is retrieved from the
String using
palette
the
method. It is then appended to the
String instance using the
charAt()
result
concatenation assignment operator (
). In addition, at the end of each row of pixels, a
+=
newline character is concatenated to the end of the
String, forcing the line to wrap to
result
create a new row of character "pixels."
226
Working with Strings

Advertisement

Table of Contents
loading

This manual is also suitable for:

Flex

Table of Contents