Invention2.java
1    package npw;
2    
3    import painter.SPainter;
4    import java.awt.Color;
5    
6    import shapes.SRectangle;
7    
8    public class Invention2 {
9        public static void main(String[] args){
10           SPainter L = new SPainter("Liu Invention", 800, 800);
11   
12           double Height = (Math.random() * 100 + 50);
13           double Width = (Math.random() * 50 + 50);
14           int NumOfRectangles = 20;
15           int RecPosition, ColorNum, dist;
16   
17           SRectangle liu = new SRectangle(Height, Width);
18   
19           int i = 0;
20           while (i < NumOfRectangles) {
21               dist = (int) (Math.random() * 200 + 100);
22   
23               RecPosition = (int) (Math.random() * 4 + 1);
24               if (RecPosition == 1){
25                   L.mlt(dist);
26               } if (RecPosition == 2){
27                   L.mfd(dist);
28               } if (RecPosition == 3){
29                   L.mrt(dist);
30               } if (RecPosition == 4){
31                   L.mbk(dist);
32               }
33   
34   
35               ColorNum = (int) (Math.random() * 2 + 1);
36               if (ColorNum == 1){
37                   L.setColor(Color.ORANGE);
38               } else {
39                   L.setColor(Color.lightGray);
40               }
41   
42               L.paint(liu);
43   
44               L.moveToCenter();
45   
46               i++;
47           }
48   
49       }
50   }
51