Bangle.setLCDMode(); // use normal display mode
g.clear();
/**** HSVtoRGB ****/
// see https://en.wikipedia.org/wiki/HSL_and_HSV#HSV_to_RGB
function HSVtoRGB (h, s, v) {
let c = v*s;
let k = h/60;
let x = c*(1 - Math.abs(k%2 - 1));
let r, g, b;
switch (true) {
case (k >=0) && (k <= 1): r = c; g = x; b = 0; break;
case (k > 1) && (k <= 2): r = x; g = c; b = 0; break;
case (k > 2) && (k <= 3): r = 0; g = c; b = x; break;
case (k > 3) && (k <= 4): r = 0; g = x; b = c; break;
case (k > 4) && (k <= 5): r = x; g = 0; b = c; break;
case (k > 5) && (k <= 6): r = c; g = 0; b = x; break;
}
let m = v-c;
return [
Math.round(255*(r+m)), Math.round(255*(g+m)), Math.round(255*(b+m))
];
}
/**** Rad2Deg ****/
function Rad2Deg (AngleInRad) {
let AngleInDeg = (180*AngleInRad/Math.PI) % 360;
return (AngleInDeg < 0 ? 360+AngleInDeg : AngleInDeg);
}
/**** draw color disc ****/
const Width = g.getWidth(), CenterX = Width/2;
const Height = g.getHeight(), CenterY = Height/2;
const Radius = Math.min(CenterX,CenterY);
const RadiusSquared = Radius*Radius;
const Saturation = 1.0;
for (let yOffset = -Radius; yOffset <= Radius; yOffset++) {
for (let xOffset = -Radius; xOffset <= Radius; xOffset++) {
let OffsetSquared = xOffset*xOffset + yOffset*yOffset;
if (OffsetSquared <= RadiusSquared) {
let Hue = Rad2Deg(Math.atan2(yOffset,xOffset));
let Value = Math.sqrt(OffsetSquared)/Radius;
let RGB = HSVtoRGB(Hue, Saturation, Value);
g.setColor(RGB[0]/255,RGB[1]/255,RGB[2]/255);
g.setPixel(CenterX+xOffset,CenterY+yOffset);
}
}
}