ascii_art
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revisionNext revisionBoth sides next revision | ||
ascii_art [2023/03/26 09:53] – [Step 5. What if it looks your image looks stretched or squashed?] frchris | ascii_art [2023/03/26 11:39] – [Step 5. What if it looks your image looks stretched or too big] frchris | ||
---|---|---|---|
Line 38: | Line 38: | ||
==== Step 0. Choose an image ==== | ==== Step 0. Choose an image ==== | ||
- | Choose the first image that you want to convert into ASCII art. It’s good to start with an image around 640x480. | + | Choose the first image that you want to convert into ASCII art. It’s good to start with an image around 640x480 |
+ | |||
+ | Light pixels will be represented by small characters like a dot (.), which leave lots of the background exposed. On the other extreme, dense characters like $ are used to cover up the background. | ||
<code PickPicture.java> | <code PickPicture.java> | ||
import java.awt.Color; | import java.awt.Color; | ||
Line 320: | Line 323: | ||
</ | </ | ||
==== Step 4. Convert brightness numbers to ASCII characters | ==== Step 4. Convert brightness numbers to ASCII characters | ||
- | You can experiment with different ways to map brightnesses to characters, but a good place to start is the string in the starter code. The characters in it are ordered from thinnest to boldest, which means lightest to darkest. | + | You can experiment with different ways to map brightnesses to characters, but a good place to start is the string in the starter code. The characters in it are ordered from thinnest to boldest, which means lightest to darkest. |
+ | <code Step4.java> | ||
+ | import java.awt.Color; | ||
+ | import java.awt.Font; | ||
+ | import java.awt.Graphics; | ||
+ | import javax.swing.JFrame; | ||
+ | import javax.swing.JPanel; | ||
+ | import java.awt.*; | ||
+ | import java.nio.file.Files; | ||
+ | import java.io.IOException; | ||
+ | import java.nio.file.Paths; | ||
+ | /** | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | */ | ||
+ | public class Step4 | ||
+ | { | ||
+ | |||
+ | private String fileName; | ||
+ | private Font titleFont, regularFont; | ||
+ | |||
+ | private int[][] brightness; | ||
+ | private char[][] ascii; | ||
+ | | ||
+ | |||
+ | public Step4(String fileName) | ||
+ | { | ||
+ | | ||
+ | this.fileName = fileName; | ||
+ | this.brightness = new Step3(fileName).getBrightness(); | ||
+ | titleFont = new Font(" | ||
+ | regularFont = new Font(" | ||
+ | //Make a 2D int array that matched the dimentions of the Brightness array | ||
+ | | ||
+ | ascii = new char[brightness.length][brightness[0].length]; | ||
+ | | ||
+ | //Fill the asciii array with your choice of conversion method | ||
+ | | ||
+ | // your code here | ||
+ | |||
+ | } | ||
+ | /** | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | */ | ||
+ | public char asciiChar( int lightValue) | ||
+ | { | ||
+ | String chars = ""; | ||
+ | int max = chars.length(); | ||
+ | // your code here | ||
+ | } | ||
+ | public int getWidth() { | ||
+ | return brightness.length;// | ||
+ | } | ||
+ | |||
+ | public int getHeight() { | ||
+ | return brightness[0].length; | ||
+ | } | ||
+ | /** | ||
+ | * The ascii array is constructed with a newline " | ||
+ | */ | ||
+ | public String toString(){ | ||
+ | // your code here | ||
+ | } | ||
+ | public void writeToFile() | ||
+ | { | ||
+ | String name = fileName.substring(0, | ||
+ | try { | ||
+ | | ||
+ | } catch (IOException e){ | ||
+ | | ||
+ | } | ||
+ | } | ||
+ | public static void main(String[] args) { | ||
+ | System.out.println(" | ||
+ | Step4 pic= new Step4(" | ||
+ | System.out.println(pic); | ||
+ | pic.writeToFile(); | ||
+ | } | ||
+ | |||
+ | } | ||
+ | </ | ||
==== Step 5. What if it looks your image looks stretched or too big ==== | ==== Step 5. What if it looks your image looks stretched or too big ==== | ||
Line 328: | Line 422: | ||
Characters tend to be three times taller than wide, so you could replace each character with three. If that is too large, you could make one character represent the average of three columns. | Characters tend to be three times taller than wide, so you could replace each character with three. If that is too large, you could make one character represent the average of three columns. | ||
+ | ==== Here are some examples ==== | ||
+ | {{ ::fry.txt |}} | ||
+ | |||
+ | |||
+ | ==== See more from Robert Heaton Here ==== | ||
[[https:// | [[https:// |
ascii_art.txt · Last modified: 2023/03/27 10:46 by frchris