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