More-circle-methods.txt (1930B)
1 2 // Comment: Move the circle a few pixels to the right. 3 public void moveRight(){ 4 moveHorizontal(20); 5 } 6 7 // Comment: Move the circle a few pixels to the left. 8 public void moveLeft(){ 9 moveHorizontal(-20); 10 } 11 12 // Comment: Move the circle a few pixels up. 13 public void moveUp(){ 14 moveVertical(-20); 15 } 16 17 // Comment:Move the circle a few pixels down. 18 public void moveDown() 19 { 20 moveVertical(20); 21 } 22 23 // Comment: Move the circle horizontally by 'distance' pixels. 24 public void moveHorizontal(int distance){ 25 erase(); 26 xPosition += distance; 27 draw(); 28 } 29 30 // Comment: Move the circle vertically by 'distance' pixels. 31 public void moveVertical(int distance){ 32 erase(); 33 yPosition += distance; 34 draw(); 35 } 36 37 // Comment: Slowly move the circle horizontally by 'distance' pixels. 38 public void slowMoveHorizontal(int distance){ 39 int delta; 40 41 if(distance < 0){ 42 delta = -1; 43 distance = -distance; 44 } 45 else{ 46 delta = 1; 47 } 48 49 for(int i = 0; i < distance; i++){ 50 xPosition += delta; 51 draw(); 52 } 53 } 54 55 // Comment:Slowly move the circle vertically by 'distance' pixels. 56 public void slowMoveVertical(int distance){ 57 int delta; 58 59 if(distance < 0){ 60 delta = -1; 61 distance = -distance; 62 } 63 else{ 64 delta = 1; 65 } 66 67 for(int i = 0; i < distance; i++){ 68 yPosition += delta; 69 draw(); 70 } 71 } 72 73 // Comment:Get the current diameter size 74 public int getSize(){ 75 return diameter; 76 } 77 78 // Comment:Get the current color 79 public String getColor(){ 80 return color.toString(); 81 } 82 83 // Comment: Get current X coordiate in the canvas 84 public int getXCoord(){ 85 return xPosition; 86 } 87 88 // Comment:Get current Y coordiate in the canvas 89 public int getYCoord(){ 90 return yPosition; 91 } 92