Farbverlauf zwischen zwei COLORREFS?
-
Moin, moin,
Colorref[0] = Startfarbe z.B. GELB
Colorref[100] = Endfarbe z.B. ROTWie berechne ich die Elemente 1 - 99 als Farbverlauf von GELB nach ROT?
Ideen?
-
Hi,
Mit der WinAPI Funktion
GradientFill(...) (MSDN) kannst du einen vollständigen Farbverlauf zeichnen.Wenns dir aber nur ums berechnen geht...Wo ist das Problem ?
-
Einfach die Farbkomponenten in einem Farbraum (RGB, HSV, CIE-XYZ) linear interpolieren.
-
MichiK schrieb:
Einfach die Farbkomponenten in einem Farbraum (RGB, HSV, CIE-XYZ) linear interpolieren.
Ich habs jetzt so gemacht:
static void ColorBell(COLORREF scolor, COLORREF ecolor, struct state *st){ int rDelta; int gDelta; int bDelta; int rShift; int gShift; int bShift; bool rSinus; bool gSinus; bool bSinus; int rVal1 = GetRValue(scolor); int gVal1 = GetGValue(scolor); int bVal1 = GetBValue(scolor); int rVal2 = GetRValue(ecolor); int gVal2 = GetGValue(ecolor); int bVal2 = GetBValue(ecolor); //////////////////////////////////////////////////////////////////////// // RED if (rVal1 < rVal2) { // Traditional bell? rSinus = true; rDelta = rVal2 - rVal1; rShift = rVal1; } else { // Or bottom up? rSinus = false; rDelta = rVal1 - rVal2; rShift = rVal2; } //////////////////////////////////////////////////////////////////////// // GREEN if (gVal1 < gVal2) { gSinus = true; gDelta = gVal2 - gVal1; gShift = gVal1; } else { gSinus = false; gDelta = gVal1 - gVal2; gShift = gVal2; } //////////////////////////////////////////////////////////////////////// // BLUE if (bVal1 < bVal2) { bSinus = true; bDelta = bVal2 - bVal1; bShift = bVal1; } else { bSinus = false; bDelta = bVal1 - bVal2; bShift = bVal2; } //////////////////////////////////////////////////////////////////////// // computing float r, g, b; for (int i=0; i <= st->ncolours; i++) { // RED if (rSinus) r = (rDelta * pow(sin((i*M_PI)/st->ncolours),2)) + rShift; // ok, traditional bell! else r = (rDelta * pow(cos((i*M_PI)/st->ncolours),2)) + rShift; // oh, a top down bell! // GREEN if (gSinus) g = (gDelta * pow(sin((i*M_PI)/st->ncolours),2)) + gShift; else g = (gDelta * pow(cos((i*M_PI)/st->ncolours),2)) + gShift; // BLUE if (bSinus) b = (bDelta * pow(sin((i*M_PI)/st->ncolours),2)) + bShift; else b = (bDelta * pow(cos((i*M_PI)/st->ncolours),2)) + bShift; // and out! st->colours[i] = RGB((int)r, (int)g, (int)b); } }Die Struktur "st" enthält unter anderem:
st->colours[] // COLORREF Array
st->ncolours // Anzahl der FarbenDer Verlauf ist jetzt glockenförmig von Quellfarbe zu Zielfarbe und zurück nach Quellfarbe. Sieht gut aus!
Linear wäre sicher einfacher.Wenn jemand Lust hat, kann er ja mal den Code vereinfachen - ich stecke noch in den Anfängen von C-Programmierung und ich stehe auf AHA-Erlebnisse.
