Work in progress
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
PrintWriter output; | |
//String scale = "@ M B H E N R # K W X D F P Q A S U Z b d e h x * 8 G m & 0 4 L O V Y k p q 5 T a g n s 6 9 o w z $ C I u 2 3 J c f r y % 1 v 7 l + i t [ ] { } ? j | ( ) = ~ ! - < > ^ _ ' ; , : ` ."; | |
String scale = "@ M B H E N R # K W X D F P Q A S U Z * 8 G & 0 4 L O V Y 5 T 6 9 $ C I 2 3 J % 1 7 + ? ( ) = ! - < > ' ; , : ."; | |
String[] scaleChars = split(scale, " "); | |
String mImageFileName = "sal.jpg"; | |
int mImageWidth = 529; | |
int mImageHeight = 532; | |
int mColumns = 65; | |
int mLines = 32; | |
String[] asciiLines = new String[mLines]; | |
PImage img; | |
int[][] imgPixels; | |
int mCellWidth; | |
int mCellHeight; | |
void setup() { | |
size(mImageWidth, mImageHeight); | |
output = createWriter("asciibbc.txt"); | |
rectMode(CENTER); | |
noFill(); | |
stroke(0); | |
img = loadImage(mImageFileName); | |
mCellWidth = mImageWidth/mColumns; | |
mCellHeight = mImageHeight/mLines; | |
println("mCellWidth: " + mCellWidth); | |
println("mCellHeight: " + mCellHeight); | |
imgPixels = new int[mImageWidth][mImageHeight]; | |
for (int i = 0; i < mImageHeight; i++) { | |
for (int j = 0; j < mImageWidth; j++) { | |
imgPixels[j][i] = img.get(j, i); | |
} | |
} | |
} | |
void draw() { | |
noLoop(); | |
background(0); | |
image(img, 0, 0); | |
output.println("1 MODE0"); | |
int line = 0; | |
String ascii = ""; | |
for (int i = 0; i < mImageHeight; i += mCellHeight) { | |
println("Line i: " + i); | |
for (int j = 0; j < mImageWidth; j += mCellWidth) { | |
println("Column j: " + j); | |
float rr = red(imgPixels[j][i]); | |
float gg = green(imgPixels[j][i]); | |
float bb = blue(imgPixels[j][i]); | |
float luminance = (0.299*rr + 0.587*gg + 0.114*bb); | |
fill(luminance); | |
int remappedLuminance = (int) map(luminance, 0, 255, 0, scaleChars.length); | |
println("LUMINANCE: " + luminance + " REMAPPED: " + remappedLuminance); | |
ascii = ascii + scaleChars[remappedLuminance]; | |
rect(j, i, mCellWidth, mCellHeight); | |
} | |
if(line > mLines -1){ | |
line = mLines - 1; | |
} | |
asciiLines[line] = ascii; | |
ascii = ""; | |
line++; | |
} | |
for(int i = 0 ; i < mLines ; i++){ | |
println(asciiLines[i]); | |
output.println("" + ((i+1) * 10) + " PRINT\"" + asciiLines[i] + "\""); | |
} | |
output.flush(); // Writes the remaining data to the file | |
output.close(); // Finishes the file | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment