/** * Class for making a simple drawing with Turtles * * @author Pat Troy: troy AT uic DOT edu */ // This example has the turtle draw in a picture that can be saved. import java.util.*; import java.awt.*; public class Lect107i { public static void main(String[] args) { // create the picture and a turtle String fileName = FileChooser.pickAFile(); Picture pict = new Picture (fileName); // get an array of pixels Pixel pixArray[]; pixArray = pict.getPixels(); System.out.println ("Width: " + pict.getWidth()); System.out.println ("Height: " + pict.getHeight()); System.out.println ("Total Pixels: " + pict.getWidth() * pict.getHeight()); System.out.println ("Array Length: " + pixArray.length ); System.out.println ( pixArray [0] ); int index; Pixel pix; Color cl1, cl2; int red, green, blue, gray; for ( index = 0 ; index < pixArray.length ; index++ ) { //System.out.println ( pixArray [index] ); pix = pixArray[index]; cl1 = pix.getColor(); red = pix.getRed(); green = pix.getGreen(); blue = pix.getBlue(); // create black and white gray = (int)(red*.299 + green*.587 + blue*.114); pix.setRed (gray); pix.setGreen (gray); pix.setBlue (gray); pixArray[index] = pix; } // display the picture pict.explore(); // save the picture to the computer // Note: Be sure to add the .jpg to the end of the filename!!!!! fileName = FileChooser.pickAFile(); System.out.println(fileName); pict.write (fileName); } }