Invention2.java
1    /* 
2     * Program that uses at least one (while) statement, one (if) statement, 
3     * features solely rectangles all generated from one rectangle. 
4     * Creates a different image each time the program is executed. 
5     */
6    package npw;
7    
8    import painter.SPainter;
9    import shapes.SRectangle;
10   
11   import java.awt.*;
12   import java.util.Random;
13   
14   public class Invention2 {
15   
16        public static void main(String[] args) {
17            // create the objects to think with
18            SPainter miro = new SPainter("Invention 2", 600, 600);
19            SRectangle rectangle = getRandomRectangle();
20            miro.setColor(randomColor());
21            miro.paint(rectangle);
22   
23            int x = 0;
24            while ( x<=10) {
25                rectangle.shrink(5,5);
26                miro.setColor(randomColor());
27                miro.paint(rectangle);
28                x = x+1;
29            }
30   
31        }
32   
33        private static SRectangle getRandomRectangle() {
34            int width = getRandomNumber(500)+100;
35            int height = getRandomNumber(600)+100;
36            return new SRectangle(width, height);
37        }
38   
39        private static int getRandomNumber(int limit) {
40            Random rgen = new Random();
41            int number = rgen.nextInt(limit);
42            return number;
43        }
44   
45        private static Color randomColor() {
46            int rv = (int) (Math.random() * 246);
47            int gv = (int) (Math.random() * 276);
48            int bv = (int) (Math.random() * 256);
49            return new Color(rv, gv, bv);
50        }
51    }
52   
53   
54