public static Picture q21 (PPicture p1) { int w = p1.getWidth(); int h = p1.getHeight(); Picture p2 = new Picture (w*2, h); int x, y, x2, y2; Pixel pix1; Pixel pix2; for (x = 0 ; x < w ; ++x) { for (y = 0 ; y < h ; ++y) { pix1 = p1.getPixel (x, y); pix2 = p2.getPixel (x, y); pix2.setColor (pix1.getColor()); x2 = w*2 - 1 - x; y2 = y; pix2 = p2.getPixel (x2, y2); pix2.setColor (pix1.getColor()); } } return p2; }
public static Picture q22 (Picture p1) { int w = p1.getWidth(); int h = p1.getHeight(); Picture p2 = new Picture (w*2, h); int x, y; Pixel pix1; Pixel pix2; int lum; for (x = 0 ; x < w ; ++x) { for (y = 0 ; y < h ; ++y) { pix1 = p1.getPixel (x, y); lum = (pix1.getRed() + pix1.getGreen() + pix1.getBlue())/3; pix2 = p2.getPixel (x, y); if (lum < 255/3) { pix2.setColor (Color.RED); } else if (lum < 255/2*3) { pix2.setColor (Color.ORANGE); } else { pix2.setColor (Color.PINK); } } } return p2; }