Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Andy Zhang, 2 period , 12/16/15
- import gpdraw.*;
- public class GraphicPolygon extends RegularPolygon
- {
- // instance variables - replace the example below with your own
- private DrawingTool pen = new DrawingTool(new SketchPad(400, 400));
- private double xPosition, yPosition;
- private double x, y;
- private double sideLength;
- private int numSides;
- private double angle;
- public GraphicPolygon(int numSides, double sideLength)
- {
- // initialise instance variables
- super(numSides, sideLength);
- xPosition = yPosition = 0;
- }
- public GraphicPolygon(int numSides, double sideLength, double xPostion, double yPostion)
- {
- //constructor
- super(numSides, sideLength);
- xPosition = x;
- yPosition = y;
- }
- public void moveTo(double x, double y)
- {
- pen.move(x ,y);
- }
- public void draw()
- {
- pen.up();
- pen.move(xPosition, yPosition);
- pen.move(getr());
- pen.turnRight(90);
- pen.down();
- pen.move(getSideLength()/2);
- for(int x = 1; x < getNumside(); x++)
- {
- pen.turnRight(180 - vertexAngle());
- pen.forward(getSideLength());
- }
- pen.turnRight(180 - vertexAngle());
- pen.forward(getSideLength()/2);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement