Invention1.java
1    package npw;
2    
3    import painter.SPainter;
4    import shapes.SCircle;
5    import shapes.SSquare;
6    
7    import javax.swing.*;
8    import java.awt.*;
9    import java.util.Random;
10   import java.util.Scanner;
11   
12   public class Invention1 {
13       public static void main(String[] args)
14       {
15           SPainter monet = new SPainter("Invention1", 500, 500);
16           SCircle dot = new SCircle(50);
17           SSquare square = new SSquare(25);
18   
19           paintCircles(monet, dot);
20           paintSquares(monet, square);
21   
22       }
23       private static void paintCircles(SPainter painter, SCircle circle)
24       {
25           int numOfCircles = 4;
26           int i = 1;
27           painter.mlt(150);
28           while (i <= numOfCircles)
29           {
30               if (i % 2 == 0)
31               {
32                   painter.setColor(Color.RED);    //red circles if i is divisible by 2
33               }
34               else
35               {
36                   painter.setColor(Color.BLUE); //blue circles if i is odd
37               }
38               painter.paint(circle);
39               painter.setColor(Color.BLACK);
40               painter.draw(circle);
41               painter.mrt(circle.radius()*2); //moves circles next to each other
42               i++;
43           }
44           painter.center();
45   
46       }
47       private static void paintSquares(SPainter painter, SSquare square)
48       {
49           int numOfSquares = 180;
50           painter.mlt(490);
51           painter.mfd(200);
52           int i = 1;
53           double distance = 0; // keeps track of width moved
54           while(i <= numOfSquares)
55           {
56   
57               if (distance == 500) // if the end of the canvas is reached, painter moves down a row and the distance is reset
58               {
59                   painter.mbk(50);
60                   painter.mlt(500);
61                   distance = 0;
62               }
63   
64               if (i % 2 == 0)
65               {
66                   painter.setColor(Color.GREEN); //green square if i is even
67                   painter.paint(square);
68               }
69               else
70               {
71                   painter.setColor(Color.YELLOW); // yellow square if i is odd
72                   painter.paint(square);
73               }
74               painter.setColor(Color.BLACK);
75               painter.draw(square);
76               painter.mrt(square.side());
77               distance = distance + square.side();
78              // System.out.println(distance);  checked that distance was incrementing
79               i++;
80           }
81           painter.center();
82   
83   
84       }
85   
86   }
87