Invention2.java
1    /* 
2     * Program that uses randomly colored rectangles to paint a different image every time it is ran 
3     */
4    
5    
6    package npw;
7    
8    import java.awt.Color;
9    import java.util.Random;
10   
11   import painter.SPainter;
12   import shapes.SRectangle;
13   
14   public class Invention2 {
15   
16       public static void main(String[] args) {
17           int width = 60;
18           int height = 120;
19   
20           SPainter painter = new SPainter("Invention 2", 800, 800);
21   
22           paintRectangle(painter, height, width);
23       }
24   
25       private static void paintOneRectangle(SPainter painter) {
26           painter.setColor(randomColor());
27           painter.move();
28           SRectangle rectangle = new SRectangle(60, 120);
29           painter.paint(rectangle);
30       }
31   
32       private static void paintRectangle(SPainter painter, int width, int height) {
33           int i = 1;
34           while (i <= width) {
35               while (i <= height)
36                   paintOneRectangle(painter);
37               i = 1 + 1;
38           }
39       }
40   
41       private static Color randomColor() {
42           Random rgen = new Random();
43           int r = rgen.nextInt(256);
44           int g = rgen.nextInt(256);
45           int b = rgen.nextInt(256);
46           return new Color(r, b, g);
47       }
48   }
49   
50   
51   
52   
53