Advertisement
gluten_free_feeling

GraphicRectangle

Dec 15th, 2015
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.35 KB | None | 0 0
  1. //Andy Zhang, 2 period , 12/16/15
  2. import gpdraw.*;
  3. public class GraphicPolygon extends RegularPolygon
  4. {
  5. // instance variables - replace the example below with your own
  6. private DrawingTool pen = new DrawingTool(new SketchPad(400, 400));
  7. private double xPosition, yPosition;
  8. private double x, y;
  9. private double sideLength;
  10. private int numSides;
  11. private double angle;
  12. public GraphicPolygon(int numSides, double sideLength)
  13. {
  14. // initialise instance variables
  15. super(numSides, sideLength);
  16. xPosition = yPosition = 0;
  17. }
  18. public GraphicPolygon(int numSides, double sideLength, double xPostion, double yPostion)
  19. {
  20. //constructor
  21. super(numSides, sideLength);
  22. xPosition = x;
  23. yPosition = y;
  24. }
  25.  
  26. public void moveTo(double x, double y)
  27. {
  28. pen.move(x ,y);
  29. }
  30. public void draw()
  31. {
  32. pen.up();
  33. pen.move(xPosition, yPosition);
  34. pen.move(getr());
  35. pen.turnRight(90);
  36. pen.down();
  37. pen.move(getSideLength()/2);
  38.  
  39. for(int x = 1; x < getNumside(); x++)
  40. {
  41. pen.turnRight(180 - vertexAngle());
  42. pen.forward(getSideLength());
  43. }
  44.  
  45. pen.turnRight(180 - vertexAngle());
  46. pen.forward(getSideLength()/2);
  47. }
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement