Invention2.java
1    package npw;
2    
3    import painter.SPainter;
4    import shapes.SRectangle;
5    
6    import javax.swing.*;
7    import java.awt.*;
8    import java.util.Random;
9    
10   public class Invention2 {
11       private void paintTheImage() {
12           SPainter painter = new SPainter("Invention 2",600,600);
13           double width = 1200;
14           double height = 1200;
15           SRectangle rectangle = new SRectangle(height, width);
16           int i = 0;
17           while(i < 100){
18               if(i % 2 == 0) {
19                   width /= 1.125;
20               }
21               if(i % 3 == 0) {
22                   height /= 1.166;
23               }
24               if(i + 23 % 5 == 1) {
25                   width *= width;
26               }
27               if(i % 6 == 7) {
28                   height *= width;
29               }
30               painter.setColor(randomColor());
31               rectangle.resetHeight((int) height);
32               rectangle.resetWidth((int) width);
33               painter.paint(rectangle);
34               i++;
35           }
36       }
37       private static Color randomColor() {
38           Random rgen = new Random();
39           int r = rgen.nextInt(256);
40           int g = rgen.nextInt(256);
41           int b = rgen.nextInt(256);
42           return new Color(r,g,b);
43       }
44   
45       public Invention2() {
46           paintTheImage();
47       }
48   
49       public static void main(String[] args) {
50           SwingUtilities.invokeLater(new Runnable() {
51               public void run() {
52                   new Invention2();
53               }
54           });
55       }
56   }
57