From d8543f4d41cbc991aa72b27a3430e19a0f240da1 Mon Sep 17 00:00:00 2001 From: Martin Boonk Date: Mon, 19 Dec 2022 12:52:33 +0100 Subject: [PATCH] choozi - Fix library not working standalone --- apps/choozi/app.js | 6 +++--- modules/graphics_utils.js | 32 ++++++++++++++++++++------------ 2 files changed, 23 insertions(+), 15 deletions(-) diff --git a/apps/choozi/app.js b/apps/choozi/app.js index 577ef606a..517628470 100644 --- a/apps/choozi/app.js +++ b/apps/choozi/app.js @@ -58,7 +58,7 @@ function drawPerimeter() { for (var i = 0; i < N; i++) { g.setColor(colours[i%colours.length]); var minAngle = (i/N)*radians; - GU.drawArc(g, perimMin,perimMax,minAngle,minAngle+arclen); + GU.drawArc(g, perimMin,perimMax,minAngle,minAngle+arclen, centreX, centreY, stepAngle); } } @@ -115,10 +115,10 @@ function choose() { animateChoice((minAngle+maxAngle)/2); g.setColor(colours[chosen%colours.length]); for (var i = segmentMax-segmentStep; i >= 0; i -= segmentStep){ - GU.drawArc(g, i, perimMax, minAngle, maxAngle); + GU.drawArc(g, i, perimMax, minAngle, maxAngle, centreX, centreY, stepAngle); if (process.env.HWVERSION == 2) g.flip(); } - GU.drawArc(g, 0, perimMax, minAngle, maxAngle); + GU.drawArc(g, 0, perimMax, minAngle, maxAngle, centreX, centreY, stepAngle); for (var r = 1; r < segmentMax; r += circleStep){ g.fillCircle(centreX,centreY,r); if (process.env.HWVERSION == 2) g.flip(); diff --git a/modules/graphics_utils.js b/modules/graphics_utils.js index 8e4b893ba..925502afb 100644 --- a/modules/graphics_utils.js +++ b/modules/graphics_utils.js @@ -1,6 +1,6 @@ -// draw an arc between radii minR and maxR, and between angles minAngle and maxAngle -exports.drawArc = function(graphics, minR, maxR, minAngle, maxAngle) { - var step = stepAngle; +// draw an arc between radii minR and maxR, and between angles minAngle and maxAngle, all angles are radians +exports.drawArc = function(graphics, minR, maxR, minAngle, maxAngle, X, Y, stepAngle) { + var step = stepAngle || 0.2; var angle = minAngle; var inside = []; var outside = []; @@ -8,20 +8,28 @@ exports.drawArc = function(graphics, minR, maxR, minAngle, maxAngle) { while (angle < maxAngle) { c = Math.cos(angle); s = Math.sin(angle); - inside.push(centreX+c*minR); // x - inside.push(centreY+s*minR); // y + inside.push(X+c*minR); // x + inside.push(Y+s*minR); // y // outside coordinates are built up in reverse order - outside.unshift(centreY+s*maxR); // y - outside.unshift(centreX+c*maxR); // x + outside.unshift(Y+s*maxR); // y + outside.unshift(X+c*maxR); // x angle += step; } c = Math.cos(maxAngle); s = Math.sin(maxAngle); - inside.push(centreX+c*minR); - inside.push(centreY+s*minR); - outside.unshift(centreY+s*maxR); - outside.unshift(centreX+c*maxR); - + inside.push(X+c*minR); + inside.push(Y+s*minR); + outside.unshift(Y+s*maxR); + outside.unshift(X+c*maxR); + var vertices = inside.concat(outside); graphics.fillPoly(vertices, true); +} + +exports.degreesToRadians = function(degrees){ + return Math.PI/180 * degrees; +} + +exports.radiansToDegrees = function(radians){ + return 180/Math.PI * degrees; } \ No newline at end of file