|
Post by NeX on Oct 9, 2015 7:30:06 GMT -8
is it possible to fade from one colour to another?
i want to fade from 0xDDDDDD to OxFFOOOO and back again, but i am not sure of a simple way of doing it without having an array of different colours and cycling through them,
|
|
|
Post by jamesbowman on Oct 9, 2015 12:22:25 GMT -8
Yes, you can use a lerp() function to blend between two colors, controlled by a 'blend factor' 0-255: lerp() is the byte-sized version. mix() does the same thing for RGB values: #include <EEPROM.h> #include <SPI.h> #include <GD2.h>
void setup() { GD.begin(); }
byte lerp(byte f, byte a, byte b) { return ((a * (255U - f)) >> 8) + ((b * f) >> 8); }
uint32_t mix(byte f, // blend factor 0-255 uint32_t a, // color0 uint32_t b) // color1 { uint32_t red = lerp(f, a >> 16, b >> 16); uint32_t grn = lerp(f, a >> 8, b >> 8); uint32_t blu = lerp(f, a, b); return (red << 16) | (grn << 8) | blu; }
void loop() { GD.Clear();
GD.PointSize(16 * 8); GD.Begin(POINTS); for (int i = 0; i < 256; i += 7) { GD.ColorRGB(mix(i, 0xff8000, 0x0000ff)); GD.Vertex2ii(i, i); } GD.swap(); }
|
|
|
Post by NeX on Oct 10, 2015 0:03:42 GMT -8
James you are a straight up genius! thank you so much for all your help!
out of interest what are you using to make that image? do you have some kind of emulator for the gameduino? my sketch is getting so big now that updating to test a little change takes for ever!
|
|
|
Post by jamesbowman on Oct 10, 2015 7:22:58 GMT -8
Lol, glad it worked. The images are screenshots from the FT800 itself, here is how: gameduino2.proboards.com/thread/23/screenshotsYeah, I wish there was an emulator too - Arduino flash loading for sketches above 20K takes a *really* long time.
|
|
|
Post by NeX on Oct 12, 2015 9:02:22 GMT -8
Ah ok, thats an interesting tool actually, shame there is no emulator as my code is actually over 30k now (migrated to a processor with 128k programming space) it takes for ever!
|
|