-
Notifications
You must be signed in to change notification settings - Fork 23
/
polygon.js
44 lines (38 loc) · 1.05 KB
/
polygon.js
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
// Daniel Shiffman
// http://codingtra.in
// Islamic Star Patterns
// Video: https://youtu.be/sJ6pMLp_IaI
// Based on: http://www.cgl.uwaterloo.ca/csk/projects/starpatterns/
function Polygon(sides) {
this.interiorAngle = ((sides - 2) * PI) / sides;
this.vertices = [];
this.edges = [];
this.addVertex = function(x, y) {
var a = createVector(x, y);
var total = this.vertices.length;
if (total > 0) {
var prev = this.vertices[total - 1];
var edge = new Edge(prev, a);
this.edges.push(edge);
}
this.vertices.push(a);
}
this.close = function() {
var total = this.vertices.length;
var last = this.vertices[total - 1];
var first = this.vertices[0];
var edge = new Edge(last, first);
this.edges.push(edge);
}
this.hankin = function() {
for (var i = 0; i < this.edges.length; i++) {
this.edges[i].hankin(this.interiorAngle);
this.edges[i].sidesOfParent=sides;
}
}
this.show = function() {
for (var i = 0; i < this.edges.length; i++) {
this.edges[i].show();
}
}
}