Invention2.java
1    package npw;
2    import java.awt.Color;
3    import javax.swing.SwingUtilities;
4    import painter.SPainter;
5    import shapes.SRectangle;
6    
7    public class Invention2 {
8    
9        private void paintTheImage() {
10           SPainter painter = new SPainter("Invention2", 600, 600);
11           SRectangle rectangle = new SRectangle(20, 20);
12   
13   
14           int x = 0;
15           while (x < 200) {
16   
17               painter.moveWithinNeighborhood(150);
18               painter.paint(rectangle);
19               painter.setColor(randomColor());
20               x = x+1;}
21               if(x == 200) {
22                   painter.moveToCenter();
23                   rectangle.expand(200, 200);
24                   painter.setColor(randomColor());
25                   painter.draw(rectangle);
26               }else{painter.paint(rectangle);
27   
28   
29           }}
30   
31   
32   
33       //REQUIRED INFRASTRUCTURE
34       private static Color randomColor() {
35           int rv = (int) (Math.random() * 256);
36           int gv = (int) (Math.random() * 256);
37           int bv = (int) (Math.random() * 256);
38           return new Color(rv, gv, bv);
39       }
40       private Invention2() {
41           paintTheImage();
42   
43       }
44   
45       public static void main(String[] args){
46   
47           SwingUtilities.invokeLater(new Runnable() {
48               public void run() {
49                   new Invention2();
50               }
51           });
52       }
53       }
54   
55