/home/ssingh6/NetBeansProjects/CS1/src/npw/Invention2.java
 1 /*
 2  * To change this license header, choose License Headers in Project Properties.
 3  * To change this template file, choose Tools | Templates
 4  * and open the template in the editor.
 5  */
 6 package npw;
 7 
 8 import java.awt.Color;
 9 import java.util.Random;
10 import painter.SPainter;
11 import shapes.SRectangle;
12 
13 /**
14  *
15  * @author ssingh6
16  */
17 public class Invention2 {
18 
19     /**
20      * @param args the command line arguments
21      */
22     public static void main(String[] args) {
23       // create the objects to think with
24          SPainter miro = new SPainter("Invention 2", 600, 600);
25          SRectangle rectangle = getRandomRectangle();
26          miro.setColor(randomColor());
27          miro.paint(rectangle);
28      
29          int x = 0;
30          while ( x<=10) {
31              rectangle.shrink(5,5);
32              miro.setColor(randomColor());
33              miro.paint(rectangle);                    
34              x = x+1;
35         }
36  
37      }
38      
39     private static SRectangle getRandomRectangle() {
40          int width = getRandomNumber(400)+100;
41          int height = getRandomNumber(500)+100;
42        return new SRectangle(width, height);
43      }
44 
45      private static int getRandomNumber(int limit) {
46          Random rgen = new Random();
47          int number = rgen.nextInt(limit);
48         return number;
49     }
50      private static Color randomColor() {
51          int rv = (int) (Math.random() * 256);
52          int gv = (int) (Math.random() * 256);
53          int bv = (int) (Math.random() * 256);
54          return new Color(rv, gv, bv);
55     }
56  }