예제 #1
0
        protected override void RenderEffect(int frame, IPixelFrameBuffer frameBuffer)
        {
            double intervalPosFactor = GetEffectTimeIntervalPosition(frame) * 100;

            int x, y;

            if (frame == 0)
            {
                int i;
                for (i = 0; i < _fireBuffer.Count(); i++)
                {
                    _fireBuffer[i] = 0;
                }
            }

            int maxHt = BufferHt;
            int maxWi = BufferWi;

            if (Location == FireDirection.Left || Location == FireDirection.Right)
            {
                maxHt = BufferWi;
                maxWi = BufferHt;
            }

            // build fire
            for (x = 0; x < maxWi; x++)
            {
                var r = x % 2 == 0 ? 190 + (Rand() % 10) : 100 + (Rand() % 50);
                SetFireBuffer(x, 0, r, maxWi, maxHt);
            }

            int h = (int)Height.GetValue(intervalPosFactor);

            if (h <= 0)
            {
                h = 1;
            }
            int step = 255 * 100 / maxHt / h;

            for (y = 1; y < maxHt; y++)
            {
                for (x = 0; x < maxWi; x++)
                {
                    var v1  = GetFireBuffer(x - 1, y - 1, maxWi, maxHt);
                    var v2  = GetFireBuffer(x + 1, y - 1, maxWi, maxHt);
                    var v3  = GetFireBuffer(x, y - 1, maxWi, maxHt);
                    var v4  = GetFireBuffer(x, y - 1, maxWi, maxHt);
                    var n   = 0;
                    var sum = 0;
                    if (v1 >= 0)
                    {
                        sum += v1;
                        n++;
                    }
                    if (v2 >= 0)
                    {
                        sum += v2;
                        n++;
                    }
                    if (v3 >= 0)
                    {
                        sum += v3;
                        n++;
                    }
                    if (v4 >= 0)
                    {
                        sum += v4;
                        n++;
                    }
                    var newIndex = n > 0 ? sum / n : 0;
                    if (newIndex > 0)
                    {
                        newIndex += (Rand() % 100 < 20) ? step : -step;
                        if (newIndex < 0)
                        {
                            newIndex = 0;
                        }
                        if (newIndex >= FirePalette.Count())
                        {
                            newIndex = FirePalette.Count() - 1;
                        }
                    }
                    SetFireBuffer(x, y, newIndex, maxWi, maxHt);
                }
            }
            for (y = 0; y < maxHt; y++)
            {
                for (x = 0; x < maxWi; x++)
                {
                    int xp = x;
                    int yp = y;
                    if (Location == FireDirection.Top || Location == FireDirection.Right)
                    {
                        yp = maxHt - y - 1;
                    }
                    if (Location == FireDirection.Left || Location == FireDirection.Right)
                    {
                        int t = xp;
                        xp = yp;
                        yp = t;
                    }

                    Color color = FirePalette.GetColor(GetFireBuffer(x, y, maxWi, maxHt));
                    var   hsv   = HSV.FromRGB(color);
                    if (CalculateHueShift(intervalPosFactor) > 0)
                    {
                        hsv.H = hsv.H + (CalculateHueShift(intervalPosFactor) / 100.0f);
                    }

                    hsv.V = hsv.V * LevelCurve.GetValue(intervalPosFactor) / 100;
                    //if (color.R == 0 && color.G == 0 && color.B == 0)
                    //{
                    //	color = Color.Transparent;
                    //}

                    frameBuffer.SetPixel(xp, yp, hsv);
                }
            }
        }
예제 #2
0
        protected override void RenderEffect(int frame, IPixelFrameBuffer frameBuffer)
        {
            double intervalPosFactor = GetEffectTimeIntervalPosition(frame) * 100;
            double level             = LevelCurve.GetValue(intervalPosFactor) / 100;
            double hueShift          = CalculateHueShift(intervalPosFactor);

            int x, y;

            int maxHt = BufferHt;
            int maxWi = BufferWi;

            if (Location == FireDirection.Left || Location == FireDirection.Right)
            {
                maxHt = BufferWi;
                maxWi = BufferHt;
            }

            // build fire
            for (x = 0; x < maxWi; x++)
            {
                var r = x % 2 == 0 ? 190 + (Rand() % 10) : 100 + (Rand() % 50);
                _fireBuffer[x] = r;
            }

            int h = (int)Height.GetValue(intervalPosFactor);

            if (h <= 0)
            {
                h = 1;
            }
            int step = 255 * 100 / maxHt / h;

            for (y = 1; y < maxHt; y++)
            {
                for (x = 0; x < maxWi; x++)
                {
                    var v1  = GetFireBuffer(x - 1, y - 1, maxWi, maxHt);
                    var v2  = GetFireBuffer(x + 1, y - 1, maxWi, maxHt);
                    var v3  = GetFireBuffer(x, y - 1, maxWi, maxHt);
                    var v4  = GetFireBuffer(x, y - 1, maxWi, maxHt);
                    var n   = 0;
                    var sum = 0;
                    if (v1 >= 0)
                    {
                        sum += v1;
                        n++;
                    }
                    if (v2 >= 0)
                    {
                        sum += v2;
                        n++;
                    }
                    if (v3 >= 0)
                    {
                        sum += v3;
                        n++;
                    }
                    if (v4 >= 0)
                    {
                        sum += v4;
                        n++;
                    }
                    var newIndex = n > 0 ? sum / n : 0;
                    if (newIndex > 0)
                    {
                        newIndex += (Rand() % 100 < 20) ? step : -step;
                        if (newIndex < 0)
                        {
                            newIndex = 0;
                        }
                        if (newIndex >= FirePalette.Count())
                        {
                            newIndex = FirePalette.Count() - 1;
                        }
                    }
                    _fireBuffer[y * maxWi + x] = newIndex;
                }
            }

            for (y = 0; y < maxHt; y++)
            {
                for (x = 0; x < maxWi; x++)
                {
                    var colorIndex = GetFireBuffer(x, y, maxWi, maxHt);
                    if (colorIndex == 0)
                    {
                        continue;                                      // No point going any further if color index is 0 (Black). Significantly reduces render time.
                    }
                    int xp = x;
                    int yp = y;
                    if (Location == FireDirection.Top || Location == FireDirection.Right)
                    {
                        yp = maxHt - y - 1;
                    }
                    if (Location == FireDirection.Left || Location == FireDirection.Right)
                    {
                        int t = xp;
                        xp = yp;
                        yp = t;
                    }
                    HSV hsv = FirePalette.GetColor(colorIndex);
                    if (hueShift > 0)
                    {
                        hsv.H = hsv.H + hueShift / 100.0f;
                    }

                    hsv.V *= level;

                    frameBuffer.SetPixel(xp, yp, hsv);
                }
            }
        }