diff --git a/src/TheArtist.java b/src/TheArtist.java index 69c8fd2..7570f73 100644 --- a/src/TheArtist.java +++ b/src/TheArtist.java @@ -14,16 +14,25 @@ import java.io.IOException; import javax.imageio.ImageIO; import src.depends.StdDraw; +/** + * The class creates and draws the image according to golden ratio. + */ public class TheArtist { - private double px, py, r, degree; - private double spacing = 15; - private int width, height; - private double goldenRatio = (Math.sqrt(5.0) + 1) / 2; + private double px, py;// pixel cordinate + private double r, degree; + private double spacing = 15; // spacing between the drawn points + private int width, height; // height and Widht of the image + private double goldenRatio = (Math.sqrt(5.0) + 1) / 2; // The Golden Ratio int iter = 0; - boolean smallChaos = false; BufferedImage img = null; + /** + * The constructor initializes with a image object to operate on. It also gives + * the height and widht of the mage. + * + * @param f A image file object + */ TheArtist(File f) { try { img = ImageIO.read(f); @@ -34,11 +43,22 @@ public class TheArtist { } } + /** + * Calculates the position of the next point to be drawn using cos and sin + * functions. + * + * @param x The x coordinate of the current pixel of the image + * @param y The y coordinate of the current pixel of the image + * @param grade The angle by which the point should be positioned + */ private void calculatePointPosition(double x, double y, double grade) { px = x + Math.cos(Math.toRadians(grade)) * (r / 2); py = y + Math.sin(Math.toRadians(grade)) * (r / 2); } + /** + * The Actual Drawing Routing. Uses StdDraw. + */ public void goldenDraw() { StdDraw.clear(StdDraw.WHITE); StdDraw.setXscale(-10, width + 10); @@ -53,16 +73,16 @@ public class TheArtist { break; } int p = img.getRGB((int) px, (int) py); - // int a = (p >> 24) & 0xff; - int r = (p >> 16) & 0xff; - int g = (p >> 8) & 0xff; - int b = p & 0xff; - int avg = (r + g + b) / 3; - float luminance = (r * 0.2126f + g * 0.7152f + b * 0.0722f) / 255; + // int a = (p >> 24) & 0xff; // alpha + int r = (p >> 16) & 0xff; // red + int g = (p >> 8) & 0xff; // green + int b = p & 0xff; // blue + int avg = (r + g + b) / 3; // because i like the gray scaled ones 😊 + float luminance = (r * 0.2126f + g * 0.7152f + b * 0.0722f) / 255; // brightness - StdDraw.setPenColor(avg, avg, avg); - StdDraw.setPenRadius((1 - luminance) / 70); - StdDraw.point(px, -1 * py); + StdDraw.setPenColor(avg, avg, avg); // set all gray 🤗 + StdDraw.setPenRadius((1 - luminance) / 70); /** set the point size */ + StdDraw.point(px, -1 * py); // draw the point StdDraw.show(); } } diff --git a/src/TheCanvas.java b/src/TheCanvas.java index 1af4cb1..06cf48e 100644 --- a/src/TheCanvas.java +++ b/src/TheCanvas.java @@ -13,24 +13,26 @@ import javax.swing.JFileChooser; import javax.swing.filechooser.FileNameExtensionFilter; /** - * TheCanvas - * - * + * This Class conatains the file chooser and main function. */ public class TheCanvas { public static void main(String[] args) { - - File f = openFile(); - TheArtist art = new TheArtist(f); - art.goldenDraw(); - + File f = openFile(); + TheArtist art = new TheArtist(f); + art.goldenDraw(); + } + /** + * Chooses Image File + * + * @return File object of the chosen File + */ public static File openFile() { JFileChooser open = new JFileChooser(); - FileNameExtensionFilter filter = new FileNameExtensionFilter("Image Files", "jpg", "jpeg"); + FileNameExtensionFilter filter = new FileNameExtensionFilter("Image Files", "jpg", "jpeg", "png"); open.setFileFilter(filter); int status = open.showOpenDialog(null); if (status == JFileChooser.APPROVE_OPTION) {