============================== exercise with Colors try some student suggestions... 255, 107, 0 0, 237, 0 128, 0, 255 255, 225, 0 ============================== SLIDES ON REPRESENTATION AND ARRAYS... rows first -OR- columns first (common) (math, images) // *********** but early on we we will process all the pixels, // as if the pixels were in one long line ============================== ... then: > double[] mileage; > mileage null > double[] mileageForWeek = {4.5, 7, 10, 6.5, 10, 0, 22}; > mileageForWeek[0] 3.0 > mileageForWeek[4] 10.0 > mileageForWeek[6] 22.2 > mileageForWeek [D@eea96c // ??? // *********** but you will get your array of Pixels from a Picture ============================== exploring Pictures, Pixels, Colors > Picture picture = new Picture( "/Users/wallingf/Desktop/wheaties-box.jpg" ); > picture Picture, filename ...wheaties-box.jpg height 640 width 480 > Pixel pixel = picture.getPixel(320,240); > pixel Pixel red=188 green=128 blue=154 > pixel.getRed() 188 > picture.getPixel(320,240).getBlue() 154 > pixel.getColor() java.awt.Color[r=188,g=128,b=154] ============================== class fields and methods; object methods > FileChooser.pickAFile(); > Sound clip = FileChooser.pickAFile(); Error: Bad types in assignment > Sound clip = new Sound( FileChooser.pickAFile() ); > clip.play(); > FileChooser.pickAFile(); > Sound.play(); Error: class SimpleSound.play() is not a static method. > Integer.MAX_VALUE 2147483647 > Picture.negate(); Error: class Picture.negate() is not a static method. ============================== introducing the for loop > pixel.setColor( Color.black ); Error: Undefined class 'Color' > import java.awt.Color; > pixel.setColor( Color.black ); > p.show(); > pixel.setColor( Color.red ); > p.show(); > pixel.setColor( new Color( 12, 253, 47 ) ); > p.show(); > p.getPixel(320,240).setColor( Color.black ); > p.getPixel(320,241).setColor( Color.black ); > p.getPixel(320,242).setColor( Color.black ); > p.getPixel(320,243).setColor( Color.black ); > p.getPixel(320,244).setColor( Color.black ); > p.getPixel(320,245).setColor( Color.black ); > p.getPixel(320,246).setColor( Color.black ); > p.getPixel(320,247).setColor( Color.black ); > p.getPixel(320,248).setColor( Color.black ); > p.getPixel(320,249).setColor( Color.black ); > p.show(); > for (int y = 240; y < 250; y++) p.getPixel(320, y).setColor( Color.white ); > p.show(); // Are you surprised to see the white line? Recall the colors // of the original pixel: red=188 green=128 blue=154 ============================== a longer black line... > p = new Picture( "/Users/wallingf/Desktop/wheaties-box.jpg" ); > p.show(); > for (int y = 240; y < 250; y++) p.getPixel(320, y).setColor( Color.black ); > p.show(); > for (int y = 240; y < 340; y++) p.getPixel(320, y).setColor( Color.black ); > p.show(); // *** HOW do we grow the line in the opposite direction? // *** HOW do we draw the line horizontally? ============================== for-loops *over PixelArrays* // LOOK AT clearBlue() in Picture // LOOK AT negate() in Picture Picture wheatiesBox = new Picture( "/Users/wallingf/Desktop/wheaties-box.jpg" ); > wheatiesBox.show(); > wheatiesBox.clearBlue(); > wheatiesBox.show(); > Pixel[] pixels = wheatiesBox.getPixels(); > for (int i = 0; i < pixels.length; i++) { red = pixels[i].getRed(); green = pixels[i].getGreen(); pixels[i].setBlue( (red + green) / 2 ); } > wheatiesBox.write( "/Users/wallingf/Desktop/wheaties-box-unblued.jpg" );