1 /* 2 * Class to create BalloonPerson Objects based off of 3 * - Name 4 * - Age 5 * - Height 6 */ 7 8 package balloonpeople; 9 10 import painter.SPainter; 11 import shapes.SCircle; 12 13 import java.awt.*; 14 import java.awt.geom.Point2D; 15 16 public class BalloonPerson { 17 18 //establish instance variables 19 private String name; 20 private int age; 21 private int height; 22 private Color color; 23 private int sizeRatio; 24 25 //establish constructor 26 public BalloonPerson(String name, int age, int height) { 27 this.name = name; 28 this.age = age; 29 this.height = height; 30 this.color = randomColor(); 31 this.sizeRatio = sizeRatio; 32 } 33 //toString method 34 public String toString() { 35 String representation = name + ": " + age + "," + height ; 36 return representation; 37 } 38 //basic returns 39 public String getName() { return name; } 40 public int getAge() { return age; } 41 public int getHeight(){ return height; } 42 43 //paint method 44 public void paint(SPainter painter) { 45 //establish some basics 46 painter.setColor(color); 47 Point2D.Double home = painter.position(); 48 SCircle circle = new SCircle(3); 49 sizeRatio = 5; 50 //paint the person 51 paintTorso(painter,circle,home,sizeRatio); 52 paintWaveLines(painter,circle,home,sizeRatio); 53 paintLeftArm(painter,circle,home,sizeRatio); 54 paintRightArm(painter,circle,home,sizeRatio); 55 paintLeftLeg(painter,circle,home,sizeRatio); 56 paintRightLeg(painter,circle,home,sizeRatio); 57 paintHead(painter,circle,home,sizeRatio); 58 } 59 60 //all painting methods to create the paint() method 61 private void paintWaveLines(SPainter painter, SCircle circle, Point2D.Double home, int sizeRatio) { 62 //move into position 63 painter.mfd(sizeRatio * (5/16.0) * height); 64 double topLength = sizeRatio * (1/5.0) * height; 65 painter.setHeading(290); 66 painter.mfd(topLength); 67 painter.setHeading(350); 68 painter.mfd(topLength); 69 Point2D.Double waveCenter = painter.position(); 70 //paint lines 71 SCircle wave = new SCircle(6*sizeRatio); 72 for(int i = 0; i <= 3; i = i + 1) { 73 painter.paint(wave); 74 wave.shrink(0.6*sizeRatio); 75 if(painter.paintBrushColor() == color) { 76 painter.setColor(Color.WHITE); 77 } else { 78 painter.setColor(color); 79 } 80 } 81 //erase top section 82 painter.setColor(Color.WHITE); 83 for(int i = 1; i <= 6*sizeRatio; i = i + 1){ 84 painter.paint(circle); 85 painter.mfd(1); 86 } 87 //reset 88 painter.ta(); painter.moveTo(waveCenter); 89 int heading = 260; 90 painter.setHeading(heading); 91 //erase bottom section 92 for(int i = 1; i <= 19; i = i+1){ 93 for(int k = 1; k <= 6*sizeRatio; k=k+1) { 94 painter.paint(circle); 95 painter.mfd(1); 96 } 97 painter.moveTo(waveCenter); 98 heading = heading - 10; 99 painter.setHeading(heading); 100 } 101 //reset 102 painter.setColor(color); 103 painter.setHeading(0); 104 painter.moveTo(home); 105 } 106 107 private void paintHead(SPainter painter, SCircle circle, Point2D.Double home, int sizeRatio) { 108 //move and paint 109 SCircle head = new SCircle(sizeRatio * (1.5/16.0)*height); 110 painter.mfd(sizeRatio*(7.5/16.0)*height); 111 painter.paint(head); 112 //reset 113 painter.moveTo(home); 114 } 115 116 private void paintLeftLeg(SPainter painter, SCircle circle, Point2D.Double home, int sizeRatio) { 117 //top part of leg 118 painter.setHeading(196); 119 double topDistance = sizeRatio * (Math.sqrt(53.0)/32.0) * height; 120 for(int i = 0; i <= topDistance; i = i + 1){ 121 painter.paint(circle); 122 painter.mfd(1); 123 } 124 //bottom part of leg 125 painter.setHeading(190); 126 double bottomDistance = sizeRatio * (Math.sqrt(53.0)/32.0) * height; 127 for(int i = 0; i <= bottomDistance; i = i + 1){ 128 painter.paint(circle); 129 painter.mfd(1); 130 } 131 //reset 132 painter.setHeading(0); 133 painter.moveTo(home); 134 135 } 136 137 private void paintRightLeg(SPainter painter, SCircle circle, Point2D.Double home, int sizeRatio) { 138 //top part of leg 139 painter.setHeading(164); 140 double topDistance = sizeRatio * (Math.sqrt(53.0)/32.0) * height; 141 for(int i = 0; i <= topDistance; i = i + 1){ 142 painter.paint(circle); 143 painter.mfd(1); 144 } 145 //bottom part of leg 146 painter.setHeading(170); 147 double bottomDistance = sizeRatio * (Math.sqrt(53.0)/32.0) * height; 148 for(int i = 0; i <= bottomDistance; i = i + 1){ 149 painter.paint(circle); 150 painter.mfd(1); 151 } 152 //reset 153 painter.setHeading(0); 154 painter.moveTo(home); 155 } 156 157 private void paintLeftArm(SPainter painter, SCircle circle, Point2D.Double home, int sizeRatio) { 158 //set position 159 painter.mfd(sizeRatio * (5/16.0) * height); 160 painter.setHeading(290); 161 //closer part of arm 162 double topLength = sizeRatio * (1/5.0) * height; 163 for(int i = 0; i <= topLength; i = i + 1){ 164 painter.paint(circle); 165 painter.mfd(1); 166 } 167 //farther part of arm 168 painter.setHeading(350); 169 for(int i = 0; i <= topLength; i = i + 1){ 170 painter.paint(circle); 171 painter.mfd(1); 172 } 173 //reset 174 painter.setHeading(0); 175 painter.moveTo(home); 176 } 177 178 private void paintRightArm(SPainter painter, SCircle circle, Point2D.Double home, int sizeRatio) { 179 //set position 180 painter.mfd(sizeRatio * (5/16.0) * height); 181 painter.setHeading(150); 182 //closer part of arm 183 double topLength = sizeRatio * (1/5.5) * height; 184 for(int i = 0; i <= topLength; i = i + 1){ 185 painter.paint(circle); 186 painter.mfd(1); 187 } 188 //farther part of arm 189 painter.setHeading(170); 190 for(int i = 0; i <= topLength; i = i + 1){ 191 painter.paint(circle); 192 painter.mfd(1); 193 } 194 //reset 195 painter.setHeading(0); 196 painter.moveTo(home); 197 } 198 199 private void paintTorso(SPainter painter, SCircle circle, Point2D.Double home, int sizeRatio) { 200 //paint 201 double torsoLength = sizeRatio*((6.0/16.0) * height); 202 for(int i = 0; i <= torsoLength+5; i = i + 1){ 203 painter.paint(circle); 204 painter.mfd(1); 205 } 206 //reset 207 painter.moveTo(home); 208 } 209 210 //random color generator 211 private Color randomColor() { 212 int rv = (int)(Math.random()*256); 213 int gv = (int)(Math.random()*256); 214 int bv = (int)(Math.random()*256); 215 return new Color(rv,gv,bv); 216 } 217 }