1 package npw; 2 3 import painter.SPainter; 4 import shapes.SRectangle; 5 6 import javax.swing.*; 7 import java.awt.*; 8 9 public class Invention1 { 10 11 private void paintTheImage(){ 12 //Declaring the variables 13 int canvasDim = 1000; 14 int rectHeight = canvasDim*2; 15 int rectWidth = 50; 16 17 //Constructing the canvas and Object 18 SPainter painter = new SPainter("Deterministic Invention",canvasDim,canvasDim); 19 SRectangle rectangle = new SRectangle(rectHeight, rectWidth); 20 21 //moving the painter to the upper right corner 22 painter.mfd(canvasDim/2.0); 23 painter.tl(); 24 painter.mfd(canvasDim/2.0); 25 painter.tl(); 26 painter.setColor(Color.RED); 27 painter.paint(rectangle); 28 // painting the vertical lines 29 int counter = 1; 30 while (counter <= canvasDim/(2.0*rectWidth)){ 31 if(counter % 2 == 0){ 32 painter.setColor(Color.RED); 33 } 34 else { 35 painter.setColor(Color.ORANGE); 36 } 37 painter.mlt(2*rectWidth); 38 painter.paint(rectangle); 39 counter = counter + 1; 40 } 41 painter.moveToCenter(); 42 painter.tl(); 43 painter.mlt(canvasDim/2.0); 44 painter.paint(rectangle); 45 // painting the horizontal lines 46 int i = 1; 47 while (i<=canvasDim/(2.0*rectWidth)){ 48 if(counter % 2 == 0){ 49 painter.setColor(Color.ORANGE); 50 } 51 else { 52 painter.setColor(Color.RED); 53 } 54 painter.mrt(2*rectWidth); 55 painter.paint(rectangle); 56 i = i+1; 57 } 58 59 } 60 public Invention1(){ 61 paintTheImage(); 62 } 63 public static void main(String[] args) { 64 SwingUtilities.invokeLater(new Runnable() { 65 public void run() { 66 new Invention1(); 67 } 68 }); 69 } 70 } 71