/home/evankemp/NetBeansProjects/CS1/src/npw/Stella.java |
1
2
3
4 package npw;
5
6 import java.awt.Color;
7 import java.util.Scanner;
8 import javax.swing.JOptionPane;
9 import painter.SPainter;
10 import shapes.SSquare;
11
12
13
14 @author
15
16 public class Stella {
17
18
19 @param args
20
21 public static void main(String[] args) {
22 double squareSide = 700;
23 Color color1 = getColor();
24 Color color2 = getColor();
25 int concentricNr = getNumber("Number of concentric squares");
26 SSquare square = new SSquare(squareSide);
27
28 SPainter me = new SPainter("Stella", 800, 800);
29 paintTheImage(square, color1, color2, concentricNr, me);
30 }
31
32 private static Color getColor() {
33 int rv = (int) (Math.random() * 256);
34 int gv = (int) (Math.random() * 256);
35 int bv = (int) (Math.random() * 256);
36 return new Color(rv, gv, bv);
37 }
38
39 private static int getNumber(String prompt) {
40 String nss = JOptionPane.showInputDialog(null, prompt + "?");
41 Scanner scanner = new Scanner(nss);
42 return scanner.nextInt();
43 }
44
45 private static void paintTheImage(SSquare square, Color color1, Color color2, int concentricNr, SPainter me) {
46 double shrinkBy = square.side() / concentricNr;
47 int i = 1;
48 while (i <= concentricNr) {
49 if (i % 2 == 0) {
50 me.setColor(color1);
51 } else {
52 me.setColor(color2);
53 }
54 me.paint(square);
55 square.shrink(shrinkBy);
56 i = i + 1;
57 }
58 }
59
60 }
61