1 package npw; 2 3 // Imports 4 import java.awt.Color; 5 import javax.swing.SwingUtilities; 6 import painter.SPainter; 7 import shapes.SCircle; 8 9 public class Dots { 10 11 // Paints the Image // 12 private void paintTheImage(){ 13 // Creates painter 14 SPainter painter = new SPainter("Y",600,600); 15 16 // Creates dot 17 SCircle dot = new SCircle(50); 18 19 // Function calls to paint regions of dots 20 paintBottom(painter, dot); 21 paintLeft(painter, dot); 22 paintRight(painter, dot); 23 24 } 25 26 // Paints the bottom dots 27 private void paintBottom(SPainter painter, SCircle dot) { 28 // Sets color to blue 29 painter.setColor(Color.BLUE); 30 31 // Moves the painter the length of the radius above the bottom 32 painter.mbk((painter.canvasHeight() / 2.0) - dot.radius()); 33 34 // Paints the dot 35 painter.paint(dot); 36 37 // Moves the painter 1/4 the length of the canvas forward 38 painter.mfd(painter.canvasHeight() / 4.0); 39 40 // Halves the radius of the dot 41 dot.setRadius((int) (dot.radius() / 2)); 42 43 // Paints the dot 44 painter.paint(dot); 45 46 // Sets color to black 47 painter.setColor(Color.BLACK); 48 49 // Moves painter to the center and paints the dot 50 painter.moveToCenter(); 51 painter.paint(dot); 52 53 } 54 55 // Paints the left dots 56 private void paintLeft(SPainter painter, SCircle dot) { 57 // Sets color to green 58 painter.setColor(Color.GREEN); 59 60 // Moves painter the diameter of the dot left and forward 61 painter.mlt(dot.diameter()); 62 painter.mfd(dot.diameter()); 63 64 // Paints the dot 65 painter.paint(dot); 66 67 // Adds 5 to the dot radius 68 dot.setRadius((int) (dot.radius() + 5)); 69 70 // Moves painter the diameter of the dot left and forward 71 painter.mlt(dot.diameter()); 72 painter.mfd(dot.diameter()); 73 74 // Paints the dot 75 painter.paint(dot); 76 77 // Adds 5 to the radius 78 dot.setRadius((int) (dot.radius() + 5)); 79 80 // Moves painter the diameter of the dot left and forward 81 painter.mlt(dot.diameter()); 82 painter.mfd(dot.diameter()); 83 84 // Paints the dot 85 painter.paint(dot); 86 87 // Invariance of painter position and circle radius 88 painter.moveToCenter(); 89 dot.setRadius(25); 90 } 91 92 // Paints the right dots 93 private void paintRight(SPainter painter, SCircle dot) { 94 // Sets color to red 95 painter.setColor(Color.RED); 96 97 // Moves painter the diameter of the dot right and forward 98 painter.mrt(dot.diameter()); 99 painter.mfd(dot.diameter()); 100 101 // Paints the dot 102 painter.paint(dot); 103 104 dot.setRadius((int) (dot.radius() + 5)); 105 106 // Moves painter the diameter of the dot right and forward 107 painter.mrt(dot.diameter()); 108 painter.mfd(dot.diameter()); 109 110 // Paints the dot 111 painter.paint(dot); 112 113 // Adds 5 to the dot radius 114 dot.setRadius((int) (dot.radius() + 5)); 115 116 // Moves painter the diameter of the dot right and forward 117 painter.mrt(dot.diameter()); 118 painter.mfd(dot.diameter()); 119 120 // Paints the dot 121 painter.paint(dot); 122 123 // Invariance of painter position and circle radius 124 painter.moveToCenter(); 125 dot.setRadius(25); 126 } 127 128 // REQUIRED INFRASTRUCTURE // 129 public Dots(){ 130 paintTheImage(); 131 } 132 133 public static void main(String[] args){ 134 SwingUtilities.invokeLater(new Runnable(){ 135 public void run(){ 136 new Dots(); 137 } 138 }); 139 } 140 } 141 142