Stella.java
1    package npw;
2    
3    import painter.SPainter;
4    import shapes.SSquare;
5    
6    import javax.swing.*;
7    import java.awt.*;
8    import java.util.Random;
9    import java.util.Scanner;
10   
11   public class Stella {
12       public static void main(String[] args) {
13           String nss = JOptionPane.showInputDialog(null,  "Number of squares?");
14           Scanner scanner = new Scanner(nss);
15           double number = scanner.nextInt();
16           SPainter miro = new SPainter("Stella squares", 800, 800);
17           Color random1 = randomColor();
18           Color random2 = randomColor();
19           SSquare square = new SSquare(700);
20           double shrinkFactor = 700/(number+1);
21           int i = 1;
22           while (i <= number) {
23               if (i % 2 == 0) {
24                   miro.setColor(random2);
25                } else {
26                   miro.setColor(random1);
27               }
28               miro.paint(new SSquare(700-(shrinkFactor * i)));
29               i = i + 1;
30           }
31       }
32   
33       private static Color randomColor() {
34           Random rgen = new Random();
35           int r = rgen.nextInt(256);
36           int g = rgen.nextInt(256);
37           int b = rgen.nextInt(256);
38           return new Color(r, b, g);
39       }
40   
41       private static void paintOneSquare(SPainter miro, SSquare square) {
42           miro.setColor(Color.RED);
43           miro.paint(square);
44          // squared.shrink(70);
45           SSquare squared2 = new SSquare(630);
46           miro.setColor(Color.BLUE);
47           miro.paint(squared2);
48       }
49   }
50