Invention2.java
1    package npw;
2    import painter.SPainter;
3    import shapes.SRectangle;
4    import java.awt.*;
5    import java.util.Random;
6    
7    public class Invention2 {
8        public static void main(String[] args) {
9            SPainter miro = new SPainter("Chaos", 600, 600);
10           SRectangle rectangle = getRandomRectangle();
11           miro.setColor(randomColor());
12           miro.paint(rectangle);
13   
14           int x = 0;
15           while ( x<=10) {
16               rectangle.shrink(5,5);
17               miro.setColor(randomColor());
18               miro.paint(rectangle);
19               x = x+1;
20           }
21   
22       }
23       private static Color randomColor() {
24           int rv = (int) (Math.random() * 246);
25           int gv = (int) (Math.random() * 276);
26           int bv = (int) (Math.random() * 256);
27           return new Color(rv, gv, bv);
28       }
29       private static SRectangle getRandomRectangle() {
30           int width = getRandomNumber(400)+100;
31           int height = getRandomNumber(400)+100;
32           return new SRectangle(width, height);
33       }
34       private static int getRandomNumber(int limit) {
35           Random rgen = new Random();
36           int NUMBER = rgen.nextInt(limit);
37           return NUMBER;
38       }
39   }