1 /* 2 * This program fills the screen with alternating rows of circles and squares 3 */ 4 5 6 package npw; 7 8 import java.awt.Color; 9 import javax.swing.SwingUtilities; 10 11 import painter.SPainter; 12 import shapes.SSquare; 13 import shapes.SCircle; 14 15 public class Invention1 { 16 17 private void paintTheImage(){ 18 // Dimensional Variables 19 double scaling = 6.0; 20 int width = 600; 21 int height = 600; 22 double radius = (width / scaling) / 2.0; 23 double side = width / scaling; 24 25 // Object Initialization 26 SCircle circle = new SCircle(radius); 27 SSquare square = new SSquare(side); 28 SPainter klee = new SPainter("Invention 1",width ,height); 29 klee.setColor(Color.green); 30 31 // Repositions Painter 32 klee.mlt((klee.canvasWidth() / 2.0) - (side / 2.0)); 33 klee.mfd((klee.canvasHeight() / 2.0) - (side / 2.0)); 34 35 36 // Proceeds to Paint Pattern 37 paintPattern(scaling, circle, square, klee); 38 } 39 40 41 private void paintPattern(double scaling, SCircle circle, SSquare square, SPainter klee){ 42 43 // Paints Alternating Rows of Squares and Circles 44 int i = 0; 45 while(i < scaling){ 46 if(i % 2 == 0) { 47 paintRowSquare(scaling, circle, square, klee); 48 }else{ 49 paintRowCircle(scaling, circle, square, klee); 50 } 51 52 // Invariance of Painter Position 53 klee.mbk(square.side()); 54 klee.mlt(scaling * square.side()); 55 i++; 56 } 57 } 58 59 // Paints Row Starting with Square 60 private void paintRowSquare(double scaling, SCircle circle, SSquare square, SPainter klee){ 61 for(int i = 0; i < scaling; i++){ 62 if(i % 2 == 0) { 63 klee.paint(square); 64 }else{ 65 klee.paint(circle); 66 } 67 klee.mrt(square.side()); 68 } 69 } 70 71 // Paints Row Starting with Circle 72 private void paintRowCircle(double scaling, SCircle circle, SSquare square, SPainter klee){ 73 for(int i = 0; i < scaling; i++){ 74 if(i % 2 == 0) { 75 klee.paint(circle); 76 }else{ 77 klee.paint(square); 78 } 79 klee.mrt(square.side()); 80 } 81 } 82 83 // REQUIRED INFRASTRUCTURE // 84 public Invention1(){ 85 paintTheImage(); 86 } 87 88 public static void main(String[] args){ 89 SwingUtilities.invokeLater(new Runnable() { 90 @Override 91 public void run() { 92 new Invention1(); 93 } 94 }); 95 } 96 } 97