Rysowanie wielokąta regularnego
Klasa używa funkcji figures.js
Listing
var cv = document.getElementById("canvas"); var ctx = cv.getContext("2d"); var polygon = new RegPolygon (new Point(150,150), 5, 100); polygon.fillStyle = "red"; polygon.strokeStyle = "blue"; polygon.fill = true; polygon.stroke = true; polygon.lineWidth = 3; polygon.draw(ctx); var area = polygon.area(); ctx.fillText("area: "+area, 20, 300); var bary = polygon.barycenter(); bary.shape="cross"; bary.strokeStyle="black"; bary.diam=8; bary.stroke=true; bary.draw(ctx); ctx.fillText("bary: "+bary.x + " " + bary.y, 20, 320); var peri = polygon.perimeter(); ctx.fillText("peri: "+peri, 20, 340); var polygon1 = polygon.deepclone(); ctx.translate(200,0); polygon1.draw(ctx);