Skip to content
This repository was archived by the owner on Nov 3, 2020. It is now read-only.

Commit e857489

Browse files
committed
and actually add it
1 parent 64e310a commit e857489

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

heart.js

+25
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,31 @@ heart.graphics = {
6666
heart.ctx.stroke();
6767
},
6868

69+
polygon: function(mode, vertices) {
70+
if(vertices.length === undefined)
71+
vertices = Array.prototype.slice.call(arguments, 1);
72+
73+
if(vertices.length <= 2) return;
74+
75+
if(vertices.length % 2 !== 0) {
76+
throw "heart.graphics.polygon: number of vertices isn't even," +
77+
" meaning you don't have x,y pairs";
78+
}
79+
80+
heart.ctx.beginPath();
81+
heart.ctx.moveTo(vertices[0], vertices[1])
82+
for(var i = 2; i < vertices.length; i += 2) {
83+
heart.ctx.lineTo(vertices[i], vertices[i+1]);
84+
}
85+
86+
if(mode === "fill")
87+
heart.ctx.fill();
88+
else {
89+
heart.ctx.lineTo(vertices[0], vertices[1]); // close the polygon
90+
heart.ctx.stroke();
91+
}
92+
},
93+
6994
print: function(text, x, y) {
7095
heart.ctx.fillText(text, x, y);
7196
},

0 commit comments

Comments
 (0)