Esempio n. 1
0
		public HSLColor(RgbColor color)
		{
			m_hue = 0;
			m_saturation = 1;
			m_lightness = 1;
			FromRGB(color);
		}
Esempio n. 2
0
		public static RgbColor FromRgb(int r, int g, int b)
		{
			RgbColor color = new RgbColor();
			color.R = (byte)r;
			color.G = (byte)g;
			color.B = (byte)b;

			return color;
		}
Esempio n. 3
0
		public static RgbColor FromString (String colorStr)
		{
			RgbColor color = new RgbColor();
			color.R = Convert.ToByte(colorStr.Substring(1, 2), 16);
			color.G = Convert.ToByte(colorStr.Substring(3, 2), 16);
			color.B = Convert.ToByte(colorStr.Substring(5, 2), 16);

			return color;
		}
Esempio n. 4
0
		public static RgbColor FromGdkColor(ushort r, ushort g, ushort b)
		{
			RgbColor color = new RgbColor();
			
			color.R = (byte)(r / 0x100);
			color.G = (byte)(g / 0x100);
			color.B = (byte)(b / 0x100);
			
			return color;
		}
		public override RgbColor GetVisibleColor ()
		{
			/*
			HSLColor color = new HSLColor (Color);
			color.Lightness = (double)(color.Lightness * cpuUsage / 100);
			return color.Color;
			*/
			RgbColor color = new RgbColor ();
			color.R = (byte)(255 * cpuUsage / 100);
			color.G = (byte)(255 - 255 * cpuUsage / 100);

			return color;
		}
Esempio n. 6
0
		void FromRGB(RgbColor cc)
		{
			double r = (double)cc.R / 255d;
			double g = (double)cc.G / 255d;
			double b = (double)cc.B / 255d;
			
			double min = Math.Min(Math.Min(r, g), b);
			double max = Math.Max(Math.Max(r, g), b);
			// calulate hue according formula given in
			// "Conversion from RGB to HSL or HSV"
			m_hue = 0;
			if (min != max)
			{
				if (r == max && g >= b)
				{
					m_hue = 60 * ((g - b) / (max - min)) + 0;
				}
				else
				if (r == max && g < b)
				{
					m_hue = 60 * ((g - b) / (max - min)) + 360;
				}
				else
				if (g == max)
				{
					m_hue = 60 * ((b - r) / (max - min)) + 120;
				}
				else
				if (b == max)
				{
					m_hue = 60 * ((r - g) / (max - min)) + 240;
				}
			}
			// find lightness
			m_lightness = (min+max)/2;

			// find saturation
			if (m_lightness == 0 ||min == max)
				m_saturation = 0;
			else
			if (m_lightness > 0 && m_lightness <= 0.5)
				m_saturation = (max-min)/(2*m_lightness);
			else
			if (m_lightness > 0.5)
				m_saturation = (max-min)/(2-2*m_lightness);
		}
		void AnimateMorphToColor(object sender)
		{
            while (!((BackgroundWorker)sender).CancellationPending) {
                
				if (TargetColor.R == VisibleColor.R && 
                    TargetColor.G == VisibleColor.G && 
                    TargetColor.B == VisibleColor.B)
                {
					break;
				}
                else
                {
                    RgbColor newColor = new RgbColor();
					newColor.R = (byte)(VisibleColor.R + Math.Sign(TargetColor.R - VisibleColor.R)); 
                    newColor.G = (byte)(VisibleColor.G + Math.Sign(TargetColor.G - VisibleColor.G)); 
                    newColor.B = (byte)(VisibleColor.B + Math.Sign(TargetColor.B - VisibleColor.B));

                    SendColor(newColor);

                    Thread.Sleep(5);
                }
			}			
		}
		public void BlinkColor(int numberOfTimes, RgbColor targetColor)
		{
			if (this.Animating)
				this.Stop();

			this.AnimationType = AnimationTypeEnum.BlinkColor;
			this.TargetColor = targetColor;
			this.TargetPulses = numberOfTimes;
					
			this.Start();
		}
		public void MorphToColor(RgbColor targetColor)
		{
			if (this.AnimationType != AnimationTypeEnum.MorphToColor && this.Animating)
				this.Stop();

			this.AnimationType = AnimationTypeEnum.MorphToColor;
			this.TargetColor = targetColor;

			this.Start();
		}
Esempio n. 10
0
        public void SendColor(RgbColor newColor)
        {
			if (Device.Connected)
			{
				if (DataEntity.Control == DeviceControlEnum.Normal)
				{
					Device.SetLedColor(newColor.R, newColor.G, newColor.B);
				}
				else
				{
					Device.SetLedColor((byte)(255 - newColor.R), (byte)(255 - newColor.G), (byte)(255 - newColor.B));
				}
			}

			VisibleColor = newColor;
        }