Invention1.java
1    /* 
2    * This program creates colorful rows of small squares and circles. 
3     */
4    
5    
6    package npw;
7    
8    
9    import painter.SPainter;
10   import shapes.SCircle;
11   import shapes.SSquare;
12   import javax.swing.*;
13   import java.awt.*;
14   
15   
16   public class Invention1 {
17   
18       private void paintTheImage(){
19           SPainter painter = new SPainter("Ivention1", 990, 990);
20           SSquare square = new SSquare(20);
21           SCircle circle = new SCircle(10);
22           int numOfCols = 50;
23           int i = 0;
24           int upB = 480;
25           int leftB = 480;
26           startPoint(painter, upB, leftB);
27           paintAllsquares(painter, square, numOfCols, upB, leftB, i);
28           paintAllcircles(painter, square, circle, numOfCols, upB, leftB, i);
29           //paintRowCircles(painter, circle, square, numOfCols, i );
30           //nextRowC(painter, circle, square, upB, leftB,i);
31   
32   
33   
34   
35   
36       }
37   
38   
39   
40   
41       private void nextRowC(SPainter painter, SCircle circle, SSquare square, int upB, int leftB, int i) {
42           // TODO Auto-generated method stub
43           if ( i%2 == 0 ) {
44               startPoint(painter, upB, leftB);
45               painter.faceNorth();
46               painter.mbk(square.side());
47               painter.tr(90);
48           }else {
49               startPoint(painter, upB, leftB);
50               painter.faceNorth();
51               painter.mbk(square.side()*i);
52               painter.tr(90);
53           }
54   
55   
56   
57   
58       }
59   
60   
61   
62   
63       private void paintRowCircles(SPainter painter, SCircle circle, SSquare square,  int numOfCols, int i) {
64           // TODO Auto-generated method stub
65           while (i < (numOfCols*2)) {
66               painter.mfd(square.side());
67               painter.setColor(color2());
68               painter.paint(circle);
69               painter.mfd(square.side());
70               i++;
71           }
72   
73   
74       }
75   
76   
77   
78   
79       private void paintAllcircles(SPainter painter, SSquare square, SCircle circle, int numOfCols, int upB, int leftB, int i) {
80           // TODO Auto-generated method stub
81           while (i < numOfCols) {
82               paintRowCircles(painter,  circle, square, numOfCols, i );
83               nextRowC(painter, circle, square, upB, leftB, i);
84               i++;
85           }
86       }
87   
88   
89   
90   
91       private void paintAllsquares(SPainter painter, SSquare square, int numOfCols, int upB, int leftB, int i  ) {
92           // TODO Auto-generated method stub
93           while (i < numOfCols) {
94               paintRowSquares(painter, numOfCols, square, i );
95               nextRowS(painter, square, upB, leftB, i);
96               i++;
97           }
98       }
99   
100  
101  
102  
103      private void nextRowS(SPainter painter, SSquare square, int upB, int leftB, int i) {
104          // TODO Auto-generated method stub
105          startPoint(painter, upB, leftB);
106          painter.faceNorth();
107          painter.mbk((square.side()*2)*i);
108          painter.tr(90);
109      }
110  
111  
112  
113  
114      private void paintRowSquares(SPainter painter, int numOfCols, SSquare  square, int i) {
115          // TODO Auto-generated method stub
116  
117          while (i < numOfCols) {
118              painter.setColor(color1());
119              painter.paint(square);
120              painter.mfd(square.side()*2);
121              i++;
122          }
123      }
124  
125  
126  
127  
128      private void startPoint(SPainter painter, int upB, int leftB) {
129          painter.moveToCenter();
130          painter.faceNorth();
131          painter.mfd(upB);
132          painter.tl();
133          painter.mfd(leftB);
134          painter.tr(180);
135          // TODO Auto-generated method stub
136  
137      }
138  
139      private static Color color2() {
140          int r = 135;
141          int g = 206;
142          int b = 250;
143          return new Color(r,g,b);
144      }
145  
146      private static Color color1() {
147          int r = 0;
148          int g = 191;
149          int b = 255;
150          return new Color(r,g,b);
151      }
152  
153  
154  
155  
156      public Invention1() {
157          paintTheImage();
158      }
159  
160      public static void main(String[] args) {
161          SwingUtilities.invokeLater(new Runnable() {
162              public void run() {
163                  new Invention1();
164              }
165          });
166      }
167  }