User Tools

Site Tools


ascii_art

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revisionBoth sides next revision
ascii_art [2023/03/25 15:26] – [Step 3. Convert the RGB tuples of your pixels into single brightness numbers] frchrisascii_art [2023/03/25 15:31] – [Step 3. Convert the RGB tuples of your pixels into single brightness numbers] frchris
Line 208: Line 208:
   - Luminosity: Take the sqrt root of the weighted squares - ''sqrt( 0.299 R^2 + 0.587 G^2 + 0.114 B^2)''   - Luminosity: Take the sqrt root of the weighted squares - ''sqrt( 0.299 R^2 + 0.587 G^2 + 0.114 B^2)''
   - See [[https://stackoverflow.com/questions/596216/formula-to-determine-brightness-of-rgb-color|this stackoverflow thread]] for more detail   - See [[https://stackoverflow.com/questions/596216/formula-to-determine-brightness-of-rgb-color|this stackoverflow thread]] for more detail
 +<code Step3.java>
 +import java.awt.Color;
 +import java.awt.Font;
 +import java.awt.Graphics;
 +import javax.swing.JFrame;
 +import javax.swing.JPanel;
 +import java.awt.*;
 +/**
 +   This is Step3 of the ASCII Art Lab:
 +   Convert the 2D Color Array into a 
 +   2D int array of brightness
 +   
 +   You need a functional Step2 class 
 +   in this project folder for this to work.
 +   this 
 +   @author Chris Thiel, OFMCap
 +   @version 25 Mar 2023
 + */
 +public class Step3 extends JPanel 
 +{
  
 +    private String fileName;
 +    private Font titleFont, regularFont;
 +    private Color[][] clr; 
 +    private int[][] brightness;
 +   
 +    public Step3(String fileName)
 +    {
 +        this.fileName = fileName;
 +        this.clr = new Step2(fileName).getPx();
 +        titleFont = new Font("Roman", Font.BOLD, 32);
 +        regularFont = new Font("Helvetica", Font.PLAIN, 24);
 +        
 +        // Make a 2D int array that same number of rows and columns 
 +        //  as the Color array
 +        
 +
 +        
 +        
 +        //Fill the brightness array with yout choice of conversion method
 +        // (like Average, Lightness, Luminocity, or your own)
 +        
 +
 +
 +    }
 +    public int average(Color c)
 +    {
 +        // your code here
 +    }
 +    public int luminance(Color c)
 +    {
 +        // your code here
 +    }
 +    public int lightness(Color c)
 +    {
 +        //your code here
 +    }
 +    public int luminosity(Color c){
 +       // your code here
 +    }
 +    public int getWidth() {
 +        return brightness.length;// width is max x i.e, the max col
 +    }
 +
 +    public int getHeight() {
 +        return brightness[0].length; // height is the max y, i.ie max row
 +    }
 +
 +    public void paintComponent(Graphics g){
 +        super.paintComponent(g);
 +        g.setColor(Color.WHITE);
 +        g.fillRect(0, 0, getWidth(),getHeight());
 +        //g.drawImage(source, 0, 0, null);
 +        for (int y=0; y < getHeight(); y++)
 +            for(int x=0; x < getWidth(); x++)
 +            {
 +                int b = brightness[x][y];
 +                g.setColor( new Color(b,b,b) );
 +                g.fillRect( x, y, 1, 1);
 +            }
 +
 +        g.setColor(Color.BLACK);// Use WHITE if the image is dark
 +        g.setFont(titleFont);
 +        g.drawString(fileName, 20, 40);
 +        g.setFont(regularFont);
 +        g.drawString ( getWidth() + " by " + getHeight() + "- Drawn from 2DColor Array", 20, 70);
 +
 +    }
 +
 +    public static void main(String[] args) {
 +        Step3 pic= new Step3("StBernardSm.jpg"); // change this to the picture you picked
 +        JFrame window = new JFrame("Step 2 Tester");
 +        window.setSize(pic.getWidth(), pic.getHeight());
 +        window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
 +        window.getContentPane().add(pic);
 +        window.setVisible(true);
 +    }
 +
 +}
 +</code>
 ==== Step 4. Convert brightness numbers to ASCII characters  ==== ==== Step 4. Convert brightness numbers to ASCII characters  ====
 ==== Step 5. What if it looks your image looks squashed? ==== ==== Step 5. What if it looks your image looks squashed? ====
ascii_art.txt · Last modified: 2023/03/27 10:46 by frchris

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki