int wxColour::AllocColour(WXDisplay* display, bool realloc) { if ((m_pixel != -1) && !realloc) return m_pixel; XColor color; color.red = (unsigned short) Red (); color.red |= color.red << 8; color.green = (unsigned short) Green (); color.green |= color.green << 8; color.blue = (unsigned short) Blue (); color.blue |= color.blue << 8; color.flags = DoRed | DoGreen | DoBlue; WXColormap cmap = wxTheApp->GetMainColormap(display); if (!XAllocColor ((Display*) display, (Colormap) cmap, &color)) { m_pixel = wxGetBestMatchingPixel((Display*) display, &color,(Colormap) cmap); return m_pixel; } else { m_pixel = (int) color.pixel; return m_pixel; } }
ElImScroller * PckBitImScroller::Reduc(INT zoom,bool quick) { Reducteur_Im_Compr Red(_pbim,zoom); Red.do_it(Pt2dr(0,0),1.0/zoom,Pt2di(0,0),Red.SzW(),quick); return new PckBitImScroller(VisuStd(),Red.pbim(),sc_im()/zoom); }
LKColor LKColor::MixColors(const LKColor& Color2, double fFact1) const { double fFact2 = 1.0f - fFact1; #ifdef GREYSCALE int Luminosity1 = GetLuminosity(); int Luminosity2 = Color2.GetLuminosity(); int Luminosity = (int) (fFact1 * (double) Luminosity1 + fFact2 * (double) Luminosity2); if (Luminosity > 255) Luminosity = 255; return Color(Luminosity, Alpha()); #else uint8_t red1 = Red(); uint8_t green1 = Green(); uint8_t blue1 = Blue(); uint8_t red2 = Color2.Red(); uint8_t green2 = Color2.Green(); uint8_t blue2 = Color2.Blue(); int red = (int) (fFact1 * (double) red1 + fFact2 * (double) red2); if (red > 255) red = 255; int green = (int) (fFact1 * (double) green1 + fFact2 * (double) green2); if (green > 255) green = 255; int blue = (int) (fFact1 * (double) blue1 + fFact2 * (double) blue2); if (blue > 255) blue = 255; return LKColor((uint8_t) red, (uint8_t) green, (uint8_t) blue); #endif }
// returns the addition of this color with another color Color Color::operator+ (const Color& vRhs) const { double trans=Transparent() > vRhs.Transparent() ? Transparent() : vRhs.Transparent(); return Color(Red()+vRhs.Red(),Green()+vRhs.Green(),Blue()+vRhs.Blue(), trans); }
Color::Color(double vRed, double vGreen, double vBlue, double vTransparent) { Red(vRed); Green(vGreen); Blue(vBlue); Transparent(vTransparent); }
// Update the Fade Pattern void FadeUpdate() { // Calculate linear interpolation between Color1 and Color2 // Optimise order of operations to minimize truncation error uint8_t red = ((Red(Color1) * (TotalSteps - Index)) + (Red(Color2) * Index)) / TotalSteps; uint8_t green = ((Green(Color1) * (TotalSteps - Index)) + (Green(Color2) * Index)) / TotalSteps; uint8_t blue = ((Blue(Color1) * (TotalSteps - Index)) + (Blue(Color2) * Index)) / TotalSteps; uint8_t white = ((White(Color1) * (TotalSteps - Index)) + (White(Color2) * Index)) / TotalSteps; // Serial.print(red); Serial.print(","); // Serial.print(green); Serial.print(","); // Serial.print(blue); Serial.print(","); // Serial.print(white); Serial.println(); ColorSet(Color(red, green, blue, white)); show(); Increment(); }
void PathSpiral(Painter& sw) { sw.Path("M153 334 C153 334 151 334 151 334 C151 339 153 344 156 344 C164 344 171 339 171 334 " "C171 322 164 314 156 314 C142 314 131 322 131 334 C131 350 142 364 156 364 " "C175 364 191 350 191 334 C191 311 175 294 156 294 C131 294 111 311 111 334 " "C111 361 131 384 156 384 C186 384 211 361 211 334 C211 300 186 274 156 274 ") .Stroke(2, Red()); }
/** * Returns the highlighted version of this color. */ constexpr Color Highlight() const { return Color((Red() + 0xff * 3) / 4, (Green() + 0xff * 3) / 4, (Blue() + 0xff * 3) / 4); }
void happy(LedGroup* group) { byte r = Red(currentColor); byte g = Green(currentColor); byte b = Blue(currentColor); Color highColor1 = createColor(r/ 2, g/2, b/2); Color highColor2 = createColor(250, 250, 250); for(int i=0;i<group->selectionLen; i++) { switch(group->pixelState[i]) { case 0: group->targetColors[i] = highColor1; group->pixelState[i]++; break; case 1: updateState(group, i, i); break; case 2: if(i == group->selectionLen - 1 && group->selectionLen < 10) { group->animatingPixel[group->selectionLen] = nextUnselected(group); group->pixelState[group->selectionLen] = 0; group->selectionLen++; } group->targetColors[i] = highColor2; group->pixelState[i]++; break; case 3: updateState(group, i, i); break; case 4: group->targetColors[i] = currentColor; group->pixelState[i]++; break; case 5: updateState(group, i, i); break; default: group->pixelState[i] = 0; group->animatingPixel[i] = nextUnselected(group); if(firstUnselected(group) >= group->length - 1) { group->animation = &flicker; group->selection = &flickerStrategy; group->counter = 0; group->waitFrames = 0; } } } }
void swapCurrentColor() { byte r = Red(currentColor); byte g = Green(currentColor); byte b = Blue(currentColor); currentColor = createColor(b, r,g); Serial.print("color:"); Serial.println(currentColor); }
LKColor LKColor::ContrastTextColor() const { #ifdef GREYSCALE return (GetLuminosity() > 127 ? RGB_BLACK : RGB_WHITE); #else // human eye brightness color factors // Y=0.30 R + 0.59 G + 0.11 B. return ((0.30 * (double) Blue() + 0.59 * (double) Green() + 0.11 * (double) Red() > 127) ? RGB_BLACK : RGB_WHITE); #endif }
double ON_Color::Value() const { // 0.0 to 1.0 0.0 = black, 1.0 = white int r = Red(); int g = Green(); int b = Blue(); int maxrgb = ( r <= g ) ? g : r; if ( maxrgb < b ) maxrgb = b; return (maxrgb/255.0); }
constexpr Color WithAlpha(uint8_t alpha) const { #ifdef GREYSCALE return Color(GetLuminosity(), alpha); #else return Color(Red(), Green(), Blue(), alpha); #endif }
void OnTextPath(Painter& sw) { sw.Text(50, 50, "Hello!", Roman(350)).Stroke(1, Black()); for(int i = 0; i <= 100; i++) { sw.BeginOnPath(i / 100.0); sw.Move(0, -6).Line(6, 0).Line(0, 6).Fill(Red()); sw.End(); } }
/** * Returns the shadowed version of this color. */ constexpr Color Shadow() const { #ifdef GREYSCALE return Color(GetLuminosity() * 15u / 16u); #else return Color(Red() * 15u / 16u, Green() * 15u / 16u, Blue() * 15u / 16u, Alpha()); #endif }
void StateEvaluationTreePanel::drawIndicatorAtArea(wxDC &DC, IndicatorStyle const &Style, wxCoord X, wxCoord Y, wxCoord W, wxCoord H) { auto const Kind = Style.GetKind(); auto const FG = Style.GetForeground(); wxPen const PrevPen = DC.GetPen(); wxBrush const PrevBrush = DC.GetBrush(); switch (Kind) { case IndicatorStyle::EKind::Plain: DC.SetPen(wxPen{FG, Settings.PenWidth}); DC.DrawLine(X, Y+H, X+W, Y+H); break; case IndicatorStyle::EKind::Box: DC.SetPen(wxPen{FG, Settings.PenWidth}); DC.DrawRectangle(X, Y, W, H); break; case IndicatorStyle::EKind::StraightBox: // Many DCs don't support alpha at all, so manually calculate an alpha // against the background colour. auto const BG = PrevBrush.GetColour(); double const Alpha = (double)Style.GetAlpha() / 255; double const OutlineAlpha = (double)Style.GetOutlineAlpha() / 255; DC.SetPen(wxPen{ wxColour(wxColour::AlphaBlend(FG.Red(), BG.Red(), OutlineAlpha), wxColour::AlphaBlend(FG.Green(), BG.Green(), OutlineAlpha), wxColour::AlphaBlend(FG.Blue(), BG.Blue(), OutlineAlpha)), Settings.PenWidth}); DC.SetBrush(wxBrush{ wxColour(wxColour::AlphaBlend(FG.Red(), BG.Red(), Alpha), wxColour::AlphaBlend(FG.Green(), BG.Green(), Alpha), wxColour::AlphaBlend(FG.Blue(), BG.Blue(), Alpha))}); DC.DrawRectangle(X, Y, W, H); break; } DC.SetPen(PrevPen); DC.SetBrush(PrevBrush); }
void wxColourExt::GetRGB(float* r, float* g, float* b) const { if(!WasLastMode(RGB)) { R = (float)Red()/255; G = (float)Green()/255; B = (float)Blue()/255; } *r = R; *g = G; *b = B; }
void wxColourExt::GetCMY(float* c, float* m, float* y) const { if(!WasLastMode(CMY)) { C = 1 - (float)Red()/255; M = 1 - (float)Green()/255; Y = 1 - (float)Blue()/255; } *c = C; *m = M; *y = Y; }
void setProportionalTargetColor(LedGroup* group, int i, float colorIntensity) { float fr = Red(currentColor); float fg = Green(currentColor); float fb = Blue(currentColor); byte r = (fr / 100.) * colorIntensity; byte g = (fg / 100.) * colorIntensity; byte b = (fb / 100.) * colorIntensity; group->targetColors[i] = createColor(r, g, b); }
/** * Returns the highlighted version of this color. */ constexpr Color Highlight() const { #ifdef GREYSCALE return Color((GetLuminosity() + 0xff * 3) / 4); #else return Color((Red() + 0xff * 3) / 4, (Green() + 0xff * 3) / 4, (Blue() + 0xff * 3) / 4); #endif }
void flickerSelectColor(LedGroup* group, int i, int min_, int max_) { float proportion = random(min_, max_); float fr = Red(currentColor); float fg = Green(currentColor); float fb = Blue(currentColor); byte r = fr / proportion; byte g = fg / proportion; byte b = fb / proportion; Color c = group->getColor(i); float cr = Red(c); float cg = Green(c); float cb = Blue(c); group->increment[i][0] = max(abs(cr - fr) / 10, 1); group->increment[i][1] = max(abs(cg - fg) / 10, 1); group->increment[i][2] = max(abs(cb - fb) / 10, 1); group->targetColors[i] = createColor(r,g,b); }
void hideStrategy(LedGroup* group) { group->selectionLen = 10; group->animationDone = false; for(int i=0;i<group->selectionLen; i++) { group->pixelState[i] = 2; byte proportion = random(1, 5); group->increment[i][0] = Red(currentColor) / proportion; group->increment[i][1] = Green(currentColor) / proportion; group->increment[i][2] = Blue(currentColor) / proportion; } }
LKColor LKColor::ChangeBrightness(double fBrightFact) const { #ifdef GREYSCALE int Luminosity = GetLuminosity()*fBrightFact; if (Luminosity > 255) Luminosity = 255; return Color(Luminosity, Alpha()); #else int red = (int) (fBrightFact * (double) Red()); if (red > 255) red = 255; int blue = (int) (fBrightFact * (double) Blue()); if (blue > 255) blue = 255; int green = (int) (fBrightFact * (double) Green()); if (green > 255) green = 255; return LKColor((uint8_t) red, (uint8_t) green, (uint8_t) blue); #endif }
double ON_Color::Saturation() const { // 0.0 to 1.0 0.0 = gray, 1.0 = saturated double s; int r = Red(); int g = Green(); int b = Blue(); int minrgb, maxrgb; if ( r <= g ) {minrgb = r; maxrgb = g;} else {minrgb = g; maxrgb = r;} if (minrgb > b) minrgb = b; else if (maxrgb < b ) maxrgb = b; if ( maxrgb > 0 ) { s = ((double)(maxrgb - minrgb))/((double)maxrgb); } else s = 0.0; return s; }
void CRocketMissile::CreateSmokeTrail( void ) { if ( m_hRocketTrail ) return; // Smoke trail. if ( (m_hRocketTrail = RocketTrail::CreateRocketTrail()) != NULL ) { m_hRocketTrail->m_Opacity = 0.2f; m_hRocketTrail->m_SpawnRate = 100; m_hRocketTrail->m_ParticleLifetime = 0.5f; m_hRocketTrail->m_StartColor.Init( 0.65f, 0.65f , 0.65f ); m_hRocketTrail->m_EndColor.Init( 0.0, 0.0, 0.0 ); m_hRocketTrail->m_StartSize = 8; m_hRocketTrail->m_EndSize = 32; m_hRocketTrail->m_SpawnRadius = 4; m_hRocketTrail->m_MinSpeed = 2; m_hRocketTrail->m_MaxSpeed = 16; m_hRocketTrail->SetLifetime( 999 ); m_hRocketTrail->FollowEntity( this, "0" ); } //const Color& col = g_PR->GetTeamColor(); Color col = Color (16, 32, 128); byte Red (col.r()); byte Green (col.g()); byte Blue (col.b()); m_pGlowTrail = CSpriteTrail::SpriteTrailCreate( "sprites/bluelaser1.vmt", GetLocalOrigin(), false ); int nAttachment = LookupAttachment( "fuse" ); if ( m_pGlowTrail != NULL ) { m_pGlowTrail->FollowEntity( this ); m_pGlowTrail->SetAttachment( this, nAttachment ); m_pGlowTrail->SetTransparency( kRenderTransAdd, Red, Green, Blue, 255, kRenderFxNone ); m_pGlowTrail->SetStartWidth( 25.0f ); m_pGlowTrail->SetEndWidth( 20.0f ); m_pGlowTrail->SetLifeTime( 0.8f ); } }
void TextOnPath(Painter& sw) { Font fnt = Roman(100); FontInfo fi = fnt.Info(); double pos = 0; const char *s = "Hello world, this is text on path!"; int l = GetTextSize(s, fnt).cx; double r = l / (2 * M_PI); sw.Circle(300, 300, r).Stroke(1, Red()); while(*s) { double w = fi[*s]; sw.BeginOnPath(pos + w / 2, true); sw.Character(-w / 2, -fi.GetAscent(), *s++, fnt) .Fill(0, -fi.GetAscent(), Yellow(), 0, fi.GetDescent(), Blue()) .Stroke(1, Black()); sw.End(); pos += w; } }
//============================================================================================== /*static*/ Color ConnState::ConvertStateToColor(EnumConnState enumConnState) { switch (enumConnState) { case NOCON_NEVER: return Gray(); case NOCON_WASSUCC: return Green(); case NOCON_WASFAIL: return Red(); case NOCON_UNDEF: return LtGray(); case NOCON_MISCONFIG: return Magenta(); case CONNECTING_START: return LtYellow(); case CONNECTING_YAWN: return Yellow(); case CONNECTING_2NDTRY: return LtMagenta(); case CONNECTING_3RDTRY: return White(); case CONNECTING_TIMEOUT: return Cyan(); case CON_SUCCEED: return LtGreen(); case CON_FAIL: return LtRed(); case CON_STALE: return LtBlue(); } return Black(); }
gcc_constexpr_method Color WithAlpha(GLubyte alpha) const { return Color(Red(), Green(), Blue(), alpha); }
/** * Returns the shadowed version of this color. */ constexpr Color Shadow() const { return Color(Red() * 15u / 16u, Green() * 15u / 16u, Blue() * 15u / 16u, Alpha()); }
void gdImage::CopyResampled(gdImage& dst, int dstX, int dstY, int /*srcX*/, int /*srcY*/, int dstW, int dstH, int srcW, int srcH, int tolerance) { gdImage& src=*this; int x, y; int srcTransparent=src.GetTransparent(); int dstTransparent=dst.GetTransparent(); for (y = dstY; (y < dstY + dstH); y++) { for (x = dstX; (x < dstX + dstW); x++) { int pd = dst.GetPixel (x, y); /* Added 7/24/95: support transparent copies */ /* fixed by paf 20030116, another fix below */ if (pd == dstTransparent) continue; double sy1, sy2, sx1, sx2; double sx, sy; double spixels = 0; double red = 0.0, green = 0.0, blue = 0.0; bool transparent=true; sy1 = ((double) y - (double) dstY) * (double) srcH / (double) dstH; sy2 = ((double) (y + 1) - (double) dstY) * (double) srcH / (double) dstH; sy = sy1; do { double yportion; if (floor (sy) == floor (sy1)) { yportion = 1.0 - (sy - floor (sy)); if (yportion > sy2 - sy1) { yportion = sy2 - sy1; } sy = floor (sy); } else if (sy == floor (sy2)) { yportion = sy2 - floor (sy2); } else { yportion = 1.0; } sx1 = ((double) x - (double) dstX) * (double) srcW / dstW; sx2 = ((double) (x + 1) - (double) dstX) * (double) srcW / dstW; sx = sx1; do { double xportion; double pcontribution; int p; if (floor (sx) == floor (sx1)) { xportion = 1.0 - (sx - floor (sx)); if (xportion > sx2 - sx1) { xportion = sx2 - sx1; } sx = floor (sx); } else if (sx == floor (sx2)) { xportion = sx2 - floor (sx2); } else { xportion = 1.0; } pcontribution = xportion * yportion; p = src.GetPixel ( (int) sx, (int) sy); // fix added 20020116 by paf to support transparent src if (p!=srcTransparent) { transparent = false; red += Red (p) * pcontribution; green += Green (p) * pcontribution; blue += Blue (p) * pcontribution; } spixels += xportion * yportion; sx += 1.0; } while (sx < sx2); sy += 1.0; } while (sy < sy2); if(transparent) continue; if (spixels != 0.0) { red /= spixels; green /= spixels; blue /= spixels; } /* Clamping to allow for rounding errors above */ if (red > 255.0) red = 255.0; if (green > 255.0) green = 255.0; if (blue > 255.0) blue = 255.0; red=round(red); green=round(green); blue=round(blue); /* First look for an exact match */ int nc = dst.ColorExact((int)red, (int)green, (int)blue); if (nc == (-1)) { /* No, so go for the closest color with high tolerance */ nc = dst.ColorClosest((int)red, (int)green, (int)blue, tolerance); if (nc == (-1)) { /* Not found with even high tolerance, so try to allocate it */ nc = dst.ColorAllocate((int)red, (int)green, (int)blue); /* If we're out of colors, go for the closest color */ if (nc == (-1)) nc = dst.ColorClosest((int)red, (int)green, (int)blue); } } dst.SetPixel(x, y, nc); } } }