void showLed(LedGroup* group, int i) {
  int index = random(1, 3);

  byte r = min(Red(currentColor) + index, Red(currentColor));
  byte g = min(Green(currentColor) + index, Green(currentColor));
  byte b = min(Blue(currentColor) + index, Blue(currentColor));

  group->waitFrames = 100;
  group->targetColors[i] = createColor(r,g,b);
}
Example #2
0
// 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);
}
Example #3
0
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;
    }
}
Example #4
0
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
}
Example #5
0
double ON_Color::Hue() const
{
  // returns 0 to 2*pi 
  // 0    = red,  pi/3   = yellow, 2*pi/3 = green, 
  // pi   = cyan, 4*pi/3 = blue,   5*pi/3 = magenta,
  // 2*pi = red
  double h;
  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 != minrgb ) {
    double d = 1.0/(maxrgb - minrgb);
    if ( r == maxrgb) {
      h = (g - b)*d;
      if ( h < 0.0 )
        h += 6.0;
    }
    else if ( g == maxrgb)
      h = 2.0 + (b - r)*d;
    else 
      h = 4.0 + (r - g)*d;
    h *= ON_PI/3.0;
  }
  else
    h = 0.0;
  return h;
}
Example #6
0
 /**
  * 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);
 }
Example #7
0
    // 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();
    }
Example #8
0
Color::Color(double vRed, double vGreen, double vBlue, 
	     double vTransparent)
{
	Red(vRed);
	Green(vGreen);
	Blue(vBlue);
	Transparent(vTransparent);
}
Example #9
0
void Stats_Draw(widget_t *w)
{
  //stats_gui_t *gf = (stats_gui_t*)w->wd;
  static int bg  = 0;
  char       buf[1024];

  // Init if needed.. I guess this can be here.
  if( bg == 0 ) {
    glEnable(GL_TEXTURE_2D);
    bg = BuildStatsBG();
    glDisable(GL_TEXTURE_2D);
  }

  // Draw background.
  glEnable(GL_TEXTURE_2D);
  White();
  glCallList(bg);
  glDisable(GL_TEXTURE_2D);

  // Draw the xp info:
  Yellow();
  sprintf(buf,"XP:");
  glRasterPos2f(0.1f, 0.1f);
  printGLf(w->glw->font,"%s",buf);
  sprintf(buf,"%.1lf",Statec->player.xp);
  glRasterPos2f(0.4f, 0.1f);
  printGLf(w->glw->font,"%s",buf);

  // Draw the mana info:
  Purple();
  sprintf(buf,"Mana:");
  glRasterPos2f(0.1f, 0.2f);
  printGLf(w->glw->font,"%s",buf);
  sprintf(buf,"%.1lf /",Statec->player.mana);
  glRasterPos2f(0.4f, 0.2f);
  printGLf(w->glw->font,"%s",buf);
  sprintf(buf,"%.0lf",Statec->player.base_mana);
  glRasterPos2f(0.4f, 0.3f);
  printGLf(w->glw->font,"%s",buf);

  // Draw the wave info:
  Green();
  sprintf(buf,"Wave:");
  glRasterPos2f(0.1f, 0.4f);
  printGLf(w->glw->font,"%s",buf);
  sprintf(buf,"%lu",Statec->wave);
  glRasterPos2f(0.4f, 0.4f);
  printGLf(w->glw->font,"%s",buf);

  // Outline
  Yellow();
  glBegin(GL_LINE_LOOP);
  glVertex2f(0.0f,0.0f);
  glVertex2f(0.0f,1.0f);
  glVertex2f(1.0f,1.0f);
  glVertex2f(1.0f,0.0f);
  glEnd();
}
Example #10
0
void GradientStop(Painter& sw)
{
	sw.Rectangle(20.5, 20.5, 500, 100)
	  .ColorStop(0.25, Green())
	  .ColorStop(0.5, Yellow())
	  .ColorStop(0.75, Gray())
	  .Fill(0, 0, Blue(), 500, 0, LtRed())
	  .Stroke(1, Black());
}
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;
      }
    }
  }
}
Example #12
0
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);
}
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);
}
Example #14
0
  constexpr
  Color
  WithAlpha(uint8_t alpha) const {
#ifdef GREYSCALE
    return Color(GetLuminosity(), alpha);
#else
    return Color(Red(), Green(), Blue(), alpha);
#endif
  }
Example #15
0
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
}
Example #16
0
  /**
   * 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
  }
Example #17
0
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);
}
Example #18
0
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;
}
Example #19
0
Color EditorSyntax::IfColor(char c)
{
	switch(c){
	case IfState::IF:          return LtBlue();
	case IfState::ELIF:        return Gray();
	case IfState::ELSE:        return Green();
	case IfState::ELSE_ERROR:  return LtRed();
	case IfState::ENDIF_ERROR: return LtMagenta();
	default:                   return Null;
	}
}
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);
}
Example #21
0
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;
}
Example #22
0
  /**
   * 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);
}
Example #24
0
bool Ctrl::PaintOpaqueAreas(SystemDraw& w, const Rect& r, const Rect& clip, bool nochild)
{
	GuiLock __;
	LTIMING("PaintOpaqueAreas");
	if(!IsShown() || r.IsEmpty() || !r.Intersects(clip) || !w.IsPainting(r))
		return true;
	Point off = r.TopLeft();
	Point viewpos = off + GetView().TopLeft();
	if(backpaint == EXCLUDEPAINT)
		return w.ExcludeClip(r);
	Rect cview = clip & (GetView() + off);
	for(Ctrl *q = lastchild; q; q = q->prev)
		if(!q->PaintOpaqueAreas(w, q->GetRect() + (q->InView() ? viewpos : off),
		                        q->InView() ? cview : clip))
			return false;
	if(nochild && (lastchild || GetNext()))
		return true;
	Rect opaque = (GetOpaqueRect() + viewpos) & clip;
	if(opaque.IsEmpty())
		return true;
#ifdef SYSTEMDRAW
	if(backpaint == FULLBACKPAINT && !dynamic_cast<BackDraw *>(&w))
#else
	if(backpaint == FULLBACKPAINT && !w.IsBack())
#endif
	{
		ShowRepaintRect(w, opaque, LtRed());
		BackDraw bw;
		bw.Create(w, opaque.GetSize());
		bw.Offset(viewpos - opaque.TopLeft());
		bw.SetPaintingDraw(w, opaque.TopLeft());
		{
			LEVELCHECK(bw, this);
			Paint(bw);
			PaintCaret(bw);
		}
		bw.Put(w, opaque.TopLeft());
	}
	else {
		w.Clip(opaque);
		ShowRepaintRect(w, opaque, Green());
		w.Offset(viewpos);
		{
			LEVELCHECK(w, this);
			Paint(w);
			PaintCaret(w);
		}
		w.End();
		w.End();
	}
	LLOG("Exclude " << opaque);
	return w.ExcludeClip(opaque);
}
Example #25
0
void Path(Painter& sw)
{
	sw.Translate(52, 52);
	for(int i = 0; i < 2; i++) {
		sw.Rectangle(20, 20, 60, 60);
		sw.Move(0, 0);
		sw.Cubic(99, 0,  50, 50,  99, 99);
		sw.Cubic(0, 99,  50, 50,  0, 0);
		sw.EvenOdd(i).Fill(Green());
		sw.Stroke(1, Black());
		sw.Translate(120, 0);
	}
}
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;
  }
}
Example #27
0
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
}
Example #28
0
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;
}
Example #29
0
void TabBubblePlot::Init()
{
	CtrlLayout(*this);	
	SizePos();
	
	scatter.SetMouseHandling(true, true).ShowContextMenu();

	for (double size = 0; size <= 10; size += 2.) {
		Vector<double> &data = s1.Add();
		data << size << (10 + 10*Random(30)*size) << Random(80); 		
	}
	idsBubble << 2;
	static Vector<int> idVoid;
	scatter.AddSeries(s1, 0, 1, idVoid, idVoid, idsBubble).Legend("Importance").MarkStyle<BubblePlot>()
		   .NoPlot().MarkColor(Green()).MarkBorderColor(LtRed()).MarkBorderWidth(3);
	
	scatter.SetLabelY("Size");
	scatter.ZoomToFit(true, true, 0.2);
}
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 );
	}
}