How to make gradient color on fonts and make some transparency with color so that you can see thru that color behind? Any examples? Or is it like a transparent font and a background picture made gradient and displaying that?
How to make gradient color on fonts and make some transparency with color so that you can see thru that color behind? Any examples? Or is it like a transparent font and a background picture made gradient and displaying that?
I've been researching color spaces and testing performance. HSV is nice for transitions from Red to Green since it passes through yellow. I tried implementing it, but it requires converting to and from…
You don't color the custom font. Here's something Hermo wrote sometime back, and look at how he does NoFrills
https://developer.garmin.com/connect-iq/connect-iq-faq/how-do-i-use-custom-fonts/…
For anyone wondering how to draw color gradients, here's some code :)
The result isn't entirely smooth, but using a stripy or outline font can hide the steps a bit. There are probably better ways to…
It's really not that complex. Hermo posted the basics in the link I provided. BTW, Nofrills came out in 2015 and this technique has been used by many since then!
I've seen and used that example :) The gradient and having it nice and smooth is the tricky part and what I'm interested in.
Make sure you check on real devices and not the sim, On a real device, pixels are much smaller than you see in the sim, and the colors might be a bit different based on your screen settings and are very different on MIP devices.
For anyone wondering how to draw color gradients, here's some code :)
The result isn't entirely smooth, but using a stripy or outline font can hide the steps a bit. There are probably better ways to do this, and if you know how to please share :)
for (var i=1; i<=textH; i++) {
var color = lerpColor(color1, color2, i/textH.toFloat());
//var color = interpolateColorsCompact(color1, color2, i/textH.toFloat());
dc.setColor(color, 0);
dc.drawLine(0, i + 208-textH/2, 416, i+208-textH/2);
}
Both functions give basically the same result visually and according to the sim the performance isn't drastically different. You can probably optimize it by storing the calculated values, if memory isn't a concern.
// www.alanzucconi.com/.../
// stackoverflow.com/.../whats-the-most-effective-way-to-interpolate-between-two-colors-pseudocode-and
function interpolateColorsCompact(a, b, lerp) {
var mask1 = 0xff00ff;
var mask2 = 0x00ff00;
var f2 = (256 * lerp).toNumber();
var f1 = 256 - f2;
return ((((( a & mask1 ) * f1 ) + ( ( b & mask1 ) * f2 )) >> 8 ) & mask1 ) | ((((( a & mask2 ) * f1 ) + ( ( b & mask2 ) * f2 )) >> 8 ) & mask2 );
}
// gist.github.com/.../b0cce2261f1382159b507dd492e1ceef
function lerpColor (pFrom, pTo, pRatio as Float) {
var ar = (pFrom & 0xFF0000) >> 16;
var ag = (pFrom & 0x00FF00) >> 8;
var ab = (pFrom & 0x0000FF);
var br = (pTo & 0xFF0000) >> 16;
var bg = (pTo & 0x00FF00) >> 8;
var bb = (pTo & 0x0000FF);
var rr = (ar + pRatio * (br - ar)).toNumber();
var rg = (ag + pRatio * (bg - ag)).toNumber();
var rb = (ab + pRatio * (bb - ab)).toNumber();
//System.println("rr=" + rr +" rg=" + rg + " rb=" + rb);
return (rr << 16) + (rg << 8) + (rb | 0);
}
With this you can achieve some nice visual effects. Other ideas are a battery icon that changes from green to red based on %, progress bars that have the same effect, starting with one color and ending in another, multiple gradient stops, etc. Hopefully Garmin will build functionality like this into the sdk at some point. You can actually achieve it with a svg, but it would be static.
THANK YOU very much for the example code :)
Glad to share and help :)
Technically the current generation of Garmin Amoled screens are 16 bit RGB565 which supports a maximum of 65,536 colors, compared to the 16.7 million colors available in RGB888. I don't think it really matters for the algorithm. I'm assuming that the device will display the nearest matching color.
I've been researching color spaces and testing performance. HSV is nice for transitions from Red to Green since it passes through yellow. I tried implementing it, but it requires converting to and from HSV colorspace which isn't optimal for performance. So I decided to have a method that accepts an optional middle color to simulate the affect. The code is available here: MrJacquers/GarminBlendWatchFace: Garmin watchface example that shows color interpolation. (github.com)
THANK YOU yet again for sharing the code, and while on the topic - your example looks beautiful.