Image to Ascii
Author |
Message |
Saad
![](http://compsci.ca/v3/uploads/user_avatars/182387547249e7ebb91fb8a.png)
|
Posted: Sat Mar 01, 2008 12:34 am Post subject: Image to Ascii |
|
|
This program allows you to read in a picture and convert it into ASCII Art. Gradient.txt is sorted by from character for darkest shade to lightest shade.
The pixel width is inversely proportional to the size of output, meaning the greater pixel size the smaller the output
Saad
Description: |
|
![](http://compsci.ca/v3/pafiledb/images/icons/clip.gif) Download |
Filename: |
ImageToAscii.zip |
Filesize: |
287.56 KB |
Downloaded: |
221 Time(s) |
|
|
|
|
|
![](images/spacer.gif) |
Sponsor Sponsor
![Sponsor Sponsor](templates/subSilver/images/ranks/stars_rank5.gif)
|
|
![](images/spacer.gif) |
LaZ3R
|
Posted: Sat Mar 01, 2008 12:59 am Post subject: RE:Image to Ascii |
|
|
Very sweet
Code please?
|
|
|
|
|
![](images/spacer.gif) |
Saad
![](http://compsci.ca/v3/uploads/user_avatars/182387547249e7ebb91fb8a.png)
|
Posted: Sat Mar 01, 2008 1:19 am Post subject: Re: Image to Ascii |
|
|
Strange I thought I added the code, but anyway here it is.
Turing: |
var file : int
open : file, "GRADIENT.txt", get
var str : string
get : file, str : *
close : file
var WIDTH : int
var N := length (str ) - 1
var GRADIENT : array 0 .. N of char
for i : 0 .. N
GRADIENT (i ) := str (i + 1)
end for
var inFileName, outFileName : string
put "Enter Picture to be converted (with extension)"
get inFileName
put "Enter Output File Name (will be saved as .txt)"
get outFileName
put "Enter Pixel Width to use, where width > 0 (1 is really good, however picture will be bigger)"
get WIDTH
outFileName + = ".txt"
var picture := Pic.FileNew (inFileName )
View.Set ("graphics:" + intstr (Pic.Width (picture )) + "," + intstr (Pic.Height (picture ) + 20))
Pic.Draw (picture, 0, 0, picMerge)
put "Working"
open : file, outFileName, put
%% The actual conversion
for decreasing y : Pic.Height (picture ) div WIDTH - 1 .. 0
for x : 0 .. Pic.Width (picture ) div WIDTH - 1
var colorSum := 0. 0
for yInc : 0 .. WIDTH - 1 %% Get average color for pixels in block
for xInc : 0 .. WIDTH - 1
var r, g, b : real
RGB.GetColor (whatdotcolor (x * WIDTH + xInc, y * WIDTH + yInc ), r, g, b )
var c := r * 0. 3 + g * 0. 59 + b * . 11 %% Convert to grayscale
colorSum + = c
end for
end for
colorSum / = WIDTH ** 2
put : file, GRADIENT (round (colorSum * N )) .. %% Base the character relative to the gradient
end for
put : file, ""
end for
put "done"
close : file
|
|
|
|
|
|
![](images/spacer.gif) |
Silinter
|
Posted: Sun Mar 02, 2008 4:42 pm Post subject: Re: Image to Ascii |
|
|
Did anyone pick up the error at
Turing: | var inFileName, outFileName : string
put "Enter Picture to be converted (with extension)"
get inFileName
put "Enter Output File Name (will be saved as .txt)"
get outFileName |
inFileName and outFileName should have an " : * " after it since the name might have a space in it
Other then that, great job! The converted pictures look really nice!
|
|
|
|
|
![](images/spacer.gif) |
fishtastic
![](http://compsci.ca/v3/uploads/user_avatars/2112433479479e80d9034af.png)
|
Posted: Sun Mar 02, 2008 9:36 pm Post subject: RE:Image to Ascii |
|
|
cool and fun program.
remind me of Ascii Art Converter that took me a while to download.
var c := r * 0.3 + g * 0.59 + b * .11
this line is interesting.
it seems like green darker than red and red is darker than blue.
|
|
|
|
|
![](images/spacer.gif) |
Saad
![](http://compsci.ca/v3/uploads/user_avatars/182387547249e7ebb91fb8a.png)
|
Posted: Sun Mar 02, 2008 9:42 pm Post subject: Re: Image to Ascii |
|
|
@ Silenter, Thanks I forgot about the spaces
@ Fishtastic, That line is to convert an image to Grayscale. Taken straight from wikipedia
Quote: To convert any color to its most approximate level of gray, first one must obtain the values of its red, green and blue (RGB) primaries.
Then, add 30% of the red value, 59% of the green value, and 11% of the blue value, together. Regardless of the scale employed (0.0 to 1.0, 0 to 255, 0% to 100%, etc.), the resultant number is the desired gray value. These percentages are chosen due to the different relative sensitivity of the normal human eye to each of the primary colors (less sensitive to green, more to blue).
|
|
|
|
|
![](images/spacer.gif) |
|
|