programs and use primary colors and When you arrive in the art red, green blue. room and start painting, mix primary paint colors and red, blue yellow. It is interesting to note that RGB colors with minimal values zero, have no at all and become totally black. When all three RGB colors reach the maximum color value of 255, the result is white. Now load ColorDemo02.java, shown in figure 15.20. This program generates three random integer values in the [0.255] range and displays a large square of that color and its RGB values. Execute the program multiple times to observe different color combination. Figure 15.20 // ColorDemo02.java // This color demo shows a new random color and its // RGB values each time it is executed. import java.awt.*; import java.applet.*; public class ColorDemo02 extends Applet { public void paint(Graphics g) { int rndRed = (int) (Math.random() * 255); int rndGreen = (int) (Math.random() * 255); int rndBlue = (int) (Math.random() * 255); Color randomColor = new Color(rndRed,rndGreen,rndBlue); g.setColor(randomColor); g.fillRect(50,50,400,400); g.setColor(Color.black); g.setFont(new Font("Arial",Font.BOLD,48)); String colorString = "[" + rndRed + "," + rndGreen + "," + rndBlue + "]"; g.drawString(colorString,100,225); } } Figure 15.20 Continued All the files of the AP Picture programs are in one location. To simplify access you are working with folders that only have the necessary program files available for each individual experiment. This will mean duplication of files, but the intention is to make the individual experiments simpler.
programs and use primary colors red, green and blue. When you arrive in the art room and start painting, mix primary paint colors red, blue and yellow. It is interesting to note that RGB colors with minimal values zero, have no at all and become totally black. When all three RGB colors reach the maximum color value of 255, the result is white. Now load ColorDemo02.java, shown in figure 15.20. This program generates three random integer values in the [0.255] range and displays a large square of that color and its RGB values. Execute the program multiple times to observe different color combination. Figure 15.20 // ColorDemo02.java // This color demo shows a new random color and its // RGB values each time it is executed. import java.awt.*; import java.applet.*; public class ColorDemo02 extends Applet { public void paint(Graphics g) { int rndRed = (int) (Math.random() * 255); int rndGreen = (int) (Math.random() * 255); int rndBlue = (int) (Math.random() * 255); Color randomColor = new Color(rndRed,rndGreen,rndBlue); g.setColor(randomColor); g.fillRect(50,50,400,400); g.setColor(Color.black); g.setFont(new Font("Arial",Font.BOLD,48)); String colorString = "[" + rndRed + "," + rndGreen + "," + rndBlue + "]"; g.drawString(colorString,100,225); } } Figure 15.20 Continued All the files of the AP Picture programs are in one location. To simplify access you are working with folders that only have the necessary program files available for each individual experiment. This will mean duplication of files, but the intention is to make the individual experiments simpler.