public void AddTest() { Test(Color4b.FromArgb(10, 20, 30, 40) + Color4b.FromArgb(100, 150, 200, 250), 110, 170, 230, 255); Test(Color4b.FromArgb(255, 255, 255, 255) + Color4b.FromArgb(100, 150, 200, 250), 255, 255, 255, 255); }
/// <summary> /// The update method is used by the emitter to apply the action /// to every particle. It is called within the emitter's update /// loop and need not be called by the user. /// </summary> /// <param name="emitter">The Emitter that created the particle.</param> /// <param name="particle">The particle to be updated.</param> /// <param name="elapsedTime">The duration of the frame - used for time based updates.</param> public override void Update(Emitter emitter, Particle particle, double elapsedTime) { double alpha = m_endAlpha + m_diffAlpha * particle.Energy; int a = Math.Max(0, Math.Min(255, (int)(alpha * 256))); particle.Color = Color4b.FromArgb(a, particle.Color); }
public void SubtractTest() { Test(Color4b.FromArgb(100, 150, 200, 250) - Color4b.FromArgb(10, 20, 30, 40), 90, 130, 170, 210); Test(Color4b.FromArgb(10, 20, 30, 40) - Color4b.FromArgb(100, 150, 200, 250), 0, 0, 0, 0); }
private static void Test(Color4b c, int a, int r, int g, int b) { Assert.AreEqual(c.A, a); Assert.AreEqual(c.R, r); Assert.AreEqual(c.G, g); Assert.AreEqual(c.B, b); Assert.AreEqual(Color4b.FromArgb(a, r, g, b), c); }
public void MultiplyTest() { Test(Color4b.FromArgb(100, 150, 200, 250) * 2, 200, 255, 255, 255); Test(2 * Color4b.FromArgb(100, 150, 200, 250), 200, 255, 255, 255); Test(Color4b.FromArgb(100, 150, 200, 130) * 1.1, 110, 165, 220, 143); Test(Color4b.FromArgb(255, 255, 255, 255) * Color4b.FromArgb(255, 128, 64, 32), 255, 128, 64, 32); }
public void CreateTest() { var c = Color4b.FromArgb(50, 100, 150, 200); Test(Color4b.FromArgb(1, 2, 3, 4), 1, 2, 3, 4); Test(Color4b.FromArgb(1, 2, 3), 255, 1, 2, 3); Test(Color4b.FromArgb(10, c), 10, 100, 150, 200); Test(Color4b.FromValue(0x11223344), 0x11, 0x22, 0x33, 0x44); }
/// <summary> /// The initialize method is used by the emitter to initialize the particle. /// It is called within the emitter's createParticle method and need not /// be called by the user. /// </summary> /// <param name="emitter">The Emitter that created the particle.</param> /// <param name="particle">The particle to be initialized.</param> public override void Initialize(Emitter emitter, Particle particle) { double alpha; if (m_max == m_min) { alpha = m_min; } else { alpha = Utils.RandomDouble(m_min, m_max); } int a = (int)(alpha * 255.9); particle.Color = Color4b.FromArgb(a, particle.Color); }
public static Color4b RotateHue(double hue, int brightness) { if (hue >= 360f || hue <= 0) { hue = 0; } hue /= 60f; int i = (int)Math.Floor(hue); double f = hue - i; double q = 1.0 - f; int r, g, b; switch (i) { case 0: r = 255; g = (int)(255 * f) % 256; b = 0; break; case 1: r = (int)(255 * q) % 256; g = 255; b = 0; break; case 2: r = 0; g = 255; b = (int)(255 * f) % 256; break; case 3: r = 0; g = (int)(255 * q) % 256; b = 255; break; case 4: r = (int)(255 * f) % 256; g = 0; b = 255; break; default: r = 255; g = 0; b = (int)(255 * q) % 256; break; } return(Color4b.FromArgb( 255, (int)(r + (brightness - r) / 2), (int)(g + (brightness - g) / 2), (int)(b + (brightness - b) / 2))); }
/// <summary> /// This function is used to find a color between two other colors. /// </summary> /// <param name="color1">The first color.</param> /// <param name="color2">The second color.</param> /// <param name="ratio">The proportion of the first color to use. The rest of the color /// is made from the second color.</param> /// <returns>The color created.</returns> public static Color4b InterpolateColors(Color4b color1, Color4b color2, double ratio) { double inv = 1.0 - ratio; #if false int red = (int)Math.Round(color1.R * ratio + color2.R * inv); int green = (int)Math.Round(color1.G * ratio + color2.G * inv); int blue = (int)Math.Round(color1.B * ratio + color2.B * inv); int alpha = (int)Math.Round(color1.A * ratio + color2.A * inv); #else int red = (int)(color1.R * ratio + color2.R * inv); int green = (int)(color1.G * ratio + color2.G * inv); int blue = (int)(color1.B * ratio + color2.B * inv); int alpha = (int)(color1.A * ratio + color2.A * inv); #endif return(Color4b.FromArgb(alpha, red, green, blue)); }