/home/ffrigin/NetBeansProjects/CS1/src/npw/Stella.java
 1 /* Program to paint concentric squares in alternating colors from user input.
 2  */
 3 package npw;
 4 
 5 import java.awt.Color;
 6 import java.util.Scanner;
 7 import javax.swing.JOptionPane;
 8 import painter.SPainter;
 9 import shapes.SSquare;
10 
11 /**
12  *
13  * @author ffrigin
14  */
15 public class Stella {
16 
17     /**
18      * @param args the command line arguments
19      */
20     public static void main(String[] args) {
21 
22         //Crate painter/square
23         int size = 800;
24         SPainter paint = new SPainter("Stella", size, size);
25         size = (size - 100);
26         SSquare square = new SSquare(size);
27 
28         //Number to shrink sqaures 
29         double decrement = getInput(size);
30 
31         //Create 2 random colros
32         Color color1 = randomColor();
33         Color color2 = randomColor();
34 
35         //paint the image
36         paintTheImage(square, paint, color1, color2, decrement);
37     }
38 
39     private static double getInput(int size) {
40         String input = "Number of Squares: ";
41         String nss = JOptionPane.showInputDialog(null, input);
42         Scanner scanner = new Scanner(nss);
43         int numSquares = scanner.nextInt();
44         double decrement = (double) size / (double) numSquares;
45         return decrement;
46     }
47 
48     private static Color randomColor() {
49         int rv = (int) (Math.random() * 256);
50         int gv = (int) (Math.random() * 256);
51         int bv = (int) (Math.random() * 256);
52         return new Color(rv, gv, bv);
53     }
54 
55     private static void paintTheImage(SSquare square, SPainter paint, Color color1, Color color2, double decrement) {
56         int i = 1;
57         while (square.side() > 0) {
58             if (i % 3 == 0) {
59                 paint.setColor(color1);
60             } else {
61                 paint.setColor(color2);
62             }
63             paint.paint(square);
64             square.shrink(decrement);
65             i = i + 1;
66         }
67     }
68 
69 }
70