CS 111 - 4/8/14 int z; z = 0; for (x = 0 ; x < 5 ; x++) { z = x + z; } x 0 1 2 3 4 5 z 0 0 1 3 6 10 -------- x = 0 ; while ( x < 5 ) { z = x + z; x++; } x = 1; y = 2; z = 3; (( x <= z && z > 6) || y >= x ) ( t && f ) || t f || t t truth table x y | x && y x || y !x ====================================== t t | t t f t f | f t f f t | f t t f f | f f t ------------------------------------- z = 2; for (x = 1 ; x < 3 ; x++) { if ( x < 2 || z > 3) { z = z + 2; } else { z = z + 1; } } ----------------------------------------- z = 2; for (x = 1 ; x < 3 ; x++) { if ( !(x < 2) ) { z = z + 2; } else { z = z + 1; } } ------------------------------------ (( x <= z && !(z != 6)) || !(y >= x) ) (( x <= z && (z == 6)) || (y < x) ) ------------ Write method public static Picture name ( Picture p, ) { Picture p2 = new Picture ( , ); int x; int y; for ( x = 0 ; x < p.getWidth() ; x++) for ( y = 0 ; y < p.getHeight() ; y++ ) { Pixel pix1 = p.getPixel(x, y); .... } return p2; } pix2.setColor(Color.BLUE); ----------------- z = 1; for ( x = 1 ; x < 4 ; x++ ) { for (y = 1 ; y < 4 ; y++) { z = x + y + z; } } x 1 2 3 4 y 1 2 3 4 1 2 3 4 1 2 3 4 z 1 3 6 10 13 17 22 26 31 37 -------------------------------------- Xindex = 0; while ( Xindex < width) { Yindex = 0; while (Yindex < height) { Pixel pix = p.getPixel(Xindex, Yindex); int r = pix.getRed (); int g = pix.getRed (); int b = pix.getRed (); r = r/2; g = g/2; b = b/2; pix.setRed(r); pix.setGreen(g); pix.setBlue(b); Yindex = Yindex + 1; } Xindex = Xindex + 1; } ================ pix4.setColor (c1); pix4.setColor (mod1(c1)); Color c2 = mod1 (c1); pix4.setColor (c2); public static Color mod1 (Color c) { int red = c.getRed(); int green = c.getGreen(); int blue = c.getBlue(); Color c2 = new Color (0,0,0); int brightness = (int)(red*0.299 + green*0.587 + blue*0.114) ; if ( brightness < 64 ) { c2.setRed (0); c2.setGreen (0); c2.setBlue (192); } else if ( brightness < 128 ) { c2.setRed (76); c2.setGreen (66); c2.setBlue (216); } else if ( brightness < 192 ) { c2.setRed (243); c2.setGreen (0); c2.setBlue (243); } else { c2.setRed (243); c2.setGreen (243); c2.setBlue (38); } return c2; }