From 42c06a8b5143e9676d137cc11acf62fb3bd30948 Mon Sep 17 00:00:00 2001 From: Sky Johnson Date: Tue, 2 Dec 2014 15:36:31 -0800 Subject: [PATCH 1/4] add code up to Act 7, rekt --- classes/IntArrayWorker.java | 260 ++++++------- classes/IntArrayWorkerTester.java | 202 +++++----- classes/Picture.java | 613 ++++++++++++++++++------------ classes/PictureExplorer.class | Bin 15347 -> 15258 bytes classes/PictureExplorer.java | 10 +- classes/PictureTester.java | 97 +++-- classes/package.bluej | 167 ++++---- 7 files changed, 736 insertions(+), 613 deletions(-) diff --git a/classes/IntArrayWorker.java b/classes/IntArrayWorker.java index 489e13e..32b6f5e 100755 --- a/classes/IntArrayWorker.java +++ b/classes/IntArrayWorker.java @@ -1,149 +1,137 @@ public class IntArrayWorker { - /** two dimensional matrix */ - private int[][] matrix = null; - - /** set the matrix to the passed one - * @param theMatrix the one to use - */ - public void setMatrix(int[][] theMatrix) - { - matrix = theMatrix; - } - - /** - * Method to return the total - * @return the total of the values in the array - */ - public int getTotal() - { - int total = 0; - for (int row = 0; row < matrix.length; row++) + /** two dimensional matrix */ + private int[][] matrix = null; + + /** set the matrix to the passed one + * @param theMatrix the one to use + */ + public void setMatrix(int[][] theMatrix) { - for (int col = 0; col < matrix[0].length; col++) - { - total = total + matrix[row][col]; - } + matrix = theMatrix; } - return total; - } - - /** - * Method to return the total using a nested for-each loop - * @return the total of the values in the array - */ - public int getTotalNested() - { - int total = 0; - for (int[] rowArray : matrix) + + public int getCount(int lookingfor){ + int timesfound = 0; + for(int row = 0; row < matrix.length; row++){ + for(int col = 0; col < matrix[row].length; col++){ + if(matrix[row][col]==(lookingfor)){ + timesfound++; + } + } + } + return timesfound; + } + + public int getLargest(){ + int largest = -1; + for(int[] row : matrix){ + for(int i : row){ + if(i>largest){ + largest = i; + } + } + } + return largest; + } + + public int getColTotal(int colLook){ + int total = 0; + for(int row = 0; row < matrix.length; row++){ + for(int col = 0; col < matrix[row].length; col++){ + if(col == colLook){ + total+=matrix[row][col]; + } + } + } + return total; + } + + /** + * Method to return the total + * @return the total of the values in the array + */ + public int getTotal() + { + int total = 0; + for (int row = 0; row < matrix.length; row++) + { + for (int col = 0; col < matrix[0].length; col++) + { + total = total + matrix[row][col]; + } + } + return total; + } + + /** + * Method to return the total using a nested for-each loop + * @return the total of the values in the array + */ + public int getTotalNested() { - for (int item : rowArray) - { - total = total + item; - } + int total = 0; + for (int[] rowArray : matrix) + { + for (int item : rowArray) + { + total = total + item; + } + } + return total; } - return total; - } - - /** - * Method to fill with an increasing count - */ - public void fillCount() - { - int numCols = matrix[0].length; - int count = 1; - for (int row = 0; row < matrix.length; row++) + + /** + * Method to fill with an increasing count + */ + public void fillCount() { - for (int col = 0; col < numCols; col++) - { - matrix[row][col] = count; - count++; - } + int numCols = matrix[0].length; + int count = 1; + for (int row = 0; row < matrix.length; row++) + { + for (int col = 0; col < numCols; col++) + { + matrix[row][col] = count; + count++; + } + } } - } - - /** - * print the values in the array in rows and columns - */ - public void print() - { - for (int row = 0; row < matrix.length; row++) + + /** + * print the values in the array in rows and columns + */ + public void print() { - for (int col = 0; col < matrix[0].length; col++) - { - System.out.print( matrix[row][col] + " " ); - } - System.out.println(); + for (int row = 0; row < matrix.length; row++) + { + for (int col = 0; col < matrix[0].length; col++) + { + System.out.print( matrix[row][col] + " " ); + } + System.out.println(); + } + System.out.println(); } - System.out.println(); - } - - - /** - * fill the array with a pattern - */ - public void fillPattern1() - { - for (int row = 0; row < matrix.length; row++) + + /** + * fill the array with a pattern + */ + public void fillPattern1() { - for (int col = 0; col < matrix[0].length; - col++) - { - if (row < col) - matrix[row][col] = 1; - else if (row == col) - matrix[row][col] = 2; - else - matrix[row][col] = 3; - } + for (int row = 0; row < matrix.length; row++) + { + for (int col = 0; col < matrix[0].length; + col++) + { + if (row < col) + matrix[row][col] = 1; + else if (row == col) + matrix[row][col] = 2; + else + matrix[row][col] = 3; + } + } } - } - - public int getCount(int number) - { - int count = 0; - for (int[] rowArray : matrix) - { - for (int i : rowArray) - { - if (i == number) - { - count++; - } - } - } - - return count; - } - - public int getLargest() - { - int largest = Integer.MIN_VALUE; - - for (int[] row : matrix) - { - for (int i : row) - { - if (i > largest) - { - largest = i; - } - } - } - - return largest; - } - - public int getColTotal(int col) - { - int total = 0; - - for (int[] row : matrix) - { - total += row[col]; - } - - return total; - } - + } \ No newline at end of file diff --git a/classes/IntArrayWorkerTester.java b/classes/IntArrayWorkerTester.java index b876cd9..11795ea 100755 --- a/classes/IntArrayWorkerTester.java +++ b/classes/IntArrayWorkerTester.java @@ -1,104 +1,104 @@ public class IntArrayWorkerTester { - /** method to test setMatrix */ - public static void testSetMatrix() - { - IntArrayWorker worker = new IntArrayWorker(); - int[][] nums = {{1, 1, 1} ,{2,2,2}}; - worker.setMatrix(nums); - System.out.println("This should have all 1's in first row and all 2's in second"); - worker.print(); - } - - /** Method to test fillPattern1 */ - public static void testFillPattern1() - { - IntArrayWorker worker = new IntArrayWorker(); - int[][] nums = new int[3][4]; - worker.setMatrix(nums); - worker.fillPattern1(); - System.out.println("fills with 2's on diagonal, 3's to left, and 1's to right"); - worker.print(); - } - - /** Method to test getCount*/ - public static void testGetCount() - { - IntArrayWorker worker = new IntArrayWorker(); - int[][] nums = new int[3][4]; - worker.setMatrix(nums); - worker.fillPattern1(); - int count = worker.getCount(1); - System.out.println("Count should be 6 and count is " + count); - } - - /** Method to test getTotal */ - public static void testGetTotal() - { - IntArrayWorker worker = new IntArrayWorker(); - int [][] nums2 = {{1, 2, 3}, {4, 5, 6}}; - worker.setMatrix(nums2); - int total = worker.getTotal(); - System.out.println("Total should be 21 and is " + total); - } - - /** Method to test getTotalNested */ - public static void testGetTotalNested() - { - IntArrayWorker worker = new IntArrayWorker(); - int [][] nums2 = {{1, 2, 3}, {4, 5, 6}}; - worker.setMatrix(nums2); - int total = worker.getTotalNested(); - System.out.println("Total should be 21 and is " + total); - } - - /** Method to test getLargest */ - public static void testGetLargest() - { // test when largest is last - IntArrayWorker worker = new IntArrayWorker(); - int [][] nums2 = {{1, 2, 3}, {4, 5, 6}}; - worker.setMatrix(nums2); - int largest = worker.getLargest(); - System.out.println("Largest should be 6 and is " + largest); - // test when largest is first - int[][] nums3 = {{6, 2, 3}, {4, 5, 1}}; - worker.setMatrix(nums3); - largest = worker.getLargest(); - System.out.println("Largest should be 6 and is " + largest); - // test when largest is in the middle - int[][] nums4 = {{1, 2, 3}, {6, 5, 1}}; - worker.setMatrix(nums4); - largest = worker.getLargest(); - System.out.println("Largest should be 6 and is " + largest); - // test when duplicate largest - int[][] nums5 = {{6, 2, 6}, {4, 5, 1}}; - worker.setMatrix(nums5); - largest = worker.getLargest(); - System.out.println("Largest should be 6 and is " + largest); - } - - /** Method to test getColTotal */ - public static void testGetColTotal() - { - IntArrayWorker worker = new IntArrayWorker(); - int [][] nums2 = {{1, 2, 3}, {4, 5, 6}}; - worker.setMatrix(nums2); - int total = worker.getColTotal(0); - System.out.println("Total for column 0 should be 5 and is " + total); - total = worker.getColTotal(1); - System.out.println("Total for column 1 should be 7 and is " + total); - total = worker.getColTotal(2); - System.out.println("Total for column 2 should be 9 and is " + total); - } - - public static void main(String[] args) - { - testSetMatrix(); - testFillPattern1(); - testGetCount(); - testGetTotal(); - testGetTotalNested(); - testGetLargest(); - testGetColTotal(); - } + /** method to test setMatrix */ + public static void testSetMatrix() + { + IntArrayWorker worker = new IntArrayWorker(); + int[][] nums = {{1, 1, 1} ,{2,2,2}}; + worker.setMatrix(nums); + System.out.println("This should have all 1's in first row and all 2's in second"); + worker.print(); + } + + /** Method to test fillPattern1 */ + public static void testFillPattern1() + { + IntArrayWorker worker = new IntArrayWorker(); + int[][] nums = new int[3][4]; + worker.setMatrix(nums); + worker.fillPattern1(); + System.out.println("fills with 2's on diagonal, 3's to left, and 1's to right"); + worker.print(); + } + + /** Method to test getCount*/ + public static void testGetCount() + { + IntArrayWorker worker = new IntArrayWorker(); + int[][] nums = new int[3][4]; + worker.setMatrix(nums); + worker.fillPattern1(); + int count = worker.getCount(1); + System.out.println("Count should be 6 and count is " + count); + } + + /** Method to test getTotal */ + public static void testGetTotal() + { + IntArrayWorker worker = new IntArrayWorker(); + int [][] nums2 = {{1, 2, 3}, {4, 5, 6}}; + worker.setMatrix(nums2); + int total = worker.getTotal(); + System.out.println("Total should be 21 and is " + total); + } + + /** Method to test getTotalNested */ + public static void testGetTotalNested() + { + IntArrayWorker worker = new IntArrayWorker(); + int [][] nums2 = {{1, 2, 3}, {4, 5, 6}}; + worker.setMatrix(nums2); + int total = worker.getTotalNested(); + System.out.println("Total should be 21 and is " + total); + } + + /** Method to test getLargest */ + public static void testGetLargest() + { // test when largest is last + IntArrayWorker worker = new IntArrayWorker(); + int [][] nums2 = {{1, 2, 3}, {4, 5, 6}}; + worker.setMatrix(nums2); + int largest = worker.getLargest(); + System.out.println("Largest should be 6 and is " + largest); + // test when largest is first + int[][] nums3 = {{6, 2, 3}, {4, 5, 1}}; + worker.setMatrix(nums3); + largest = worker.getLargest(); + System.out.println("Largest should be 6 and is " + largest); + // test when largest is in the middle + int[][] nums4 = {{1, 2, 3}, {6, 5, 1}}; + worker.setMatrix(nums4); + largest = worker.getLargest(); + System.out.println("Largest should be 6 and is " + largest); + // test when duplicate largest + int[][] nums5 = {{6, 2, 6}, {4, 5, 1}}; + worker.setMatrix(nums5); + largest = worker.getLargest(); + System.out.println("Largest should be 6 and is " + largest); + } + + /** Method to test getColTotal */ + public static void testGetColTotal() + { + IntArrayWorker worker = new IntArrayWorker(); + int [][] nums2 = {{1, 2, 3}, {4, 5, 6}}; + worker.setMatrix(nums2); + int total = worker.getColTotal(0); + System.out.println("Total for column 0 should be 5 and is " + total); + total = worker.getColTotal(1); + System.out.println("Total for column 1 should be 7 and is " + total); + total = worker.getColTotal(2); + System.out.println("Total for column 2 should be 9 and is " + total); + } + + public static void main(String[] args) + { + testSetMatrix(); + testFillPattern1(); + //testGetCount(); + testGetTotal(); + testGetTotalNested(); + //testGetLargest(); + //testGetColTotal(); + } } \ No newline at end of file diff --git a/classes/Picture.java b/classes/Picture.java index 92d845e..f189aea 100755 --- a/classes/Picture.java +++ b/classes/Picture.java @@ -15,269 +15,376 @@ */ public class Picture extends SimplePicture { - ///////////////////// constructors ////////////////////////////////// - - /** - * Constructor that takes no arguments - */ - public Picture () - { - /* not needed but use it to show students the implicit call to super() - * child constructors always call a parent constructor + ///////////////////// constructors ////////////////////////////////// + + /** + * Constructor that takes no arguments + */ + public Picture () + { + /* not needed but use it to show students the implicit call to super() + * child constructors always call a parent constructor + */ + super(); + } + + /** + * Constructor that takes a file name and creates the picture + * @param fileName the name of the file to create the picture from + */ + public Picture(String fileName) + { + // let the parent class handle this fileName + super(fileName); + } + + /** + * Constructor that takes the width and height + * @param height the height of the desired picture + * @param width the width of the desired picture + */ + public Picture(int height, int width) + { + // let the parent class handle this width and height + super(width,height); + } + + /** + * Constructor that takes a picture and creates a + * copy of that picture + * @param copyPicture the picture to copy + */ + public Picture(Picture copyPicture) + { + // let the parent class do the copy + super(copyPicture); + } + + /** + * Constructor that takes a buffered image + * @param image the buffered image to use */ - super(); - } - - /** - * Constructor that takes a file name and creates the picture - * @param fileName the name of the file to create the picture from - */ - public Picture(String fileName) - { - // let the parent class handle this fileName - super(fileName); - } - - /** - * Constructor that takes the width and height - * @param height the height of the desired picture - * @param width the width of the desired picture - */ - public Picture(int height, int width) - { - // let the parent class handle this width and height - super(width,height); - } - - /** - * Constructor that takes a picture and creates a - * copy of that picture - * @param copyPicture the picture to copy - */ - public Picture(Picture copyPicture) - { - // let the parent class do the copy - super(copyPicture); - } - - /** - * Constructor that takes a buffered image - * @param image the buffered image to use - */ - public Picture(BufferedImage image) - { - super(image); - } - - ////////////////////// methods /////////////////////////////////////// - - /** - * Method to return a string with information about this picture. - * @return a string with information about the picture such as fileName, - * height and width. - */ - public String toString() - { - String output = "Picture, filename " + getFileName() + - " height " + getHeight() - + " width " + getWidth(); - return output; - - } - - /** Method to set the blue to 0 */ - public void zeroBlue() - { - Pixel[][] pixels = this.getPixels2D(); - for (Pixel[] rowArray : pixels) + public Picture(BufferedImage image) + { + super(image); + } + + ////////////////////// methods /////////////////////////////////////// + + /** + * Method to return a string with information about this picture. + * @return a string with information about the picture such as fileName, + * height and width. + */ + public String toString() + { + String output = "Picture, filename " + getFileName() + + " height " + getHeight() + + " width " + getWidth(); + return output; + + } + + /** Method to set the blue to 0 */ + public void zeroBlue() + { + Pixel[][] pixels = this.getPixels2D(); + for (Pixel[] rowArray : pixels) + { + for (Pixel pixelObj : rowArray) + { + pixelObj.setBlue(0); + } + } + } + + public void keepOnlyBlue() + { + Pixel[][] pixels = this.getPixels2D(); + for (Pixel[] rowArray : pixels) + { + for (Pixel pixelObj : rowArray) + { + pixelObj.setGreen(0); + pixelObj.setRed(0); + } + } + } + + public void negate(){ + Pixel[][] pixels = this.getPixels2D(); + for (Pixel[] rowArray : pixels) + { + for (Pixel pixelObj : rowArray) + { + int red = 255 - pixelObj.getRed(); + int green = 255 -pixelObj.getGreen(); + int blue = 255-pixelObj.getBlue(); + pixelObj.setRed(red); + pixelObj.setGreen(green); + pixelObj.setBlue(blue); + } + } + } + + public void grayscale(){ + Pixel[][] pixels = this.getPixels2D(); + for (Pixel[] rowArray : pixels) + { + for (Pixel pixelObj : rowArray) + { + int value = (pixelObj.getBlue()+pixelObj.getGreen()+pixelObj.getRed())/3; + pixelObj.setGreen(value); + pixelObj.setBlue(value); + pixelObj.setRed(value); + } + } + } + + public void fixUnderwater(){ + Pixel[][] pixels = this.getPixels2D(); + for (Pixel[] rowArray : pixels) + { + for (Pixel pixelObj : rowArray) + { + int red = pixelObj.getRed(); + int blue = pixelObj.getBlue(); + int green = pixelObj.getGreen(); + int diffromblue = Math.abs(blue-(red+green)); + //if(blue>(Math.abs(green+red-blue))){ + pixelObj.setBlue(blue-diffromblue); + pixelObj.setGreen(green+diffromblue-(red)); + pixelObj.setRed(red+diffromblue); + //} + } + } + } + + /** Method that mirrors the picture around a + * vertical mirror in the center of the picture + * from left to right */ + public void mirrorVertical() + { + Pixel[][] pixels = this.getPixels2D(); + Pixel leftPixel = null; + Pixel rightPixel = null; + int width = pixels[0].length; + for (int row = 0; row < pixels.length; row++) + { + for (int col = 0; col < width / 2; col++) + { + leftPixel = pixels[row][col]; + rightPixel = pixels[row][width - 1 - col]; + rightPixel.setColor(leftPixel.getColor()); + } + } + } + + public void mirrorVerticalRightToLeft() + { + Pixel[][] pixels = this.getPixels2D(); + Pixel leftPixel = null; + Pixel rightPixel = null; + int width = pixels[0].length; + for (int row = 0; row < pixels.length; row++) + { + for (int col = 0; col < width / 2; col++) + { + leftPixel = pixels[row][col]; + rightPixel = pixels[row][width - 1 - col]; + leftPixel.setColor(rightPixel.getColor()); + } + } + } + + public void mirrorHorrizontal() + { + Pixel[][] pixels = this.getPixels2D(); + Pixel topPixel = null; + Pixel bottomPixel = null; + int height = pixels.length; + for (int row = 0; row < height / 2; row++) + { + for (int col = 0; col < pixels[0].length; col++) + { + topPixel = pixels[row][col]; + bottomPixel = pixels[height - 1 - row][col]; + bottomPixel.setColor(topPixel.getColor()); + } + } + } + + public void mirrorHorrizontalBotToTop() + { + Pixel[][] pixels = this.getPixels2D(); + Pixel topPixel = null; + Pixel bottomPixel = null; + int height = pixels.length; + for (int row = 0; row < height / 2; row++) + { + for (int col = 0; col < pixels[0].length; col++) + { + topPixel = pixels[row][col]; + bottomPixel = pixels[height - 1 - row][col]; + topPixel.setColor(bottomPixel.getColor()); + } + } + } + + public void mirrorDiagonal(){ + Pixel[][] pixels = this.getPixels2D(); + + Pixel one = null; + Pixel two = null; + + for (int row = 0; row < pixels.length; row++) + { + for (int col = 0; col < pixels[0].length; col++) + { + + try{ + one = pixels[row][col]; + two = pixels[col][row]; + one.setColor(two.getColor()); + }catch(Exception e){ + + } + } + } + } + + /** Mirror just part of a picture of a temple */ + public void mirrorTemple() { - for (Pixel pixelObj : rowArray) - { - pixelObj.setBlue(0); - } + int mirrorPoint = 276; + Pixel leftPixel = null; + Pixel rightPixel = null; + int count = 0; + Pixel[][] pixels = this.getPixels2D(); + + // loop through the rows + for (int row = 27; row < 97; row++) + { + // loop from 13 to just before the mirror point + for (int col = 13; col < mirrorPoint; col++) + { + count++; + leftPixel = pixels[row][col]; + rightPixel = pixels[row] + [mirrorPoint - col + mirrorPoint]; + rightPixel.setColor(leftPixel.getColor()); + } + } + System.out.println(count); } - } - - /** Method that mirrors the picture around a - * vertical mirror in the center of the picture - * from left to right */ - public void mirrorVertical() - { - Pixel[][] pixels = this.getPixels2D(); - Pixel leftPixel = null; - Pixel rightPixel = null; - int width = pixels[0].length; - for (int row = 0; row < pixels.length; row++) + + public void mirrorArms() { - for (int col = 0; col < width / 2; col++) - { - leftPixel = pixels[row][col]; - rightPixel = pixels[row][width - 1 - col]; - rightPixel.setColor(leftPixel.getColor()); - } + int top = 190; + int bot = 225; + int right = 96; + int left = 311; + + Pixel[][] pixels = this.getPixels2D(); + Pixel lookingatPixel = null; + Pixel copyingPixel = null; + int height = pixels.length; + for (int row = top; row < bot; row++) + { + for (int col = right; col < left; col++) + { + if(col < 171|| col > 233){ + lookingatPixel = pixels[row][col]; + copyingPixel = pixels[row - 2*(row-top)][col]; + lookingatPixel.setColor(copyingPixel.getColor()); + } + } + } } - } - - public void mirrorVerticalRightToLeft() - { - Pixel[][] pixels = this.getPixels2D(); - Pixel leftPixel = null; - Pixel rightPixel = null; - int width = pixels[0].length; - for (int row = 0; row < pixels.length; row++) + + /** copy from the passed fromPic to the + * specified startRow and startCol in the + * current picture + * @param fromPic the picture to copy from + * @param startRow the start row to copy to + * @param startCol the start col to copy to + */ + public void copy(Picture fromPic, + int startRow, int startCol) { - for (int col = 0; col < width / 2; col++) - { - leftPixel = pixels[row][col]; - rightPixel = pixels[row][width - 1 - col]; - leftPixel.setColor(rightPixel.getColor()); - } + Pixel fromPixel = null; + Pixel toPixel = null; + Pixel[][] toPixels = this.getPixels2D(); + Pixel[][] fromPixels = fromPic.getPixels2D(); + for (int fromRow = 0, toRow = startRow; + fromRow < fromPixels.length && + toRow < toPixels.length; + fromRow++, toRow++) + { + for (int fromCol = 0, toCol = startCol; + fromCol < fromPixels[0].length && + toCol < toPixels[0].length; + fromCol++, toCol++) + { + fromPixel = fromPixels[fromRow][fromCol]; + toPixel = toPixels[toRow][toCol]; + toPixel.setColor(fromPixel.getColor()); + } + } } - } - - public void mirrorHorizontal() - { - Pixel[][] pixels = this.getPixels2D(); - Pixel topPixel = null; - Pixel bottomPixel = null; - int height = pixels.length; - for (int row = 0; row < height; row++) - { - for (int col = 0; col < pixels[0].length; col++) - { - topPixel = pixels[row][col]; - bottomPixel = pixels[height - 1 - row][col]; - bottomPixel.setColor(topPixel.getColor()); - } - } - } - - public void mirrorHorizontalBottomToTop() - { - Pixel[][] pixels = this.getPixels2D(); - Pixel topPixel = null; - Pixel bottomPixel = null; - int height = pixels.length; - for (int row = 0; row < height; row++) - { - for (int col = 0; col < pixels[0].length; col++) - { - topPixel = pixels[row][col]; - bottomPixel = pixels[height - 1 - row][col]; - topPixel.setColor(bottomPixel.getColor()); - } - } - } - - /** Mirror just part of a picture of a temple */ - public void mirrorTemple() - { - int mirrorPoint = 276; - Pixel leftPixel = null; - Pixel rightPixel = null; - int count = 0; - Pixel[][] pixels = this.getPixels2D(); - - // loop through the rows - for (int row = 27; row < 97; row++) + + /** Method to create a collage of several pictures */ + public void createCollage() { - // loop from 13 to just before the mirror point - for (int col = 13; col < mirrorPoint; col++) - { - - leftPixel = pixels[row][col]; - rightPixel = pixels[row] - [mirrorPoint - col + mirrorPoint]; - rightPixel.setColor(leftPixel.getColor()); - } + Picture flower1 = new Picture("flower1.jpg"); + Picture flower2 = new Picture("flower2.jpg"); + this.copy(flower1,0,0); + this.copy(flower2,100,0); + this.copy(flower1,200,0); + Picture flowerNoBlue = new Picture(flower2); + flowerNoBlue.zeroBlue(); + this.copy(flowerNoBlue,300,0); + this.copy(flower1,400,0); + this.copy(flower2,500,0); + this.mirrorVertical(); + this.write("collage.jpg"); } - } - - /** copy from the passed fromPic to the - * specified startRow and startCol in the - * current picture - * @param fromPic the picture to copy from - * @param startRow the start row to copy to - * @param startCol the start col to copy to - */ - public void copy(Picture fromPic, - int startRow, int startCol) - { - Pixel fromPixel = null; - Pixel toPixel = null; - Pixel[][] toPixels = this.getPixels2D(); - Pixel[][] fromPixels = fromPic.getPixels2D(); - for (int fromRow = 0, toRow = startRow; - fromRow < fromPixels.length && - toRow < toPixels.length; - fromRow++, toRow++) + + /** Method to show large changes in color + * @param edgeDist the distance for finding edges + */ + public void edgeDetection(int edgeDist) { - for (int fromCol = 0, toCol = startCol; - fromCol < fromPixels[0].length && - toCol < toPixels[0].length; - fromCol++, toCol++) - { - fromPixel = fromPixels[fromRow][fromCol]; - toPixel = toPixels[toRow][toCol]; - toPixel.setColor(fromPixel.getColor()); - } - } - } - - /** Method to create a collage of several pictures */ - public void createCollage() - { - Picture flower1 = new Picture("flower1.jpg"); - Picture flower2 = new Picture("flower2.jpg"); - this.copy(flower1,0,0); - this.copy(flower2,100,0); - this.copy(flower1,200,0); - Picture flowerNoBlue = new Picture(flower2); - flowerNoBlue.zeroBlue(); - this.copy(flowerNoBlue,300,0); - this.copy(flower1,400,0); - this.copy(flower2,500,0); - this.mirrorVertical(); - this.write("collage.jpg"); - } - - - /** Method to show large changes in color - * @param edgeDist the distance for finding edges - */ - public void edgeDetection(int edgeDist) - { - Pixel leftPixel = null; - Pixel rightPixel = null; - Pixel[][] pixels = this.getPixels2D(); - Color rightColor = null; - for (int row = 0; row < pixels.length; row++) + Pixel leftPixel = null; + Pixel rightPixel = null; + Pixel[][] pixels = this.getPixels2D(); + Color rightColor = null; + for (int row = 0; row < pixels.length; row++) + { + for (int col = 0; + col < pixels[0].length-1; col++) + { + leftPixel = pixels[row][col]; + rightPixel = pixels[row][col+1]; + rightColor = rightPixel.getColor(); + if (leftPixel.colorDistance(rightColor) > + edgeDist) + leftPixel.setColor(Color.BLACK); + else + leftPixel.setColor(Color.WHITE); + } + } + } + + /* Main method for testing - each class in Java can have a main + * method + */ + public static void main(String[] args) { - for (int col = 0; - col < pixels[0].length-1; col++) - { - leftPixel = pixels[row][col]; - rightPixel = pixels[row][col+1]; - rightColor = rightPixel.getColor(); - if (leftPixel.colorDistance(rightColor) > - edgeDist) - leftPixel.setColor(Color.BLACK); - else - leftPixel.setColor(Color.WHITE); - } + Picture beach = new Picture("beach.jpg"); + beach.explore(); + beach.zeroBlue(); + beach.explore(); } - } - - - /* Main method for testing - each class in Java can have a main - * method - */ - public static void main(String[] args) - { - Picture beach = new Picture("beach.jpg"); - beach.explore(); - beach.zeroBlue(); - beach.explore(); - } - + } // this } is the end of class Picture, put all new methods before this diff --git a/classes/PictureExplorer.class b/classes/PictureExplorer.class index 86e91a8e4643ecef292c62810ad3bba50a7b6e79..a5a9154b6cadf37aa0b08d486cbfbcb9a4751b1e 100644 GIT binary patch delta 6019 zcma)931C#^5uTaN?t6K85OQ)QA%uj$267ORaFkm?4mmtI)Dj_LAS5&i1gN?y;)#ep z6tGfkrQlhQ$Oc70@BnX7Yn7tbt0JwnlzLm}H~%i1h*$-7X8!-5f9{$0bGYf&rqFXo z9^Fnv{pIa=dY^As@H+*+cL45CYNLWbIP?K;Qfjk;JN5J~rS5j99p7W|y^1#}xKF_! zExzBOB<%15{GjeUltAOS+2V&CO6M)Q6SlY|9h$=bR4tz=_*Z-g@Q{-Kw)wCg?z8znHh*sO z7YY0&f2H7Si@$N`JpNYCzq9zi4ps6IUA$=VQHN&p5lhIS3ly_M7b+Hq=JF;>d=AxU zUgjbT5+{C30=8HVEih4)kZnsm^owIjf+Mc9b7+yYw4MF4D#Ol7yR* ztUSpoE=57Af;6a*R7=twS}q+e>EzH=yvdf%z|uuGyDF8TAX61)+0xCS&~nMvRd-u* zl&Oa+;V-<{3HRF+gnV{6E8pw&3Owz?<4b~J5+Z0PqbKuG8x_yQtXUbVl8Q|HrOtod2 zEz@n8;mA31t}W*|@=KYij1vOGUO|K6kFF{eobTP^E6SW@%WQ|<;cWm?WyuAW%(3J` zOR6oI>mB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<#qW6 z{pN>`8)G{3V^DSIIF1kf+-ZO8^i6zo)Po_>Zn5&aO>5J5B%xO1I80gWVT3W#C}XW+J0mRpMH<(GHJ(SJO(4&=u*{0(o?Ja`wBr?es4lC#?*X1q=1 z-P@3DiR}*FZ1f%~PiZ3$Eqd>a$imaseZ&u9qpc>49tQunM(TI;DR4Qyc2n?=_oEm- O%dys Date: Tue, 2 Dec 2014 17:54:49 -0800 Subject: [PATCH 2/4] actual a7 code --- df | 143 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 143 insertions(+) create mode 100644 df diff --git a/df b/df new file mode 100644 index 0000000..7d2edca --- /dev/null +++ b/df @@ -0,0 +1,143 @@ +commit 42c06a8b5143e9676d137cc11acf62fb3bd30948 +Author: Sky Johnson +Date: Tue Dec 2 15:36:31 2014 -0800 + + add code up to Act 7, rekt + +commit 76e03ffb600b0e195cc2c250929d72df495de027 +Author: Will Kaufman +Date: Tue Dec 2 15:21:25 2014 -0700 + + works on A6 exercises + +commit 67a4cec4c8dd52fd2d4af0808ab03fe9333758e5 +Author: Will Kaufman +Date: Tue Dec 2 14:26:28 2014 -0700 + + updates Questions for A4 + +commit 8a94109a61bf781ed32a78a31bd4a10c7afa5cbc +Merge: fdf4efa f41de47 +Author: Jackson Chen +Date: Tue Dec 2 14:25:20 2014 -0700 + + Fixes conflicts + +commit fdf4efac34e99e02d5bc8180bcd42d7ccb021d60 +Author: Jackson Chen +Date: Tue Dec 2 14:22:03 2014 -0700 + + A5 Questions + +commit f41de47da7ff5cce3d4f4458b76445a4c5f5ed9f +Author: Will Kaufman +Date: Tue Dec 2 14:17:45 2014 -0700 + + cleans up files in classes/ + +commit 1283b31fed3d950998160cb80a5d5c88f46f3e6d +Author: Will Kaufman +Date: Tue Dec 2 14:11:39 2014 -0700 + + completes A4 exercises + +commit 4a0eb201c5accbd186885a1a8ab1fad24a45f889 +Author: Jackson Chen +Date: Tue Dec 2 11:20:52 2014 -0700 + + Finishes A3 + +commit 9b2dc2c6c3748155c71aafb7222468a1e9a08a65 +Merge: 8a45046 fcfb214 +Author: Jackson Chen +Date: Tue Dec 2 11:07:43 2014 -0700 + + Adds backbone + +commit 8a450469537f17ffaab90c96dbcb647bd1ac7bee +Author: Jackson Chen +Date: Tue Dec 2 11:05:13 2014 -0700 + + Adds backbone to all the questions + +commit fcfb214319f6afeb1f3ae7a4c88d8def387461e2 +Author: Jackson Chen +Date: Mon Dec 1 17:21:56 2014 -0700 + + Update README + +commit e4b1a733f4b0d9010b16a5a29af1bbee915417c2 +Author: Will Kaufman +Date: Mon Dec 1 14:26:55 2014 -0700 + + works on A3 exercises + +commit 707b420f7ac8b8f14f5221df6c31b188c07c0ee9 +Merge: c663b44 36368f7 +Author: Will Kaufman +Date: Mon Dec 1 14:14:19 2014 -0700 + + fixes Questions + +commit 36368f720a6fc038ff727e3c0000d35255931afa +Author: Jackson Chen +Date: Mon Dec 1 14:12:58 2014 -0700 + + Gitignore update + +commit c663b44cfc4053e7f3ea3eb7763e2e72e331c123 +Author: Will Kaufman +Date: Mon Dec 1 14:11:32 2014 -0700 + + adds answers to question A3 + +commit a3dd22952f82570384368369c158376ba866a2c9 +Author: Jackson Chen +Date: Mon Dec 1 14:10:15 2014 -0700 + + A2 Questions + +commit 84d04cd2c1887571fb58ab7d4419a75f83a91cea +Author: Jackson Chen +Date: Mon Dec 1 14:01:24 2014 -0700 + + Adds PDF + +commit cc89e3c432753982cf83e6a937196da33670102a +Author: Jackson Chen +Date: Mon Dec 1 13:59:05 2014 -0700 + + A1 Questions + +commit 0060c952bc1137d3d869cc37c5dc9a58d1a3b5a6 +Author: Will Kaufman +Date: Mon Dec 1 13:52:12 2014 -0700 + + updates README again + +commit 87bde428f7a89be04e73d9940e6c4dcdebe97b75 +Author: Will Kaufman +Date: Mon Dec 1 13:50:52 2014 -0700 + + updates README + +commit 3cadd3a5a33ad9692885a29de639958d8cc09ca5 +Merge: a2c34ac d136c85 +Author: Jackson Chen +Date: Mon Dec 1 13:41:15 2014 -0700 + + Merge branch 'master' of https://github.com/jacksonchen/Picture-Lab + + README + +commit a2c34ac038e9397a405b6359ae12e4e993f81236 +Author: Jackson Chen +Date: Mon Dec 1 13:40:45 2014 -0700 + + First commit + +commit d136c85fb96fc3414e3e1fd011ab8d202f5f3e46 +Author: Jackson Chen +Date: Mon Dec 1 13:39:23 2014 -0700 + + Initial commit From 3598a1be1090ff67cd6c9a64a771390ed4e57018 Mon Sep 17 00:00:00 2001 From: Sky Johnson Date: Wed, 3 Dec 2014 15:12:07 -0800 Subject: [PATCH 3/4] finish lab 9 --- classes/Picture.java | 238 +++++++++++++-- classes/PictureExplorer.class | Bin 15258 -> 15258 bytes classes/PictureExplorer.java | 2 +- classes/PictureTester.java | 286 +++++++++-------- classes/doc/Picture.html | 458 +++++++++++++++++++--------- classes/doc/allclasses-frame.html | 30 +- classes/doc/allclasses-noframe.html | 30 +- classes/doc/constant-values.html | 107 +------ classes/doc/index.html | 9 +- classes/doc/logfile.txt | 41 +++ classes/doc/package-frame.html | 40 +-- classes/doc/package-summary.html | 174 +---------- classes/doc/stylesheet.css | 26 +- classes/package.bluej | 27 +- images/collage.jpg | Bin 0 -> 17074 bytes images/magic.jpg | Bin 0 -> 5427 bytes 16 files changed, 803 insertions(+), 665 deletions(-) create mode 100644 classes/doc/logfile.txt create mode 100644 images/collage.jpg create mode 100644 images/magic.jpg diff --git a/classes/Picture.java b/classes/Picture.java index f189aea..06518b0 100755 --- a/classes/Picture.java +++ b/classes/Picture.java @@ -127,7 +127,7 @@ public void negate(){ } } - public void grayscale(){ + public void grayScale(){ Pixel[][] pixels = this.getPixels2D(); for (Pixel[] rowArray : pixels) { @@ -302,6 +302,28 @@ public void mirrorArms() } } + public void mirrorGull() + { + int top = 229; + int bot = 330; + int right = 347; + int left = 225; + + Pixel[][] pixels = this.getPixels2D(); + Pixel lookingatPixel = null; + Pixel copyingPixel = null; + + for (int row = top; row < bot; row++) + { + for (int col = left; col < right; col++) + { + lookingatPixel = pixels[row][col]; + copyingPixel = pixels[row][col-120]; + copyingPixel.setColor(lookingatPixel.getColor()); + } + } + } + /** copy from the passed fromPic to the * specified startRow and startCol in the * current picture @@ -333,45 +355,217 @@ public void copy(Picture fromPic, } } - /** Method to create a collage of several pictures */ - public void createCollage() + public void copy(Picture fromPic, + int toRow, int toCol, int fromRowStart, int fromRowEnd, int fromColStart, int fromColEnd) { - Picture flower1 = new Picture("flower1.jpg"); - Picture flower2 = new Picture("flower2.jpg"); - this.copy(flower1,0,0); - this.copy(flower2,100,0); - this.copy(flower1,200,0); - Picture flowerNoBlue = new Picture(flower2); - flowerNoBlue.zeroBlue(); - this.copy(flowerNoBlue,300,0); - this.copy(flower1,400,0); - this.copy(flower2,500,0); - this.mirrorVertical(); - this.write("collage.jpg"); + Pixel fromPixel = null; + Pixel toPixel = null; + Pixel[][] toPixels = this.getPixels2D(); + Pixel[][] fromPixels = fromPic.getPixels2D(); + for(int toPixelRow = toRow, fromPixelRow = fromRowStart; + fromPixelRow < fromRowEnd; + toPixelRow++, fromPixelRow++){ + for(int toPixelCol = toCol, fromPixelCol = fromColStart; + fromPixelCol < fromColEnd; + toPixelCol++, fromPixelCol++){ + try{ + fromPixel = fromPixels[fromPixelRow][fromPixelCol]; + toPixel = toPixels[toPixelRow][toPixelCol]; + toPixel.setColor(fromPixel.getColor()); + }catch(Exception e){ + toPixelCol+=1000; + fromPixelCol+=1000; + } + } + } + } + + public void copy(Picture fromPic, + int toRow, int toCol, int fromRowStart, int fromRowEnd, int fromColStart, int fromColEnd, int effect) + { + Pixel fromPixel = null; + Pixel toPixel = null; + Pixel[][] toPixels = this.getPixels2D(); + switch(effect){ + case 0: break; + case 1: fromPic.zeroBlue(); break; + case 2: fromPic.keepOnlyBlue(); break; + case 3: fromPic.negate(); break; + case 4: fromPic.grayScale(); break; + case 5: fromPic.fixUnderwater(); break; + + } + Pixel[][] fromPixels = fromPic.getPixels2D(); + for(int toPixelRow = toRow, fromPixelRow = fromRowStart; + fromPixelRow < fromRowEnd; + toPixelRow++, fromPixelRow++){ + for(int toPixelCol = toCol, fromPixelCol = fromColStart; + fromPixelCol < fromColEnd; + toPixelCol++, fromPixelCol++){ + try{ + fromPixel = fromPixels[fromPixelRow][fromPixelCol]; + toPixel = toPixels[toPixelRow][toPixelCol]; + toPixel.setColor(fromPixel.getColor()); + }catch(Exception e){ + toPixelCol+=1000; + fromPixelCol+=1000; + } + } + } } + public void createMagic(){ + Picture a = new Picture("beach.jpg"); + Picture b = new Picture("seagull.jpg"); + + this.copy(a,0,0,0,479,0,639); + this.copy(b,100,100, 229, 330, 225, 347); + + } + + public void myCollage(){ + Random k = new Random(); + + Pixel[][] collage = this.getPixels2D(); + + Picture a = new Picture("beach.jpg"); + Picture b = new Picture("seagull.jpg"); + Picture c = new Picture("snowman.jpg"); + Picture[] pics = {a,b,c}; + int thisheight = collage.length; + int thislength = collage[0].length; + int firsty = 0; + for(int y = 0; ythislength){ + xadd=thislength-x; + } + int yadd = k.nextInt(100); + if(yadd>thisheight){ + yadd=thisheight-y; + } + int piccstart = k.nextInt(539); + int piccend= piccstart+yadd; + int picrstart = k.nextInt(379); + int picrend=picrstart+xadd; + this.copy(pics[whichpic],y+yadd,x+xadd,picrstart,picrend,piccstart,piccend,effect); + firsty=yadd; + x+=xadd; + } + y+=firsty; + } + + } + /** Method to create a collage of several pictures */ + // public void createCollage() + // { + // Picture flower1 = new Picture("flower1.jpg"); + // Picture flower2 = new Picture("flower2.jpg"); + // this.copy(flower1,0,0); + // this.copy(flower2,100,0); + // this.copy(flower1,200,0); + // Picture flowerNoBlue = new Picture(flower2); + // flowerNoBlue.zeroBlue(); + // this.copy(flowerNoBlue,300,0); + // this.copy(flower1,400,0); + // this.copy(flower2,100,0); + // this.copy(flower1,200,0); + // Picture flowerNoBlue = new Picture(flower2); + // + // this.copy(flowerNoBlue,300,0); + // this.copy(flower1,400,0); + // this.copy(flower2,500,0); + // this.mirrorVertical(); + // this.write("collage.jpg"); + // } + /** Method to show large changes in color * @param edgeDist the distance for finding edges */ public void edgeDetection(int edgeDist) { - Pixel leftPixel = null; + Pixel curPixel = null; Pixel rightPixel = null; + + Pixel botPixel = null; Pixel[][] pixels = this.getPixels2D(); Color rightColor = null; - for (int row = 0; row < pixels.length; row++) + Color botColor = null; + for (int row = 0; row < pixels.length-1; row++) { for (int col = 0; col < pixels[0].length-1; col++) { - leftPixel = pixels[row][col]; + curPixel = pixels[row][col]; rightPixel = pixels[row][col+1]; + botPixel = pixels[row+1][col]; + botColor = botPixel.getColor(); rightColor = rightPixel.getColor(); - if (leftPixel.colorDistance(rightColor) > + if (curPixel.colorDistance(rightColor) > edgeDist) - leftPixel.setColor(Color.BLACK); - else - leftPixel.setColor(Color.WHITE); + curPixel.setColor(Color.BLACK); + else if(curPixel.colorDistance(botColor) > edgeDist){ + curPixel.setColor(Color.BLACK); + }else{ + curPixel.setColor(Color.WHITE); + } + } + } + } + + public void edgeDetection2() + { + Pixel curPixel = null; + Pixel rightPixel = null; + Pixel leftPixel = null; + Pixel topPixel = null; + Pixel botPixel = null; + Pixel[][] pixels = this.getPixels2D(); + Pixel[][] pixelsOrg= this.getPixels2D(); + + double averageDif = 0; + int totalpixs = 0; + + for (Pixel[] rowArray : pixels) + { + for (Pixel pixelObj : rowArray) + { + totalpixs++; + averageDif+=pixelObj.getAverage(); + } + } + int edgeDist = ((int)averageDif)/totalpixs; + + System.out.println(totalpixs+" "+averageDif+" "+edgeDist); + for (int row = 1; row < pixels.length-1; row++) + { + for (int col = 1; + col < pixels[0].length-1; col++) + { + curPixel = pixels[row][col]; + + rightPixel = pixelsOrg[row][col+1]; + botPixel = pixelsOrg[row+1][col]; + + + + double k2 = rightPixel.getAverage()+botPixel.getAverage()+curPixel.getAverage(); + k2 = (edgeDist*edgeDist)/((k2/3)*(k2/3)+3); + //System.out.println(k2); + + if(//curPixel.colorDistance(leftPixel.getColor())>5|| + curPixel.colorDistance(rightPixel.getColor())>k2|| + //curPixel.colorDistance(topPixel.getColor())>5|| + curPixel.colorDistance(botPixel.getColor())>k2){ + + curPixel.setColor(Color.BLACK); + + }else{ + curPixel.setColor(Color.WHITE); + } } } } diff --git a/classes/PictureExplorer.class b/classes/PictureExplorer.class index a5a9154b6cadf37aa0b08d486cbfbcb9a4751b1e..ff58b2e9c9c5cb4819bc9cdfac4bca3a7521c70c 100644 GIT binary patch delta 19 bcmbPLKC67gEm5}A#PrgfoXrnJcc}sZTG

- + + -Picture (classes) +Picture - +