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    
10   public class Invention2 {
11       private void paintTheImage() {
12           double width = 20;
13           double length = 40;
14           SRectangle rectangle = new SRectangle(15, 30);
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                   rectangle.expand(width, length);
23                   i = i + 1;
24                   width = width + 10;
25                   length = length + 10;
26               } else {
27                   rectangle.shrink(width,length);
28                   painter.mfd(width);
29                   painter.tr(45);
30                   painter.draw(rectangle);
31                   i = i + 1;
32               }
33   
34           }
35       }
36   
37       private Color randomColor() {
38           int rv = (int)(Math.random()*256);
39           int gv = (int)(Math.random()*256);
40           int bv = (int)(Math.random()*256);
41           return new Color(rv,gv,bv);
42       }
43   
44       public Invention2() {
45           paintTheImage();
46       }
47   
48       public static void main(String[] args) {
49           SwingUtilities.invokeLater(new Runnable() {
50               public void run() {
51                   new Invention2();
52               }
53           });
54       }
55   }