forked from espruino/BangleApps
-
Notifications
You must be signed in to change notification settings - Fork 0
/
graphics_utils.js
35 lines (32 loc) · 1018 Bytes
/
graphics_utils.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
// draw an arc between radii minR and maxR, and between angles minAngle and maxAngle centered at X,Y. All angles are radians.
exports.fillArc = function(graphics, X, Y, minR, maxR, minAngle, maxAngle, stepAngle) {
var step = stepAngle || 0.21;
var angle = minAngle;
var inside = [];
var outside = [];
var c, s;
while (angle < maxAngle) {
c = Math.cos(angle);
s = Math.sin(angle);
inside.push(X+c*minR); // x
inside.push(Y+s*minR); // y
// outside coordinates are built up in reverse order
outside.unshift(Y+s*maxR); // y
outside.unshift(X+c*maxR); // x
angle += step;
}
c = Math.cos(maxAngle);
s = Math.sin(maxAngle);
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 * radians;
}