-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGraphicPolygon.java
55 lines (48 loc) · 1.42 KB
/
GraphicPolygon.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
/**
* Write a description of class GraphicPolygon here.
*
* @author (your name)
* @version (a version number or a date)
*/
import gpdraw.*;
public class GraphicPolygon extends RegularPolygon
{
private DrawingTool pen = new DrawingTool(new SketchPad(400, 400));
private double xPosition, yPosition;
public GraphicPolygon(int numSides, double sideLength)
{
super(numSides, sideLength);
xPosition = 0;
yPosition = 0;
}
public GraphicPolygon(int numSides, double sideLength, double x, double y)
{
super(numSides, sideLength);
xPosition = x;
yPosition = y;
}
public void moveTo(double x, double y){
pen.up();
pen.move(x,y);
pen.down();
}
public void draw(){
moveTo(xPosition, yPosition);
double numSide = super.getNumSide();
double sideLen = super.getSideLength();
double radius = super.getr();
//double vertAng = super.vertexAngle();
double vertAng = 360/numSide;
drawPoly(numSide, sideLen, vertAng);
}
private void drawPoly(double level, double length, double vertex){
if(level < 1){
pen.forward(length);
}
else{
pen.forward(length);
pen.turnLeft(vertex);
drawPoly(level - 1, length, vertex);
}
}
}