Invention2.java
1    package npw;
2    
3    
4    import painter.SPainter;
5    import shapes.SRectangle;
6    
7    import java.awt.*;
8    import java.util.Random;
9    
10   public class Invention2 {
11       public static void main(String[] args) {
12           // So Create the Object to Think With it
13           SPainter inventor = new SPainter("Invention2", 600, 600);
14           inventor.setBrushWidth(7);
15           SRectangle rectangle = new SRectangle(550,450);
16           paintTheImage(inventor,rectangle);
17       }
18   
19       private static void paintTheImage(SPainter painter, SRectangle rectangle) {
20           int i = 1;
21           while ( i <= 20 ) {
22               paintTwoRectangle(painter,rectangle);
23               i = i + 1 ;
24           }
25       }
26   
27       private static void paintTwoRectangle(SPainter painter, SRectangle rectangle) {
28           Random rgen = new Random();
29           double length = rgen.nextInt(250);
30           double width = rgen.nextInt(200);
31           if (length > 150) {
32               painter.setColor(Color.pink);
33           } else if (length < 50){
34               painter.setColor(Color.green);
35           } else painter.setColor(randomColor());
36           rectangle.shrink(length,width);
37           painter.draw(rectangle);
38           rectangle.shrink(-length/7*6,-width/7*6);
39           painter.draw(rectangle);
40       }
41   
42       private static Color randomColor() {
43           int rv = (int)(Math.random()*256);
44           int gv = (int)(Math.random()*256);
45           int bv = (int)(Math.random()*256);
46           Color color = new Color(rv,gv,bv);
47           return color;
48       }
49   }
50