Invention1.java
1    /* 
2    *Creating a spiral in a square with inputs of the radius and the color 
3     */
4    package npw;
5    
6    import shapes.SCircle;
7    import shapes.SSquare;
8    import painter.SPainter;
9    import javax.swing.*;
10   import java.awt.*;
11   import java.util.Scanner;
12   
13   public class Invention1 {
14   
15       //setting the parameters for the code
16       private void paintTheImage() {
17           int radius = getNumber("Radius");
18           String color = getColor("Color");
19           SCircle circle = new SCircle(radius);
20           SSquare square = circle.circumscribingSquare();
21           SPainter painter = new SPainter("The Inventor", (int) circle.diameter(), (int) circle.diameter());
22           painter.setBrushWidth(1/3);
23   
24          //creates the color options for the image
25           if (color.equals("pink")) {
26               painter.setColor(Color.PINK);
27           } else if (color.equals("green")) {
28               painter.setColor(Color.GREEN);
29           } else if (color.equals("cyan")) {
30               painter.setColor(Color.CYAN);
31           }else if (color.equalsIgnoreCase("black")) {
32               painter.setColor(Color.BLACK);
33           }
34   
35           //Draws the spiral in a square
36           double min = 0;
37           while (square.side() > min) {
38               painter.draw(square);
39               square.resetSide((int) (square.side() - 1));
40               painter.tl(0.5);
41           }
42          // painter.draw(square);
43          // painter.draw(circle);
44   
45       }
46   /* 
47   *Used to retrieve the information needed to construct the image 
48   * The infrastructure 
49    */
50       private String getColor(String color) {
51           String nss = JOptionPane.showInputDialog(null,color+1);
52           Scanner scanner = new Scanner(nss);
53           return scanner.next();
54       }
55   
56       private int getNumber(String circle_radius) {
57           String nss = JOptionPane.showInputDialog(null,circle_radius+1);
58           Scanner scanner = new Scanner(nss);
59           return scanner.nextInt();
60       }
61   
62       public Invention1() {
63           paintTheImage();
64       }
65   
66       public static void main(String[] args) {
67           SwingUtilities.invokeLater(new Runnable() {
68               @Override
69               public void run() {
70                   new Invention1();
71               }
72           });
73       }
74   }