Bangle.js: fills the display with a color stripe
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// fills the display of a Bangle.js with a color stripe | |
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)) | |
]; | |
} | |
/**** draw color stripe ****/ | |
const Width = g.getWidth(); | |
const Height = g.getHeight(); | |
const Saturation = 1.0; | |
const Value = 1.0; | |
for (let x = 0; x < Width; x++) { | |
let Hue = Math.round(360*x/Width); | |
let RGB = HSVtoRGB(Hue, Saturation, Value); | |
g.setColor(RGB[0]/255,RGB[1]/255,RGB[2]/255); | |
g.drawLine(x,0, x,Height-1); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment