コード例 #1
0
		/// <summary>
		/// Converts color given in string representation 
		/// (GDK color name, HTML triplet in #fff and #777777 forms)
		/// to a Color2 structure
		/// </summary>
		/// <returns>Color2 structure.</returns>
		/// <param name="colorString">Color string.</param>
		private static Color2 FromColorString (string colorString)
		{
			// default / fallback
			var color = new Color2 (0, 0, 0);

			try
			{
				if (string.IsNullOrWhiteSpace (colorString))
					throw new Exception ();

				if (colorString.StartsWith ("#", StringComparison.InvariantCultureIgnoreCase))
				{
					int r, g, b;

					if (colorString.Length == "#fff".Length)
					{		
						r = Convert.ToInt32 (colorString.Substring (1, 1), 16);
						g = Convert.ToInt32 (colorString.Substring (2, 1), 16);
						b = Convert.ToInt32 (colorString.Substring (3, 1), 16);

						color.R = (r * 16 + r) / 255.0;
						color.G = (g * 16 + g) / 255.0;
						color.B = (b * 16 + b) / 255.0;

					}
					else if (colorString.Length == "#f0f0f0".Length)
					{
						r = Convert.ToInt32 (colorString.Substring (1, 2), 16);
						g = Convert.ToInt32 (colorString.Substring (3, 2), 16);
						b = Convert.ToInt32 (colorString.Substring (5, 2), 16);

						color.R = r / 255.0;
						color.G = g / 255.0;
						color.B = b / 255.0;
					}
				}
				else // Gdk
				{
					Gdk.Color gdkColor = new Gdk.Color ();
					if (Gdk.Color.Parse (colorString, ref gdkColor))
					{
						color.R = gdkColor.Red / 65535.0;
						color.G = gdkColor.Green / 65535.0;
						color.B = gdkColor.Blue / 65535.0;
					}
				}
			}
			catch
			{
				// set explicit in case some parse operations 
				// were successful, but others were not
				color = new Color2 (0, 0, 0);

				// TODO: Must write to log
				Console.WriteLine ("Warning: Could not parse color, falling back to black");
			}

			return color;
		}
コード例 #2
0
ファイル: Bubble.cs プロジェクト: roman-yagodin/Cairo.R7
		/// <summary>
		/// How this bubble eats another bubble.
		/// </summary>
		/// <param name="b">The blue component.</param>
		public void EatBubble (Bubble b)
		{
			// area ratio
			var Sd = b.S / this.S;
			b.IsEaten = true;

			// mixing colors (depending on area ratio)
			this.Color = new Color (
				(b.Color.R * Sd + this.Color.R * (1 - Sd)), 
				(b.Color.G * Sd + this.Color.G * (1 - Sd)), 
				(b.Color.B * Sd + this.Color.B * (1 - Sd)));

			// increase radius (depending on area ratio)
			this.R = Math.Sqrt ((this.S + b.S) / Math.PI);

			// calculating speed (depending on area / "mass" ratio)
			this.VX += b.VX * Sd;
			this.VY += b.VY * Sd;
		}
コード例 #3
0
ファイル: MainWindow.cs プロジェクト: roman-yagodin/Cairo.R7
		private void ModifyScene ()
		{
			var cinc = 0.01;

			if (turn) 
			{
				color1 = new Color (0, color1.G + cinc, color1.B - cinc, 0.5);
				color2 = new Color (color2.R + cinc, color2.G - cinc, 0, 0.5);
				color3 = new Color (color3.R - cinc, 0, color3.B + cinc, 0.5);
				
				if (color1.G >= 1.0)
					turn = false;
			}
			else 
			{
				color1 = new Color (0, color1.G - cinc, color1.B + cinc, 0.5);
				color2 = new Color (color2.R - cinc, color2.G + cinc, 0, 0.5);
				color3 = new Color (color3.R + cinc, 0, color3.B - cinc, 0.5);
				
				if (color1.B >= 1.0)
					turn = true;
			}

			alpha += Math.PI / 100;
		}
コード例 #4
0
		public Color2 PopColor ()
		{
			this.Color = colorStack.Pop ();

			return this.Color;
		}
コード例 #5
0
		public void PushColor (Color2 color2)
		{
			colorStack.Push (color2);
		}