# Problems

[Page 207 (continued)]

 6.1 What are each of the following: Conditional executionShort circuit evaluationA boolean expression[Page 208]ChromakeySepia-tintPosterizeEdge detectionBlurring 6.2 Try doing chromakey (page 203) in a rangegrab something out of its background where the something is only in one part of a picture. For example, put a halo around someone's head, but don't mess with the rest of their body. 6.3 Try doing edge detection (page 184) in a range. Change just part of a picture by passing in the start x, start y, end x, and end y. 6.4 Try doing sepia-tint (page 188) in a range. Change just part of a picture by passing in the start x, start y, end x, and end y. 6.5 Modify the general copy method copyPictureTo on page 152 in Chapter 5 to stop looping if it is past the width of either the source picture or the current picture. 6.6 Write a method to copy all but the white pixels from one picture to another. Use this to put the robot in robot.jpg on the moon in moon-surface.jpg. 6.7 Start with a picture of someone you know, and make some specific color changes to it: Turn the skin green.Turn the eyes red.Turn the hair orange. Of course, if you're friend's skin is already green, or eyes red, or hair orangechoose different target colors. 6.8 Which of the methods below removes all the blue from every pixel of a picture that already has a blue value of more than 100? A onlyD onlyB and CC and DNoneAll What do the other ones do? `public void blueOneHundred() { Pixel p = null; for (int x = 0; x < 100; x++) { [Page 209] for (int y=0; y < 100; y++) { p = getPixel(x,y); p.setBlue(100); } } }``public void blueChange() { Pixel[] pixelArray = getPixels(); Pixel pixel = null; for (int i = 0; i < pixelArray.length; i++) { pixel = pixelArray[i]; if (pixel.getBlue() > 0) { pixel.setBlue(100); } } }``public void clearSomeBlue() { Pixel[] pixelArray = getPixels(); Pixel pixel = null; for (int i = 0; i < pixelArray.length; i++) { pixel = pixelArray[i]; if (pixel.colorDistance(Color.BLUE) > 100) pixel.setBlue(0); } }``public void setBlue() { Pixel[] pixelArray = getPixels(); Pixel pixel = null; for (int i = 0; i < pixelArray.length; i++) { pixel = pixelArray[i]; if (pixel.getBlue() > 100) pixel.setBlue(0); } }` [Page 210] 6.9 What is the result from the following: `boolean value1 = true; boolean value2 = false; if (value1 && value2) System.out.println("first if is true"); if (value1 || value2) System.out.println("second if is true"); if (value1 && !value2) System.out.println("third if is true"); if (value1 || !value2) System.out.println("fourth if is true"); if (!value1 && value2) System.out.println("fifth if is true"); if (!value1 || value2) System.out.println("sixth if is true"); if (!value1 && !value2) System.out.println("seventh if is true"); if (!value1 || !value2) System.out.println("eighth if is true");` 6.10 Write the method to turn the lightest areas of a picture gray to simulate a fog. 6.11 Write the method to turn the darkest areas of a picture green. 6.12 Write a method to lighten the darkest areas of a picture. 6.13 Write a method to darken the lightest areas of a picture. 6.14 Write a method to turn the pixels with an average color < 85 green, pixels with an average color < 170 red, and the rest of the pixels blue. 6.15 Write another method to blur the picture (Program 42 (page 195)) but this time make a copy of the picture first and use the values from the copy to determine the new value for a pixel. To make a copy of a picture, just create a new picture passing in the old one Picture copy = new Picture(oldPicture);. 6.16 Write other edge detection methods (page 184). Try comparing the current pixel intensity with the one on the right. Try comparing the current pixel to the average of the pixels to the right and below. 6.17 What would the output from the following be: `int x = 30; for (int i=x; i < 40; i++) { if (i < 35) System.out.println("i is less than 35"); else if (i == 35) System.out.println("i is 35"); else System.out.println("i is greater than 35"); }` [Page 211] 6.18 What would the output from the following be: `boolean continue = true; int count = 0; int max = 20; while (continue) { System.out.println(count); count++; max++; if (count > 10 && max > 40) continue = false; }` 6.19 What would the output from the following be: `boolean continue = true; int count = 0; int max = 20; while (continue) { System.out.println(count); count++; max++; if (count > 10 || max > 40) continue = false; }` 6.20 Write a method to do green or red chromakey (page 203). Introduction to Computing & Programming Algebra in Java(c) A Multimedia Approach
ISBN: N/A
EAN: N/A
Year: 2007
Pages: 191