Last active
January 21, 2020 19:36
-
-
Save abhigkar/c63a9d49a09847144666ea8b0a6a2fd5 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
Bangle.setLCDMode(); | |
g.clear(); | |
function hex(c) { | |
var s = "0123456789abcdef"; | |
var i = parseInt (c); | |
if (i == 0 || isNaN (c)) | |
return "00"; | |
i = Math.round (Math.min (Math.max (0, i), 255)); | |
return s.charAt ((i - i % 16) / 16) + s.charAt (i % 16); | |
} | |
function convertToHex (rgb) { | |
return hex(rgb[0]) + hex(rgb[1]) + hex(rgb[2]); | |
} | |
function trim (s) { return (s.charAt(0) == '#') ? s.substring(1, 7) : s;} | |
function convertToRGB (hex) { | |
var color = []; | |
color[0] = parseInt ((trim(hex)).substring (0, 2), 16); | |
color[1] = parseInt ((trim(hex)).substring (2, 4), 16); | |
color[2] = parseInt ((trim(hex)).substring (4, 6), 16); | |
return color; | |
} | |
function generateColor(colorStart,colorEnd,colorCount){ | |
var start = convertToRGB (colorStart); | |
var end = convertToRGB (colorEnd); | |
var len = colorCount; | |
var alpha = 0.0; | |
var saida = []; | |
for (i = 0; i < len; i++) { | |
var c = []; | |
alpha += (1.0/len); | |
c[0] = Math.round(start[0] * alpha + (1 - alpha) * end[0]); | |
c[1] = Math.round(start[1] * alpha + (1 - alpha) * end[1]); | |
c[2] = Math.round(start[2] * alpha + (1 - alpha) * end[2]); | |
saida.push(c); | |
} | |
return saida; | |
} | |
const Width = g.getWidth(), CenterX = Math.floor(Width)/2; | |
const Height = g.getHeight(), CenterY = Math.floor(Height)/2; | |
let Radius = Math.min(CenterX,CenterY), RadiusSquared = Radius*Radius; | |
var tmp = generateColor('#ff0ff0','#ff0f67',Radius); | |
print(convertToHex(tmp[0])); | |
for(let i=0;i< tmp.length; i++){ | |
g.setColor('#'+convertToHex(tmp[i])); | |
g.fillCircle(CenterX,CenterY,Radius); | |
Radius = Radius -1; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment