Example #1
0
        public void RenderFireworks(int Number_Explosions, int Count, float Velocity, int Fade)
        {
            int idxFlakes = 0;
            int i = 0;
            int mod100;
            int x25, x75, y25, y75;
            const int maxFlakes = 1000;
            int startX;
            int startY; //, ColorIdx;
            float v;
            HSV hsv = new HSV();
            int colorCount = GetColorCount();

            // This does not work with 1 string, so use a try/catch block to prevent errors
            try {
                InitFireworksBuffer();

                if (State == 0) {
                    for (i = 0; i < maxFlakes; i++) {
                        fireworkBursts[i]._bActive = false;
                    }
                }

                mod100 = (int) (State%(101 - Number_Explosions)*20);
                if (mod100 == 0) {
                    x25 = (int) (BufferWi*0.25);
                    x75 = (int) (BufferWi*0.75);
                    y25 = (int) (BufferHt*0.25);
                    y75 = (int) (BufferHt*0.75);
                    startX = x25 + (rand()%(x75 - x25));
                    startY = y25 + (rand()%(y75 - y25));

                    // Create new bursts
                    hsv = Palette.ActiveColors.Count>0?HSV.ColorToHSV(Palette.ActiveColors[rand() % colorCount]):HSV.ColorToHSV(Color.White);
                    for (i = 0; i < Count; i++) {
                        do {
                            idxFlakes = (idxFlakes + 1)%maxFlakes;
                        } while (fireworkBursts[idxFlakes]._bActive);
                        fireworkBursts[idxFlakes].Reset(startX, startY, true, Velocity, hsv);
                    }
                }
                else {
                    for (i = 0; i < maxFlakes; i++) {
                        // ... active flakes:
                        if (fireworkBursts[i]._bActive) {
                            // Update position
                            fireworkBursts[i]._x += fireworkBursts[i]._dx;
                            fireworkBursts[i]._y +=
                                (float) (-fireworkBursts[i]._dy - fireworkBursts[i]._cycles*fireworkBursts[i]._cycles/10000000.0);
                            // If this flake run for more than maxCycle, time to switch it off
                            fireworkBursts[i]._cycles += 20;
                            if (10000 == fireworkBursts[i]._cycles) // if (10000 == fireworkBursts[i]._cycles)
                            {
                                fireworkBursts[i]._bActive = false;
                                continue;
                            }
                            // If this flake hit the earth, time to switch it off
                            if (fireworkBursts[i]._y >= BufferHt) {
                                fireworkBursts[i]._bActive = false;
                                continue;
                            }
                            // Draw the flake, if its X-pos is within frame
                            if (fireworkBursts[i]._x >= 0.0 && fireworkBursts[i]._x < BufferWi) {
                                // But only if it is "under" the roof!
                                if (fireworkBursts[i]._y >= 0.0) {
                                    // sean we need to set color here
                                }
                            }
                            else {
                                // otherwise it just got outside the valid X-pos, so switch it off
                                fireworkBursts[i]._bActive = false;
                            }
                        }
                    }
                }

                for (i = 0; i < 1000; i++) {
                    if (fireworkBursts[i]._bActive) {
                        v = (float) (((Fade*10.0) - fireworkBursts[i]._cycles)/(Fade*10.0));
                        if (v < 0) v = 0.0f;
                        hsv = fireworkBursts[i]._hsv;
                        hsv.Value = v;
                        SetPixel((int) fireworkBursts[i]._x, (int) fireworkBursts[i]._y, hsv);
                    }
                }
            }
            catch {
            }
        }
Example #2
0
 public void RenderButterfly(int colorScheme, int style, int chunks, int skip, int direction)
 {
     int x, y, d;
     double n, x1, y1, f;
     double h = 0.0;
     Color color;
     HSV hsv = new HSV();
     int maxframe = BufferHt*2;
     int frame = (int) ((BufferHt*(double) State/200.0)%maxframe);
     double offset = State/100.0;
     if (direction == 1) offset = -offset;
     for (x = 0; x < BufferWi; x++) {
         for (y = 0; y < BufferHt; y++) {
             switch (style) {
                 case 1:
                     n = Math.Abs((x*x - y*y)*Math.Sin(offset + ((x + y)*pi2/(BufferHt + BufferWi))));
                     d = x*x + y*y + 1;
                     h = n/d;
                     break;
                 case 2:
                     f = (frame < maxframe/2) ? frame + 1 : maxframe - frame;
                     x1 = (x - BufferWi/2.0)/f;
                     y1 = (y - BufferHt/2.0)/f;
                     h = Math.Sqrt(x1*x1 + y1*y1);
                     break;
                 case 3:
                     f = (frame < maxframe/2) ? frame + 1 : maxframe - frame;
                     f = f*0.1 + BufferHt/60.0;
                     x1 = (x - BufferWi/2.0)/f;
                     y1 = (y - BufferHt/2.0)/f;
                     h = Math.Sin(x1)*Math.Cos(y1);
                     break;
             }
             hsv.Saturation = 1.0f;
             hsv.Value = 1.0f;
             if (chunks <= 1 || ((int) (h*chunks))%skip != 0) {
                 if (colorScheme == 0) {
                     hsv.Hue = (float) h;
                     SetPixel(x, y, hsv);
                 }
                 else {
                     color = GetMultiColorBlend(h, false);
                     SetPixel(x, y, color);
                 }
             }
         }
     }
 }
Example #3
0
 public void RenderColorWash(bool HorizFade, bool VertFade, int RepeatCount)
 {
     const int SpeedFactor = 200;
     int x, y;
     Color color;
     HSV hsv2 = new HSV();
     int colorcnt = GetColorCount();
     int CycleLen = colorcnt*SpeedFactor;
     if (State > (colorcnt - 1)*SpeedFactor*RepeatCount && RepeatCount < 10) {
         //Console.WriteLine("1");
         color = GetMultiColorBlend((double) (RepeatCount%2), false);
     }
     else {
         //Console.WriteLine("2");
         color = GetMultiColorBlend((double) (State%CycleLen)/(double) CycleLen, true);
     }
     HSV hsv = HSV.ColorToHSV(color);
     double HalfHt = (double) (BufferHt - 1)/2.0;
     double HalfWi = (double) (BufferWi - 1)/2.0;
     for (x = 0; x < BufferWi; x++) {
         for (y = 0; y < BufferHt; y++) {
             hsv2.SetToHSV(hsv);
             if (HorizFade && HalfWi > 0) hsv2.Value *= (float) (1.0 - Math.Abs(HalfWi - x)/HalfWi);
             if (VertFade && HalfHt > 0) hsv2.Value *= (float) (1.0 - Math.Abs(HalfHt - y)/HalfHt);
             //SetPixel(x, y, hsv);
             SetPixel(x, y, hsv2);
             //SetPixel(x, y, color);
         }
     }
 }
Example #4
0
        private void RenderMeteors(int MeteorType, int Count, int Length)
        {
            if (State == 0)
                meteors.Clear();
            int mspeed = (int) State/4;
            State -= mspeed*4 - 1;

            // create new meteors
            HSV hsv = new HSV();
            HSV hsv0 = new HSV();
            HSV hsv1 = new HSV();
            hsv0 = Palette.GetHSV(0);
            hsv1 = Palette.GetHSV(1);
            int colorcnt = GetColorCount();
            Count = BufferWi*Count/100;
            int TailLength = (BufferHt < 10) ? Length/10 : BufferHt*Length/100;
            if (TailLength < 1) TailLength = 1;
            int TailStart = BufferHt - TailLength;
            if (TailStart < 1) TailStart = 1;
            for (int i = 0; i < Count; i++) {
                MeteorClass m = new MeteorClass();
                m.x = rand()%BufferWi;
                m.y = BufferHt - 1 - (rand()%TailStart);
                switch (MeteorType) {
                    case 1:
                        m.hsv = HSV.SetRangeColor(hsv0, hsv1);
                        break;
                    case 2:
                        m.hsv = Palette.GetHSV(rand()%colorcnt);
                        break;
                }
                meteors.Add(m);
            }

            // render meteors
            foreach (MeteorClass meteor in meteors) {
                {
                    for (int ph = 0; ph < TailLength; ph++) {
                        switch (MeteorType) {
                            case 0:
                                hsv.Hue = (float) (rand()%1000)/1000.0f;
                                hsv.Saturation = 1.0f;
                                hsv.Value = 1.0f;
                                break;
                            default:
                                hsv.SetToHSV(meteor.hsv);
                                break;
                        }
                        hsv.Value *= (float) (1.0 - (double) ph/TailLength);
                        SetPixel(meteor.x, meteor.y + ph, hsv);
                    }
                    meteor.y -= mspeed;
                }
            }
            // delete old meteors
            int meteorNum = 0;
            while (meteorNum < meteors.Count) {
                if (meteors[meteorNum].HasExpired(TailLength)) {
                    meteors.RemoveAt(meteorNum);
                }
                else {
                    meteorNum++;
                }
            }
        }
Example #5
0
 public void Reset(int x, int y, bool active, float velocity, HSV hsv)
 {
     _x = x;
     _y = y;
     vel = (random.Next() - int.MaxValue/2)*velocity/(int.MaxValue/2);
     angle = (float) (2*Math.PI*random.Next()/int.MaxValue);
     _dx = (float) (vel*Math.Cos(angle));
     _dy = (float) (vel*Math.Sin(angle));
     _bActive = active;
     _cycles = 0;
     _hsv = hsv;
 }
Example #6
0
 // 0,0 is lower left
 public void SetPixel(int x, int y, HSV hsv)
 {
     Color color = HSV.HSVtoColor(hsv);
     SetPixel(x, y, color);
 }
Example #7
0
        // initialize FirePalette[]
        private void InitFirePalette()
        {
            HSV hsv = new HSV();
            Color color;

            FirePalette.Clear();
            //wxImage::HSVValue hsv;
            //wxImage::RGBValue rgb;
            //wxColour color;
            int i;
            // calc 100 reds, black to bright red
            hsv.Hue = 0.0f;
            hsv.Saturation = 1.0f;
            for (i = 0; i < 100; i++)
            {
                hsv.Value = (float)i / 100.0f;
                //rgb = wxImage::HSVtoRGB(hsv);
                //color.Set(rgb.red,rgb.green,rgb.blue);
                color = HSV.HSVtoColor(hsv);
                FirePalette.Add(color);
                //FirePalette.push_back(color);
            }

            // gives 100 hues red to yellow
            hsv.Value = 1.0f;
            for (i = 0; i < 100; i++)
            {
                //rgb = wxImage::HSVtoRGB(hsv);
                //color.Set(rgb.red,rgb.green,rgb.blue);
                color = HSV.HSVtoColor(hsv);
                //FirePalette.push_back(color);
                FirePalette.Add(color);
                hsv.Hue += 0.00166666f;
            }
        }
Example #8
0
 public HSV GetHSV(int index)
 {
     return(HSV.ColorToHSV(GetColor(index)));
     //return HSV.ColorToHSV(Colors[index]);
 }
Example #9
0
		public void SetToHSV(HSV hsv)
		{
			Hue = hsv.Hue;
			Saturation = hsv.Saturation;
			Value = hsv.Value;
		}
Example #10
0
		public static HSV SetRangeColor(HSV hsv1, HSV hsv2)
		{
			HSV newHsv = new HSV(RandomRange(hsv1.Hue, hsv2.Hue),
			                     RandomRange(hsv1.Saturation, hsv2.Saturation),
			                     1.0f);
			return newHsv;
		}
Example #11
0
		//public static HSV ColorToHSV(Color color)
		//{
		//    float h, s, v = 0;
		//    float min, max, delta;
		//    min = Math.Min(color.R, Math.Min(color.G, color.B));
		//    max = Math.Max(color.R, Math.Max(color.G, color.B));
		//    v = max;				// v
		//    delta = max - min;
		//    //Console.WriteLine(min + ":" + max + ":" + v);
		//    if (max != 0)
		//    {
		//        //Console.WriteLine("1.1:" + max);
		//        s = delta / max;		// s
		//    }
		//    else
		//    {
		//        // r = g = b = 0		// s = 0, v is undefined
		//        s = 0;
		//        h = -1;
		//        //Console.WriteLine("2");
		//        return new HSV(h, s, v);
		//    }
		//    //Console.WriteLine("3");
		//    if (color.R == max)
		//        h = (color.G - color.B) / delta;		// between yellow & magenta
		//    else if (color.G == max)
		//        h = 2 + (color.B - color.R) / delta;	// between cyan & yellow
		//    else
		//        h = 4 + (color.R - color.G) / delta;	// between magenta & cyan
		//    h *= 60;				// degrees
		//    if (h < 0)
		//        h += 360;
		//    //Console.WriteLine("4");
		//    HSV hsv = new HSV(h, s, v);
		//    //Console.WriteLine("OUT");
		//    return hsv;
		//}

		//public static HSV ColorToHSV(Color color)
		//{

		//    float h, s, v = 0f;
		//    float min = Math.Min(Math.Min(color.R, color.G), color.B);
		//    float max = Math.Max(Math.Max(color.R, color.G), color.B);
		//    float delta = max - min;

		//    // value is our max color
		//    v = max;

		//    // saturation is percent of max
		//    if (!Math.Equals(max, 0))
		//        s = delta / max;
		//    else
		//    {
		//        // all colors are zero, no saturation and hue is undefined
		//        s = 0;
		//        h = -1;
		//        return new HSV(h, s, v);
		//    }

		//    // grayscale image if min and max are the same
		//    if (Math.Equals(min, max))
		//    {
		//        v = max;
		//        s = 0;
		//        h = -1;
		//        return new HSV(h, s, v);
		//    }

		//    // hue depends which color is max (this creates a rainbow effect)
		//    if (color.R == max)
		//        h = (color.G - color.B) / delta;         	// between yellow & magenta
		//    else if (color.G == max)
		//        h = 2 + (color.B - color.R) / delta; 		// between cyan & yellow
		//    else
		//        h = 4 + (color.R - color.G) / delta; 		// between magenta & cyan

		//    // turn hue into 0-360 degrees
		//    h *= 60;
		//    if (h < 0)
		//        h += 360;

		//    return new HSV(h, s, v);
		//}

		public static Color HSVtoColor(HSV inHsv)
		{
			//1:0:1:255
			//2:65025:0:65025:0
			//Console.WriteLine("1");
			HSV hsv = new HSV(inHsv.Hue, inHsv.Saturation, inHsv.Value);
			//if (hsv.Hue > 0 && hsv.Hue < 1)
			//{
			hsv.Hue *= 360;
			//}
			int hi = Convert.ToInt32(Math.Floor(hsv.Hue/60)%6);
			double f = hsv.Hue/60f - Math.Floor(hsv.Hue/60f);

			hsv.Value = hsv.Value*255f;
			int v = Convert.ToInt32(hsv.Value);
			int p = Convert.ToInt32(hsv.Value*(1 - hsv.Saturation));
			int q = Convert.ToInt32(hsv.Value*(1 - f*hsv.Saturation));
			int t = Convert.ToInt32(hsv.Value*(1 - (1 - f)*hsv.Saturation));
			//Console.WriteLine("1:" + inHsv.Hue + ":" + inHsv.Saturation + ":" + inHsv.Value);
			//Console.WriteLine("2:" + v + ":" + p + ":" + q + ":" + t);
			//Console.WriteLine("hi:" + hi);
			if (hi == 0) {
				return Color.FromArgb(255, v, t, p);
			}
			else if (hi == 1) {
				return Color.FromArgb(255, q, v, p);
			}
			else if (hi == 2) {
				return Color.FromArgb(255, p, v, t);
			}
			else if (hi == 3) {
				return Color.FromArgb(255, p, q, v);
			}
			else if (hi == 4) {
				return Color.FromArgb(255, t, p, v);
			}
			else {
				return Color.FromArgb(255, v, p, q);
			}
		}
 public void SetToHSV(HSV hsv)
 {
     Hue        = hsv.Hue;
     Saturation = hsv.Saturation;
     Value      = hsv.Value;
 }