protected override void RenderEffect(int frame, ref PixelFrameBuffer frameBuffer) { using (var bitmap = new Bitmap(BufferWi, BufferHt)) { using (Graphics graphics = Graphics.FromImage(bitmap)) { var text = TextMode == TextMode.Normal ? TextLines.Where(x => !String.IsNullOrEmpty(x)).ToList() : SplitTextIntoCharacters(TextLines); int numberLines = text.Count(); SizeF textsize = new SizeF(0, 0); foreach (string t in text) { if (!String.IsNullOrEmpty(t)) { var size = graphics.MeasureString(t, Font); if (size.Width > textsize.Width) { textsize = size; } } } _maxTextSize = Convert.ToInt32(textsize.Width * .95); int maxht = Convert.ToInt32(textsize.Height * numberLines); int offsetLeft = (((BufferWi - _maxTextSize) / 2) * 2 + Position) / 2; int offsetTop = (((BufferHt - maxht) / 2) * 2 + Position) / 2; double intervalPosition = (GetEffectTimeIntervalPosition(frame) * Speed) % 1; Point point; switch (Direction) { case TextDirection.Left: // left int leftX = BufferWi - (int)(intervalPosition * (textsize.Width + BufferWi)); point = new Point(Convert.ToInt32(CenterStop ? Math.Max(leftX, (BufferWi - (int)textsize.Width) / 2) : leftX), offsetTop); DrawText(text, graphics, point); break; case TextDirection.Right: // right int rightX = -_maxTextSize + (int)(intervalPosition * (_maxTextSize + BufferWi)); point = new Point(Convert.ToInt32(CenterStop ? Math.Min(rightX, (BufferWi - (int)textsize.Width) / 2) : rightX), offsetTop); DrawText(text, graphics, point); break; case TextDirection.Up: // up int upY = BufferHt - (int)(((textsize.Height * numberLines) + BufferHt) * intervalPosition); point = new Point(offsetLeft, Convert.ToInt32(CenterStop ? Math.Max(upY, (BufferHt - (int)(textsize.Height * numberLines)) / 2): upY)); DrawText(text, graphics, point); break; case TextDirection.Down: // down int downY = -(int)(textsize.Height * numberLines) + (int)(((textsize.Height * numberLines) + BufferHt) * intervalPosition); point = new Point(offsetLeft, Convert.ToInt32(CenterStop ? Math.Min(downY, (BufferHt - (int)(textsize.Height * numberLines)) / 2) : downY)); DrawText(text, graphics, point); break; default: // no movement - centered point = new Point(((BufferWi - _maxTextSize) / 2) + PositionX, offsetTop); DrawText(text, graphics, point); break; } // copy to frameBuffer for (int x = 0; x < BufferWi; x++) { for (int y = 0; y < BufferHt; y++) { Color color = bitmap.GetPixel(x, BufferHt - y - 1); if (!EmptyColor.Equals(color)) { var hsv = HSV.FromRGB(color); hsv.V = hsv.V * LevelCurve.GetValue(GetEffectTimeIntervalPosition(frame) * 100) / 100; frameBuffer.SetPixel(x, y, hsv); } } } } } }
protected override void RenderEffect(int frame, ref PixelFrameBuffer frameBuffer) { int x, y, n, colorIdx; int colorcnt = Colors.Count(); int barCount = Repeat * colorcnt; double position = (GetEffectTimeIntervalPosition(frame) * Speed) % 1; if (barCount < 1) { barCount = 1; } if (Direction < BarDirection.Left || Direction == BarDirection.AlternateUp || Direction == BarDirection.AlternateDown) { int barHt = BufferHt / barCount + 1; if (barHt < 1) { barHt = 1; } int halfHt = BufferHt / 2; int blockHt = colorcnt * barHt; if (blockHt < 1) { blockHt = 1; } int fOffset = (int)(position * blockHt * Repeat); // : Speed * frame / 4 % blockHt); if (Direction == BarDirection.AlternateUp || Direction == BarDirection.AlternateDown) { fOffset = (int)(Math.Floor(position * barCount) * barHt); } int indexAdjust = 1; for (y = 0; y < BufferHt; y++) { n = y + fOffset; colorIdx = ((n + indexAdjust) % blockHt) / barHt; //we need the integer division here to make things work double colorPosition = ((double)(n + indexAdjust) / barHt) - ((n + indexAdjust) / barHt); Color c = Colors[colorIdx].GetColorAt(colorPosition); var hsv = HSV.FromRGB(c); if (Highlight && (n + indexAdjust) % barHt == 0) { hsv.S = 0.0f; } if (Show3D) { hsv.V *= (float)(barHt - (n + indexAdjust) % barHt - 1) / barHt; } hsv.V = hsv.V * LevelCurve.GetValue(GetEffectTimeIntervalPosition(frame) * 100) / 100; switch (Direction) { case BarDirection.Down: case BarDirection.AlternateDown: // down for (x = 0; x < BufferWi; x++) { frameBuffer.SetPixel(x, y, hsv); } break; case BarDirection.Expand: // expand if (y <= halfHt) { for (x = 0; x < BufferWi; x++) { frameBuffer.SetPixel(x, y, hsv); frameBuffer.SetPixel(x, BufferHt - y - 1, hsv); } } break; case BarDirection.Compress: // compress if (y >= halfHt) { for (x = 0; x < BufferWi; x++) { frameBuffer.SetPixel(x, y, hsv); frameBuffer.SetPixel(x, BufferHt - y - 1, hsv); } } break; default: // up & AlternateUp for (x = 0; x < BufferWi; x++) { frameBuffer.SetPixel(x, BufferHt - y - 1, hsv); } break; } } } else { int barWi = BufferWi / barCount + 1; if (barWi < 1) { barWi = 1; } int halfWi = BufferWi / 2; int blockWi = colorcnt * barWi; if (blockWi < 1) { blockWi = 1; } int fOffset = (int)(position * blockWi * Repeat); if (Direction > BarDirection.AlternateDown) { fOffset = (int)(Math.Floor(position * barCount) * barWi); } for (x = 0; x < BufferWi; x++) { n = x + fOffset; colorIdx = ((n + 1) % blockWi) / barWi; //we need the integer division here to make things work double colorPosition = ((double)(n + 1) / barWi) - ((n + 1) / barWi); Color c = Colors[colorIdx].GetColorAt(colorPosition); var hsv = HSV.FromRGB(c); if (Highlight && n % barWi == 0) { hsv.S = 0.0f; } if (Show3D) { hsv.V *= (float)(barWi - n % barWi - 1) / barWi; } hsv.V = hsv.V * LevelCurve.GetValue(GetEffectTimeIntervalPosition(frame) * 100) / 100; switch (Direction) { case BarDirection.Right: case BarDirection.AlternateRight: // right for (y = 0; y < BufferHt; y++) { frameBuffer.SetPixel(BufferWi - x - 1, y, hsv); } break; case BarDirection.HExpand: // H-expand if (x <= halfWi) { for (y = 0; y < BufferHt; y++) { frameBuffer.SetPixel(x, y, hsv); frameBuffer.SetPixel(BufferWi - x - 1, y, hsv); } } break; case BarDirection.HCompress: // H-compress if (x >= halfWi) { for (y = 0; y < BufferHt; y++) { frameBuffer.SetPixel(x, y, hsv); frameBuffer.SetPixel(BufferWi - x - 1, y, hsv); } } break; default: // left & AlternateLeft for (y = 0; y < BufferHt; y++) { frameBuffer.SetPixel(x, y, hsv); } break; } } } }
protected override void RenderEffect(int frame, IPixelFrameBuffer frameBuffer) { var intervalPos = GetEffectTimeIntervalPosition(frame); var intervalPosFactor = intervalPos * 100; double level = LevelCurve.GetValue(intervalPosFactor) / 100; double rangeAdjust = CalculateRange(intervalPosFactor); int i, x, y, xc, yc, ColorIdx; int mod1440, d_mod; srand(1); double state = frame * CalculateSpeed(intervalPosFactor); float R, r, d, d_orig, t; double hyp, x2, y2; HSV hsv = new HSV(); // we will define an hsv color model. int colorcnt = Colors.Count; xc = (int)(BufferWi / 2); // 20x100 flex strips with 2 fols per strip = 40x50 yc = (int)(BufferHt / 2); R = (float)(xc * (OCR / 100.0)); // Radius of the large circle just fits in the width of model r = (float)(xc * (ICR / 100.0)); // start little circle at 1/4 of max width if (r > R) { r = R; } d = (float)(xc * (CalculateDistance(intervalPosFactor) / 100.0)); // A hypotrochoid is a roulette traced by a point attached to a circle of radius r rolling around the inside of a fixed circle of radius R, where the point is a distance d from the center of the interior circle. //The parametric equations for a hypotrochoid are:[citation needed] // // more info: http://en.wikipedia.org/wiki/Hypotrochoid // try { mod1440 = Convert.ToInt32(state % 1440); d_orig = d; for (i = 1; i <= CalculateSpirographRange(intervalPosFactor) * 18; i++) { if (Animate) { d = (int)(d_orig + state / 2) % 100; // should we modify the distance variable each pass through? } t = (float)((i + mod1440) * Math.PI / 180); x = Convert.ToInt32((R - r) * Math.Cos(t) + d * Math.Cos(((R - r) / r) * t) + xc); y = Convert.ToInt32((R - r) * Math.Sin(t) + d * Math.Sin(((R - r) / r) * t) + yc); if (colorcnt > 0) { d_mod = (int)Math.Round(rangeAdjust / colorcnt); } else { d_mod = 1; } x2 = Math.Pow((x - xc), 2); y2 = Math.Pow((y - yc), 2); hyp = Math.Sqrt(x2 + y2) / rangeAdjust * 100.0; switch (Type) { case ColorType.Random: ColorIdx = _random.Next(0, colorcnt); // Select random numbers from 0 up to number of colors the user has added. break; case ColorType.Rainbow: ColorIdx = 1; hsv.H = (float)(rand() % 1000) / 1000.0f; hsv.S = 1.0f; hsv.V = 1.0f; break; default: ColorIdx = (int)(hyp / d_mod); break; } if (ColorIdx >= colorcnt) { ColorIdx = colorcnt - 1; } if (Type != ColorType.Rainbow) { hsv = HSV.FromRGB(Colors[ColorIdx].GetColorAt((intervalPosFactor) / 100)); hsv.V = hsv.V * level; } frameBuffer.SetPixel(x, y, hsv); } } catch { } }
protected override void RenderEffect(int frame, ref PixelFrameBuffer frameBuffer) { if (StringCount == 1) { return; } var mod100 = (Speed * frame % (101 - Explosions) * 20); HSV hsv; if (mod100 == 0) { var x25 = (int)(BufferWi * 0.25); var x75 = (int)(BufferWi * 0.75); var y25 = (int)(BufferHt * 0.25); var y75 = (int)(BufferHt * 0.75); var startX = x25 + (Rand() % (x75 - x25)); var startY = y25 + (Rand() % (y75 - y25)); // Create new bursts hsv = Colors.Count > 0 ? HSV.FromRGB(Colors[Rand() % Colors.Count]) : HSV.FromRGB(Color.White); int idxFlakes = 0; for (int i = 0; i < Particles; i++) { do { idxFlakes = (idxFlakes + 1) % MaxFlakes; } while (_fireworkBursts[idxFlakes].Active); _fireworkBursts[idxFlakes].Reset(startX, startY, true, Velocity, hsv); } } else { for (int i = 0; i < MaxFlakes; i++) { // ... active flakes: if (_fireworkBursts[i].Active) { // 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].Active = false; continue; } // If this flake hit the earth, time to switch it off if (_fireworkBursts[i].Y >= BufferHt) { _fireworkBursts[i].Active = 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].Active = false; } } } } double position = GetEffectTimeIntervalPosition(frame); double level = LevelCurve.GetValue(position * 100) / 100; for (int i = 0; i < 1000; i++) { if (_fireworkBursts[i].Active) { var v = (float)(((ParticalFade * 10.0) - _fireworkBursts[i].Cycles) / (ParticalFade * 10.0)); if (v < 0) { v = 0.0f; } hsv = _fireworkBursts[i].HSV; hsv.V = v * level; frameBuffer.SetPixel((int)_fireworkBursts[i].X, (int)_fireworkBursts[i].Y, hsv); } } }
protected override void RenderEffect(int frame, IPixelFrameBuffer frameBuffer) { if (StringCount == 1) { return; } int colorcnt = ColorGradients.Count; for (int i = 0; i < _maxFlakes; i++) { if (_fireworkBursts[i].StartPeriod == frame) { _fireworkBursts[i].Active = true; } // ... active flakes: if (_fireworkBursts[i].Active) { // 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 (_fireworkBursts[i].Cycles >= _maxFlakes) { _fireworkBursts[i].Active = false; continue; } // If this flake hit the earth or is out of bounds, time to switch it off if (_fireworkBursts[i].Y >= BufferHt || _fireworkBursts[i].Y < 0 || _fireworkBursts[i].X < 0 || _fireworkBursts[i].X >= BufferWi) { _fireworkBursts[i].Active = false; } } } double position = GetEffectTimeIntervalPosition(frame); double level = LevelCurve.GetValue(position * 100) / 100; for (int i = 0; i < _maxFlakes; i++) { if (_fireworkBursts[i].Active) { var v = (float)(((ParticalFade * 10.0) - _fireworkBursts[i].Cycles) / (ParticalFade * 10.0)); if (v < 0) { v = 0.0f; } switch (ColorType) { case FireworksColorType.Range: //Random two colors are selected from the list for each Firework. _fireworkBursts[i].HSV = SetRangeColor(HSV.FromRGB(ColorGradients[Rand() % colorcnt].GetColorAt((GetEffectTimeIntervalPosition(frame) * 100) / 100)), HSV.FromRGB(ColorGradients[Rand() % colorcnt].GetColorAt((GetEffectTimeIntervalPosition(frame) * 100) / 100))); break; case FireworksColorType.Palette: //All colors are used _fireworkBursts[i].HSV = HSV.FromRGB(ColorGradients[Rand() % colorcnt].GetColorAt((GetEffectTimeIntervalPosition(frame) * 100) / 100)); break; case FireworksColorType.RainBow: //No user colors are used for Rainbow effect. _fireworkBursts[i].HSV.H = (float)(Rand() % 1000) / 1000.0f; _fireworkBursts[i].HSV.S = 1.0f; _fireworkBursts[i].HSV.V = 1.0f; break; case FireworksColorType.Standard: _fireworkBursts[i].HSV = HSV.FromRGB(ColorGradients[_fireworkBursts[i].ColorLocation].GetColorAt((GetEffectTimeIntervalPosition(frame) * 100) / 100)); break; } HSV hsv = _fireworkBursts[i].HSV; hsv.V = v * level; frameBuffer.SetPixel((int)_fireworkBursts[i].X, (int)_fireworkBursts[i].Y, hsv); } } }
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); } } }
protected override void RenderEffect(int frame, IPixelFrameBuffer frameBuffer) { var swagArray = new List <int>(); int curtainDir, xlimit, middle, ylimit; int swaglen = BufferHt > 1 ? Swag * BufferWi / 40 : 0; double position = (GetEffectTimeIntervalPosition(frame) * Speed) % 1; double level = LevelCurve.GetValue(GetEffectTimeIntervalPosition(frame) * 100) / 100; if (swaglen > 0) { double a = (double)(BufferHt - 1) / (swaglen * swaglen); for (int x = 0; x < swaglen; x++) { swagArray.Add((int)(a * x * x)); } } if (Direction < CurtainDirection.CurtainOpenClose) { if (Direction == CurtainDirection.CurtainOpen) { xlimit = (int)((position * BufferWi) + (swaglen * position * 2)); ylimit = (int)((position * BufferHt) + (swaglen * position * 2)); } else { xlimit = (int)((position * BufferWi) - (swaglen * (1 - position) * 2)); ylimit = (int)((position * BufferHt) - (swaglen * (1 - position) * 2)); } } else { if (Direction == CurtainDirection.CurtainOpenClose) { xlimit = (int)(position <= .5 ? (position * 2 * BufferWi) + (swaglen * position * 4) : ((position - .5) * 2 * BufferWi) - (swaglen * (1 - position) * 4)); ylimit = (int)(position <= .5 ? (position * 2 * BufferHt) + (swaglen * position * 4) : ((position - .5) * 2 * BufferHt) - (swaglen * (1 - position) * 4)); } else { xlimit = (int)(position <= .5 ? (position * 2 * BufferWi) - (swaglen * (0.5 - position) * 4) : ((position - .5) * 2 * BufferWi) + (swaglen * position * 2)); ylimit = (int)(position <= .5 ? (position * 2 * BufferHt) - (swaglen * (0.5 - position) * 4) : ((position - .5) * 2 * BufferHt) + (swaglen * position * 2)); } } if (Direction < CurtainDirection.CurtainOpenClose) { curtainDir = (int)Direction % 2; } else if (xlimit < _lastCurtainLimit - swaglen * 2) { curtainDir = 1 - _lastCurtainDir; } else { curtainDir = _lastCurtainDir; } _lastCurtainDir = curtainDir; _lastCurtainLimit = xlimit; if (curtainDir == 0) { xlimit = BufferWi - xlimit - 1; ylimit = BufferHt - ylimit - 1; } switch (Edge) { case CurtainEdge.Left: // left DrawCurtain(true, xlimit, swagArray, frameBuffer, level, (BufferWi - 1)); break; case CurtainEdge.Center: // center middle = (xlimit + 1) / 2; DrawCurtain(true, middle, swagArray, frameBuffer, level, (BufferWi / 2 - 1)); DrawCurtain(false, middle, swagArray, frameBuffer, level, (BufferWi / 2 - 1)); break; case CurtainEdge.Right: // right DrawCurtain(false, xlimit, swagArray, frameBuffer, level, (BufferWi - 1)); break; case CurtainEdge.Bottom: // bottom DrawCurtainVertical(true, ylimit, swagArray, frameBuffer, level, (BufferHt - 1)); break; case CurtainEdge.Middle: // middle middle = (ylimit + 1) / 2; DrawCurtainVertical(true, middle, swagArray, frameBuffer, level, (BufferHt / 2 - 1)); DrawCurtainVertical(false, middle, swagArray, frameBuffer, level, (BufferHt / 2 - 1)); break; case CurtainEdge.Top: // top DrawCurtainVertical(false, ylimit, swagArray, frameBuffer, level, (BufferHt - 1)); break; } }
private void addIntentsToElement(Element element, double[] allPointsTimeOrdered, Color?color = null) { if (element != null) { double lastPosition = allPointsTimeOrdered[0]; TimeSpan lastEnd = TimeSpan.Zero; for (var i = 1; i < allPointsTimeOrdered.Length; i++) { double position = allPointsTimeOrdered[i]; LightingValue startValue; LightingValue endValue; if (color == null) { startValue = new LightingValue(ColorGradient.GetColorAt(lastPosition), LevelCurve.GetValue(lastPosition * 100) / 100); endValue = new LightingValue(ColorGradient.GetColorAt(position), LevelCurve.GetValue(position * 100) / 100); } else { startValue = new LightingValue((Color)color, (ColorGradient.GetProportionOfColorAt(lastPosition, (Color)color) * LevelCurve.GetValue(lastPosition * 100) / 100)); endValue = new LightingValue((Color)color, (ColorGradient.GetProportionOfColorAt(position, (Color)color) * LevelCurve.GetValue(position * 100) / 100)); } TimeSpan startTime = lastEnd; TimeSpan timeSpan = TimeSpan.FromMilliseconds(TimeSpan.TotalMilliseconds * (position - lastPosition)); if (startValue.Intensity.Equals(0f) && endValue.Intensity.Equals(0f)) { lastPosition = position; lastEnd = startTime + timeSpan; continue; } IIntent intent = new LightingIntent(startValue, endValue, timeSpan); _elementData.AddIntentForElement(element.Id, intent, startTime); lastPosition = position; lastEnd = startTime + timeSpan; } } }
protected override void RenderEffect(int frame, IPixelFrameBuffer frameBuffer) { double pos = GetEffectTimeIntervalPosition(frame); double intervalPosFactor = pos * 100; double level = LevelCurve.GetValue(intervalPosFactor) / 100; double blendLevel = BlendCurve.GetValue(intervalPosFactor) / 100; double backgroundLevelCurve = BackgroundLevelCurve.GetValue(intervalPosFactor) / 100; HSV backgroundhsv = HSV.FromRGB(BackgroundColor.GetColorAt(pos)); int x, y, mod, b; float V; int cycleLen = frame * Speed; int pixelsPerBranch = (int)(0.5 + (double)BufferHt / Branches); if (pixelsPerBranch == 0) { pixelsPerBranch = 1; } if (frame == _xLimit) { _treeWidth = 0; _xLimit += BufferWi; } _treeWidth++; for (y = 0; y < BufferHt; y++) { mod = y % pixelsPerBranch; if (mod == 0) { mod = pixelsPerBranch; } V = ToggleBlend //Fade between branches ? (float)(1 - (1.0 * mod / pixelsPerBranch) * (1 - blendLevel)) : (float)((1.0 * mod / pixelsPerBranch) * (blendLevel)); backgroundhsv.V = backgroundLevelCurve * V; // we have now set the color for the background tree Branch = (int)((y - 1) / pixelsPerBranch); if (_branchColor >= Colors.Count || Branch == 0) { _branchColor = 0; } _row = pixelsPerBranch - mod; // now row=0 is bottom of branch, row=1 is one above bottom // mod = which pixel we are in the branch // mod=1,row=pixels_per_branch-1 top picrl in branch // mod=2, second pixel down into branch // mod=pixels_per_branch,row=0 last pixel in branch // // row = 0, the $p is in the bottom row of tree // row =1, the $p is in second row from bottom b = (int)((cycleLen) / BufferWi) % Branches; // what branch we are on based on frame # // // b = 0, we are on bottomow row of tree during frames 1 to BufferWi // b = 1, we are on second row from bottom, frames = BufferWi+1 to 2*BufferWi // b = 2, we are on third row from bottome, frames - 2*BufferWi+1 to 3*BufferWi for (x = 0; x < BufferWi; x++) { Color col = backgroundhsv.ToRGB(); M = (x % 6); // m=0, 1sr strand // m=1, 2nd strand // m=5, last strand in 6 strand pattern switch (ColorType) { case TreeColorType.Twinkle: _colorIdx = Rand(0, Colors.Count); break; case TreeColorType.AlternatePixel: _colorIdx = (x % Colors.Count); break; case TreeColorType.Static: _colorIdx = _branchColor; break; case TreeColorType.Alternate: break; } switch (BranchDirection) { case TreeBranchDirection.UpRight: case TreeBranchDirection.DownRight: case TreeBranchDirection.UpLeft: case TreeBranchDirection.DownLeft: if (Branch <= b && x <= _treeWidth && (((_row == 3 && (M == 0 || M == 5)) || ((_row == 2 && (M == 1 || M == 4)) || ((_row == 1 && (M == 2 || M == 3))))))) { col = Colors[_colorIdx].GetColorAt(pos); } break; case TreeBranchDirection.Up: case TreeBranchDirection.Down: if (Branch <= b && (((_row == 3 && (M == 0 || M == 5)) || ((_row == 2 && (M == 1 || M == 4)) || ((_row == 1 && (M == 2 || M == 3))))))) { col = Colors[_colorIdx].GetColorAt(pos); } break; case TreeBranchDirection.Left: if ((BufferWi - x) <= _treeWidth && (((_row == 3 && (M == 0 || M == 5)) || ((_row == 2 && (M == 1 || M == 4)) || ((_row == 1 && (M == 2 || M == 3))))))) { col = Colors[_colorIdx].GetColorAt(pos); } break; case TreeBranchDirection.Alternate: if (Branch % 2 != 0) { if ((BufferWi - x) <= _treeWidth && (((_row == 3 && (M == 0 || M == 5)) || ((_row == 2 && (M == 1 || M == 4)) || ((_row == 1 && (M == 2 || M == 3))))))) { col = Colors[_colorIdx].GetColorAt(pos); } } else { if (x <= _treeWidth && (((_row == 3 && (M == 0 || M == 5)) || ((_row == 2 && (M == 1 || M == 4)) || ((_row == 1 && (M == 2 || M == 3))))))) { col = Colors[_colorIdx].GetColorAt(pos); } } break; case TreeBranchDirection.Right: if (x <= _treeWidth && (((_row == 3 && (M == 0 || M == 5)) || ((_row == 2 && (M == 1 || M == 4)) || ((_row == 1 && (M == 2 || M == 3))))))) { col = Colors[_colorIdx].GetColorAt(pos); } break; case TreeBranchDirection.None: if (((((_row == 3 && (M == 0 || M == 5)) || ((_row == 2 && (M == 1 || M == 4)) || ((_row == 1 && (M == 2 || M == 3)))))))) { col = Colors[_colorIdx].GetColorAt(pos); } break; } if (level < 1) { HSV hsv = HSV.FromRGB(col); hsv.V = hsv.V * level; //adjusts overall intensity col = hsv.ToRGB(); } switch (BranchDirection) { case TreeBranchDirection.Down: case TreeBranchDirection.DownRight: frameBuffer.SetPixel(x, BufferHt - y, col); break; case TreeBranchDirection.UpLeft: frameBuffer.SetPixel(BufferWi - x, y, col); break; case TreeBranchDirection.DownLeft: frameBuffer.SetPixel(BufferWi - x, BufferHt - y, col); break; default: frameBuffer.SetPixel(x, y, col); break; } } _colorIdx = (Branch % Colors.Count); } }
protected override void RenderEffect(int frame, IPixelFrameBuffer frameBuffer) { int colorcntOutSide = OutSideColor.Count; int colorcntInside = InnerColor.Count; int minDirection = 1; int maxDirection = 360; // create new SnowFlakes and maintain maximum number as per users selection. int flakeCount = SnowflakeEffect == SnowflakeEffect.Explode && frame < FlakeCount ? 1 : FlakeCount; for (int i = 0; i < flakeCount; i++) { double position = RandomSpeed ? (double)_random.Next(MinSpeed, MaxSpeed) / 5 : (double)Speed / 5; if (_snowFlakes.Count >= FlakeCount) { continue; } SnowFlakeClass m = new SnowFlakeClass(); if (SnowflakeEffect == SnowflakeEffect.RandomDirection) { minDirection = MinDirection; maxDirection = MaxDirection; } int direction; if (SnowflakeEffect == SnowflakeEffect.None) { direction = _random.Next(145, 215); //Set Range for standard Snowflakes as we don't want to just have them going straight down or two dirctions like the original Snowflake effect. } else { //This is to generate random directions between the Min and Max values //However if Someone makes the MaxDirection lower then the Min Direction then //the new direction will be the inverserve of the Min and Max effectively changing //the range from a downward motion to an upward motion, increasing the feature capability. direction = maxDirection <= minDirection ? (_random.Next(1, 3) == 1 ? _random.Next(1, maxDirection) : _random.Next(minDirection, 360)) : _random.Next(minDirection, maxDirection); } //Moving (direction) if (direction > 0 && direction <= 90) { m.DeltaX = ((double)direction / 90) * position; m.DeltaY = ((double)Math.Abs(direction - 90) / 90) * position; } else if (direction > 90 && direction <= 180) { m.DeltaX = ((double)Math.Abs(direction - 180) / 90) * position; m.DeltaY = (-1 * ((double)Math.Abs(direction - 90) / 90)) * position; } else if (direction > 180 && direction <= 270) { m.DeltaX = (-1 * ((double)Math.Abs(direction - 180) / 90)) * position; m.DeltaY = (-1 * ((double)Math.Abs(direction - 270) / 90)) * position; } else if (direction > 270 && direction <= 360) { m.DeltaX = (-1 * ((double)Math.Abs(direction - 360) / 90)) * position; m.DeltaY = ((double)Math.Abs(270 - direction) / 90) * position; } //Start position for Snowflake if (SnowflakeEffect == SnowflakeEffect.Explode) //Will start in the centre of the grid { m.X = BufferWi / 2; m.Y = BufferHt / 2; } else { m.X = _random.Next() % BufferWi; if (frame == 0) { m.Y = _random.Next() % BufferHt; //This is used so for the first lot of Snowflakes they will start in a random position and then fall from the edge. } else { m.Y = BufferHt; } } m.DeltaXOrig = m.DeltaX; m.DeltaYOrig = m.DeltaY; m.Type = SnowflakeType == SnowflakeType.Random ? RandomFlakeType <SnowflakeType>() : SnowflakeType; //Set the SnowFlake colors during the creation of the snowflake. switch (ColorType) { case SnowflakeColorType.Range: //Random two colors are selected from the list for each SnowFlake and then the color range between them are used. m.OuterHsv = SetRangeColor(HSV.FromRGB(OutSideColor[rand() % colorcntOutSide].GetColorAt((GetEffectTimeIntervalPosition(frame) * 100) / 100)), HSV.FromRGB(OutSideColor[rand() % colorcntOutSide].GetColorAt((GetEffectTimeIntervalPosition(frame) * 100) / 100))); m.InnerHsv = SetRangeColor(HSV.FromRGB(InnerColor[rand() % colorcntInside].GetColorAt((GetEffectTimeIntervalPosition(frame) * 100) / 100)), HSV.FromRGB(InnerColor[rand() % colorcntInside].GetColorAt((GetEffectTimeIntervalPosition(frame) * 100) / 100))); break; case SnowflakeColorType.Palette: //All user colors are used m.OuterHsv = HSV.FromRGB(OutSideColor[rand() % colorcntOutSide].GetColorAt((GetEffectTimeIntervalPosition(frame) * 100) / 100)); m.InnerHsv = HSV.FromRGB(InnerColor[rand() % colorcntInside].GetColorAt((GetEffectTimeIntervalPosition(frame) * 100) / 100)); break; default: m.InnerHsv = HSV.FromRGB(InnerColor[rand() % colorcntInside].GetColorAt((GetEffectTimeIntervalPosition(frame) * 100) / 100)); break; } m.HsvBrightness = RandomBrightness ? _random.NextDouble() * (1.0 - .25) + .25 : 1; //Adds a random brightness to each Snowflake making it look more realistic _snowFlakes.Add(m); } // render all SnowFlakes foreach (SnowFlakeClass snowFlakes in _snowFlakes) { snowFlakes.DeltaX += snowFlakes.DeltaXOrig; snowFlakes.DeltaY += snowFlakes.DeltaYOrig; for (int c = 0; c < 1; c++) { //Sets the new position the SnowFlake is moving to int colorX = (snowFlakes.X + Convert.ToInt32(snowFlakes.DeltaX) - (BufferWi / 100)); int colorY = (snowFlakes.Y + Convert.ToInt32(snowFlakes.DeltaY) + (BufferHt / 100)); if (SnowflakeEffect != SnowflakeEffect.Explode) //Modifies the colorX and colorY when the Explode effect is not used. { colorX = colorX % BufferWi; colorY = colorY % BufferHt; } if (ColorType == SnowflakeColorType.RainBow) //No user colors are used for Rainbow effect. Color selection for user will be hidden. { snowFlakes.OuterHsv.H = (float)(rand() % 1000) / 1000.0f; snowFlakes.OuterHsv.S = 1.0f; snowFlakes.OuterHsv.V = 1.0f; } //Added the color and then adjusts brightness based on effect time position, randon Brightness and over all brightness level. HSV hsvInner = snowFlakes.OuterHsv; HSV hsvOuter = snowFlakes.InnerHsv; hsvInner.V *= snowFlakes.HsvBrightness * LevelCurve.GetValue(GetEffectTimeIntervalPosition(frame) * 100) / 100; hsvOuter.V *= snowFlakes.HsvBrightness * LevelCurve.GetValue(GetEffectTimeIntervalPosition(frame) * 100) / 100; if (colorX >= BufferWi || colorY >= BufferHt || colorX <= 0 || colorY <= 0) { snowFlakes.Expired = true; //flags SnowFlakes that have reached the end of the grid as expiried. Allows new Snowflakes to be created. break; } //Render SnowFlakes switch (snowFlakes.Type) { case SnowflakeType.Single: // single node frameBuffer.SetPixel(colorX, colorY, hsvInner); break; case SnowflakeType.Five: // 5 nodes frameBuffer.SetPixel(colorX, colorY, hsvOuter); //Inner point of the Flake frameBuffer.SetPixel(colorX - 1, colorY, hsvInner); frameBuffer.SetPixel(colorX + 1, colorY, hsvInner); frameBuffer.SetPixel(colorX, colorY - 1, hsvInner); frameBuffer.SetPixel(colorX, colorY + 1, hsvInner); break; case SnowflakeType.Three: // 3 nodes frameBuffer.SetPixel(colorX, colorY, hsvOuter); //Inner point of the Flake if (rand() % 100 > 50) { frameBuffer.SetPixel(colorX - 1, colorY, hsvInner); frameBuffer.SetPixel(colorX + 1, colorY, hsvInner); } else { frameBuffer.SetPixel(colorX, colorY - 1, hsvInner); frameBuffer.SetPixel(colorX, colorY + 1, hsvInner); } break; case SnowflakeType.Nine: // 9 nodes frameBuffer.SetPixel(colorX, colorY, hsvOuter); //Inner point of the Flake int i; for (i = 1; i <= 2; i++) { frameBuffer.SetPixel(colorX - i, colorY, hsvInner); frameBuffer.SetPixel(colorX + i, colorY, hsvInner); frameBuffer.SetPixel(colorX, colorY - i, hsvInner); frameBuffer.SetPixel(colorX, colorY + i, hsvInner); } break; case SnowflakeType.Thirteen: // 13 nodes frameBuffer.SetPixel(colorX, colorY, hsvOuter); //Inner point of the Flake frameBuffer.SetPixel(colorX - 1, colorY, hsvInner); frameBuffer.SetPixel(colorX + 1, colorY, hsvInner); frameBuffer.SetPixel(colorX, colorY - 1, hsvInner); frameBuffer.SetPixel(colorX, colorY + 1, hsvInner); frameBuffer.SetPixel(colorX - 1, colorY + 2, hsvInner); frameBuffer.SetPixel(colorX + 1, colorY + 2, hsvInner); frameBuffer.SetPixel(colorX - 1, colorY - 2, hsvInner); frameBuffer.SetPixel(colorX + 1, colorY - 2, hsvInner); frameBuffer.SetPixel(colorX + 2, colorY - 1, hsvInner); frameBuffer.SetPixel(colorX + 2, colorY + 1, hsvInner); frameBuffer.SetPixel(colorX - 2, colorY - 1, hsvInner); frameBuffer.SetPixel(colorX - 2, colorY + 1, hsvInner); break; case SnowflakeType.FortyFive: // 45 nodes int ii = 4; for (int j = -4; j < 5; j++) { if (colorX <= BufferWi && colorY <= BufferHt) { frameBuffer.SetPixel(colorX + j, colorY + ii, hsvInner); } ii--; } for (int j = -4; j < 5; j++) { if (colorX <= BufferWi && colorY <= BufferHt) { frameBuffer.SetPixel(colorX + j, colorY + j, hsvInner); } } if (colorX <= BufferWi && colorY <= BufferHt) { frameBuffer.SetPixel(colorX - 2, colorY + 3, hsvInner); frameBuffer.SetPixel(colorX - 3, colorY + 2, hsvInner); frameBuffer.SetPixel(colorX - 3, colorY - 2, hsvInner); frameBuffer.SetPixel(colorX - 2, colorY - 3, hsvInner); frameBuffer.SetPixel(colorX + 2, colorY + 3, hsvInner); frameBuffer.SetPixel(colorX + 2, colorY - 3, hsvInner); frameBuffer.SetPixel(colorX + 3, colorY + 2, hsvInner); frameBuffer.SetPixel(colorX + 3, colorY - 2, hsvInner); } for (int j = -5; j < 6; j++) { if (colorX <= BufferWi && colorY <= BufferHt) { frameBuffer.SetPixel(colorX, colorY + j, hsvInner); } } for (int j = -5; j < 6; j++) { if (colorX <= BufferWi && colorY <= BufferHt) { frameBuffer.SetPixel(colorX + j, colorY, hsvInner); } } if (colorX <= BufferWi && colorY <= BufferHt) { frameBuffer.SetPixel(colorX, colorY, hsvOuter); //Inner point of the Flake } break; } } } // deletes SnowFlakes that have expired when reaching the edge of the grid, allowing new Snowflakes to be created. int snowFlakeNum = 0; while (snowFlakeNum < _snowFlakes.Count) { if (_snowFlakes[snowFlakeNum].Expired) { _snowFlakes.RemoveAt(snowFlakeNum); } else { snowFlakeNum++; } } }
protected override void RenderEffect(int frame, IPixelFrameBuffer frameBuffer) { int x, y, n, colorIdx; int colorcnt = Colors.Count(); int barCount = Repeat * colorcnt; double intervalPosFactor = GetEffectTimeIntervalPosition(frame) * 100; _negPosition = false; if (MovementType == MovementType.Iterations) { _position = (GetEffectTimeIntervalPosition(frame) * Speed) % 1; } else { var s = CalculateSpeed(intervalPosFactor); if (frame == 0) { _position = s; } var adj = s / 100 * FrameTime / 50d; _position += adj; //Adjust the speed setting for different frame rates with FrameTime / 50d //Debug.WriteLine($"S:{s}, PosFactor:{intervalPosFactor}, Frame:{frame}, FrameTime:{FrameTime}, Position:{_position}, Adj:{adj}"); _negPosition = _position < 0; } var workingPosition = Math.Abs(_position); if (barCount < 1) { barCount = 1; } double level = LevelCurve.GetValue(intervalPosFactor) / 100; var bufferHt = BufferHt; var bufferWi = BufferWi; if (Direction < BarDirection.Left || Direction == BarDirection.AlternateUp || Direction == BarDirection.AlternateDown) { int barHt = bufferHt / barCount + 1; if (barHt < 1) { barHt = 1; } int halfHt = bufferHt / 2; int blockHt = colorcnt * barHt; if (blockHt < 1) { blockHt = 1; } int fOffset = (int)(workingPosition * blockHt * Repeat); // : Speed * frame / 4 % blockHt); if (Direction == BarDirection.AlternateUp || Direction == BarDirection.AlternateDown) { fOffset = (int)(Math.Floor(workingPosition * barCount) * barHt); } var indexAdjust = 1; for (y = 0; y < bufferHt; y++) { n = y + fOffset; colorIdx = ((n + indexAdjust) % blockHt) / barHt; //we need the integer division here to make things work double colorPosition = (n + indexAdjust) % barHt / (double)barHt; Color c = Colors[colorIdx].GetColorAt(colorPosition); if (Highlight || Show3D) { var hsv = HSV.FromRGB(c); if (Highlight && (n + indexAdjust) % barHt == 0) { hsv.S = 0.0f; } if (Show3D) { hsv.V *= (float)(barHt - (n + indexAdjust) % barHt - 1) / barHt; } hsv.V *= level; c = hsv.ToRGB(); } else { if (level < 1) { HSV hsv = HSV.FromRGB(c); hsv.V *= level; c = hsv.ToRGB(); } } switch (Direction) { case BarDirection.Down: case BarDirection.AlternateDown: // dow if (_negPosition) { for (x = 0; x < bufferWi; x++) { frameBuffer.SetPixel(x, bufferHt - y - 1, c); } } else { for (x = 0; x < bufferWi; x++) { frameBuffer.SetPixel(x, y, c); } } break; case BarDirection.Compress: // expand if (_negPosition) { if (y <= halfHt) { for (x = 0; x < bufferWi; x++) { frameBuffer.SetPixel(x, y, c); frameBuffer.SetPixel(x, bufferHt - y - 1, c); } } } else { if (y >= halfHt) { for (x = 0; x < bufferWi; x++) { frameBuffer.SetPixel(x, y, c); frameBuffer.SetPixel(x, bufferHt - y - 1, c); } } } break; case BarDirection.Expand: // compress if (!_negPosition) { if (y <= halfHt) { for (x = 0; x < bufferWi; x++) { frameBuffer.SetPixel(x, y, c); frameBuffer.SetPixel(x, bufferHt - y - 1, c); } } } else { if (y >= halfHt) { for (x = 0; x < bufferWi; x++) { frameBuffer.SetPixel(x, y, c); frameBuffer.SetPixel(x, bufferHt - y - 1, c); } } } break; default: // up & AlternateUp if (!_negPosition) { for (x = 0; x < bufferWi; x++) { frameBuffer.SetPixel(x, bufferHt - y - 1, c); } } else { for (x = 0; x < bufferWi; x++) { frameBuffer.SetPixel(x, y, c); } } break; } } } else { int barWi = bufferWi / barCount + 1; if (barWi < 1) { barWi = 1; } int halfWi = bufferWi / 2; int blockWi = colorcnt * barWi; if (blockWi < 1) { blockWi = 1; } int fOffset = (int)(workingPosition * blockWi * Repeat); if (Direction > BarDirection.AlternateDown) { fOffset = (int)(Math.Floor(workingPosition * barCount) * barWi); } for (x = 0; x < bufferWi; x++) { n = x + fOffset; //we need the integer division here to make things work colorIdx = ((n + 1) % blockWi) / barWi; var colorPosition = (n + 1) % barWi / (double)barWi; Color c = Colors[colorIdx].GetColorAt(colorPosition); if (Highlight || Show3D) { var hsv = HSV.FromRGB(c); if (Highlight && (n + 1) % barWi == 0) { hsv.S = 0.0f; } if (Show3D) { hsv.V *= (float)(barWi - n % barWi - 1) / barWi; } hsv.V *= level; c = hsv.ToRGB(); } else { if (level < 1) { HSV hsv = HSV.FromRGB(c); hsv.V *= level; c = hsv.ToRGB(); } } switch (Direction) { case BarDirection.Right: case BarDirection.AlternateRight: // right for (y = 0; y < bufferHt; y++) { frameBuffer.SetPixel(_negPosition?x:bufferWi - x - 1, y, c); } break; case BarDirection.HExpand: // H-expand if (!_negPosition && x <= halfWi || _negPosition && x >= halfWi) { for (y = 0; y < bufferHt; y++) { frameBuffer.SetPixel(x, y, c); frameBuffer.SetPixel(bufferWi - x - 1, y, c); } } break; case BarDirection.HCompress: // H-compress if (!_negPosition && x >= halfWi || _negPosition && x <= halfWi) { for (y = 0; y < bufferHt; y++) { frameBuffer.SetPixel(x, y, c); frameBuffer.SetPixel(bufferWi - x - 1, y, c); } } break; default: // left & AlternateLeft for (y = 0; y < bufferHt; y++) { frameBuffer.SetPixel(_negPosition?bufferWi - x - 1:x, y, c); } break; } } } }
protected override void RenderEffectByLocation(int numFrames, PixelLocationFrameBuffer frameBuffer) { int repeat = ConfigureRepeat(); int maxframe = BufferHt; double position; var nodes = frameBuffer.ElementLocations.OrderBy(x => x.X).ThenBy(x => x.Y).GroupBy(x => x.X); for (int effectFrame = 0; effectFrame < numFrames; effectFrame++) { frameBuffer.CurrentFrame = effectFrame; double intervalPosFactor = GetEffectTimeIntervalPosition(effectFrame) * 100; if (MovementType == MovementType.Iterations) { position = (GetEffectTimeIntervalPosition(effectFrame) * Iterations) % 1; } else { _position += CalculateSpeed(intervalPosFactor) / 200; if (_position < 0) { _negPosition = true; position = -_position % 1; } else { _negPosition = false; position = _position % 1; } } int curState = (int)(TimeSpan.TotalMilliseconds * position * repeat); int frame = (BufferHt * curState / (int)TimeSpan.TotalMilliseconds) % maxframe; double offset = curState / TimeSpan.TotalMilliseconds; double level = LevelCurve.GetValue(GetEffectTimeIntervalPosition(effectFrame) * 100) / 100; switch (MovementType) { case MovementType.Speed: { if (!_negPosition) { offset = -offset; } break; } default: { if (Direction == Direction.Forward) { offset = -offset; } break; } } int bufferDim = 0; if (ButterflyType == ButterflyType.Type1 || ButterflyType == ButterflyType.Type4) { bufferDim = BufferHt + BufferWi; } else if (ButterflyType == ButterflyType.Type5) { bufferDim = BufferHt * BufferWi; } foreach (IGrouping <int, ElementLocation> elementLocations in nodes) { foreach (var elementLocation in elementLocations) { CalculatePixel(elementLocation.X, elementLocation.Y, bufferDim, offset, frame, maxframe, level, frameBuffer); } } } }
protected override void RenderEffect(int effectFrame, IPixelFrameBuffer frameBuffer) { int repeat = ConfigureRepeat(); int maxframe = BufferHt; double position; double intervalPosFactor = GetEffectTimeIntervalPosition(effectFrame) * 100; if (MovementType == MovementType.Iterations) { position = (GetEffectTimeIntervalPosition(effectFrame) * Iterations) % 1; } else { _position += CalculateSpeed(intervalPosFactor) / 200; if (_position < 0) { _negPosition = true; position = -_position % 1; } else { _negPosition = false; position = _position % 1; } } int curState = (int)(TimeSpan.TotalMilliseconds * position * repeat); int frame = (BufferHt * curState / (int)TimeSpan.TotalMilliseconds) % maxframe; double offset = curState / TimeSpan.TotalMilliseconds; double level = LevelCurve.GetValue(GetEffectTimeIntervalPosition(effectFrame) * 100) / 100; switch (MovementType) { case MovementType.Speed: { if (!_negPosition) { offset = -offset; } break; } default: { if (Direction == Direction.Forward) { offset = -offset; } break; } } int bufferDim = 0; if (ButterflyType == ButterflyType.Type1 || ButterflyType == ButterflyType.Type4) { bufferDim = BufferHt + BufferWi; } else if (ButterflyType == ButterflyType.Type5) { bufferDim = BufferHt * BufferWi; } for (int x = 0; x < BufferWi; x++) { for (int y = 0; y < BufferHt; y++) { CalculatePixel(x, y, bufferDim, offset, frame, maxframe, level, frameBuffer); } } }
protected override void RenderEffect(int frame, IPixelFrameBuffer frameBuffer) { double level = LevelCurve.GetValue(GetEffectTimeIntervalPosition(frame) * 100) / 100; int width, height; double totalFrames = (int)(TimeSpan.TotalMilliseconds / FrameTime) - 1; int pixelSpacing = Spacing * BufferHt / 100 + 3; if (Direction == GarlandsDirection.Up || Direction == GarlandsDirection.Down) { width = BufferWi; height = BufferHt; } else { width = BufferHt; height = BufferWi; } int limit = height * pixelSpacing * 4; int garlandsState; if (MovementType == MovementType.Iterations) { garlandsState = (int)(limit - ((_frames) * (limit / totalFrames * Iterations))) / 4; //Iterations if (garlandsState <= 0) { _frames = 0; } } else { _speed += Speed; garlandsState = (limit - _speed % limit) / 4; //Speed } _frames++; for (int ring = 0; ring < height; ring++) { var ratio = ring / (double)height; var color = GetMultiColorBlend(ratio, false, frame); var hsv = HSV.FromRGB(color); hsv.V = hsv.V * level; var y = garlandsState - ring * pixelSpacing; var ylimit = height - ring - 1; for (int x = 0; x < width; x++) { var yadj = y; switch (Type) { case 1: switch (x % 5) { case 2: yadj -= 2; break; case 1: case 3: yadj -= 1; break; } break; case 2: switch (x % 5) { case 2: yadj -= 4; break; case 1: case 3: yadj -= 2; break; } break; case 3: switch (x % 6) { case 3: yadj -= 6; break; case 2: case 4: yadj -= 4; break; case 1: case 5: yadj -= 2; break; } break; case 4: switch (x % 5) { case 1: case 3: yadj -= 2; break; } break; } switch (Direction) { case GarlandsDirection.Down: if (yadj < ylimit) { yadj = ylimit; } if (yadj < BufferHt) { frameBuffer.SetPixel(x, BufferHt - 1 - yadj, hsv); } break; case GarlandsDirection.Up: if (yadj < ylimit) { yadj = ylimit; } if (yadj < BufferHt) { frameBuffer.SetPixel(x, yadj, hsv); } break; case GarlandsDirection.Left: if (yadj < ylimit) { yadj = ylimit; } if (yadj < BufferWi) { frameBuffer.SetPixel(BufferWi - 1 - yadj, x, hsv); } break; case GarlandsDirection.Right: if (yadj < ylimit) { yadj = ylimit; } if (yadj < BufferWi) { frameBuffer.SetPixel(yadj, x, hsv); } break; } } } }
// use tempbuf for calculations protected override void RenderEffect(int frame, IPixelFrameBuffer frameBuffer) { double level = LevelCurve.GetValue(GetEffectTimeIntervalPosition(frame) * 100) / 100; int i, x, y; Color color; int state = frame * Speed; int count = BufferWi * BufferHt * CellsToStart / 200 + 1; if (frame == 0) { ClearTempBuf(); for (i = 0; i < count; i++) { x = rand() % BufferWi; y = rand() % BufferHt; color = GetMultiColorBlend(rand01(), frame); HSV hsv = HSV.FromRGB(color); hsv.V = hsv.V * level; color = hsv.ToRGB(); SetTempPixel(x, y, color); } } long tempState = (state % 400) / 20; if (tempState == _lastLifeState) { //Pixels=tempbuf; CopyTempBufToPixels(frameBuffer); return; } _lastLifeState = tempState; for (x = 0; x < BufferWi; x++) { for (y = 0; y < BufferHt; y++) { color = GetTempPixel(x, y); //isLive=(color.GetRGB() != 0); bool isLive = (color != Color.Black && color != Color.Transparent); int cnt = Life_CountNeighbors(x, y); switch (Type) { case 0: // B3/S23 /* * Any live cell with fewer than two live neighbours dies, as if caused by under-population. * Any live cell with two or three live neighbours lives on to the next generation. * Any live cell with more than three live neighbours dies, as if by overcrowding. * Any dead cell with exactly three live neighbours becomes a live cell, as if by reproduction. */ if (isLive && cnt >= 2 && cnt <= 3) { HSV hsv = HSV.FromRGB(color); hsv.V = hsv.V * level; frameBuffer.SetPixel(x, y, hsv); } else if (!isLive && cnt == 3) { color = GetMultiColorBlend(rand01(), frame); HSV hsv = HSV.FromRGB(color); hsv.V = hsv.V * level; frameBuffer.SetPixel(x, y, hsv); } break; case 1: // B35/S236 if (isLive && (cnt == 2 || cnt == 3 || cnt == 6)) { color = GetMultiColorBlend(rand01(), frame); HSV hsv = HSV.FromRGB(color); hsv.V = hsv.V * level; frameBuffer.SetPixel(x, y, hsv); } else if (!isLive && (cnt == 3 || cnt == 5)) { color = GetMultiColorBlend(rand01(), frame); HSV hsv = HSV.FromRGB(color); hsv.V = hsv.V * level; frameBuffer.SetPixel(x, y, hsv); } break; case 2: // B357/S1358 if (isLive && (cnt == 1 || cnt == 3 || cnt == 5 || cnt == 8)) { HSV hsv = HSV.FromRGB(color); hsv.V = hsv.V * level; frameBuffer.SetPixel(x, y, hsv); } else if (!isLive && (cnt == 3 || cnt == 5 || cnt == 7)) { color = GetMultiColorBlend(rand01(), frame); HSV hsv = HSV.FromRGB(color); hsv.V = hsv.V * level; frameBuffer.SetPixel(x, y, hsv); } break; case 3: // B378/S235678 if (isLive && (cnt == 2 || cnt == 3 || cnt >= 5)) { HSV hsv = HSV.FromRGB(color); hsv.V = hsv.V * level; frameBuffer.SetPixel(x, y, hsv); } else if (!isLive && (cnt == 3 || cnt == 7 || cnt == 8)) { color = GetMultiColorBlend(rand01(), frame); HSV hsv = HSV.FromRGB(color); hsv.V = hsv.V * level; frameBuffer.SetPixel(x, y, hsv); } break; case 4: // B25678/S5678 if (isLive && (cnt >= 5)) { HSV hsv = HSV.FromRGB(color); hsv.V = hsv.V * level; frameBuffer.SetPixel(x, y, hsv); } else if (!isLive && (cnt == 2 || cnt >= 5)) { color = GetMultiColorBlend(rand01(), frame); HSV hsv = HSV.FromRGB(color); hsv.V = hsv.V * level; frameBuffer.SetPixel(x, y, hsv); } break; } } } // copy new life state to tempbuf CopyPixelsToTempBuf(frameBuffer); }
protected override void RenderEffect(int frame, IPixelFrameBuffer frameBuffer) { var buffer = frameBuffer as PixelLocationFrameBuffer; if (buffer != null) { RenderEffectByLocation(frame, buffer); } int x, y, n, colorIdx; int colorcnt = Colors.Count(); int barCount = Repeat * colorcnt; double intervalPosFactor = GetEffectTimeIntervalPosition(frame) * 100; _negPosition = false; if (MovementType == MovementType.Iterations) { _position = (GetEffectTimeIntervalPosition(frame) * Speed) % 1; } else { if (frame == 0) { _position = CalculateSpeed(intervalPosFactor); } _position += CalculateSpeed(intervalPosFactor) / 100; if (_position < 0) { _negPosition = true; _position = -_position; } } if (barCount < 1) { barCount = 1; } double level = LevelCurve.GetValue(intervalPosFactor) / 100; if (Direction < BarDirection.Left || Direction == BarDirection.AlternateUp || Direction == BarDirection.AlternateDown) { int barHt = BufferHt / barCount + 1; if (barHt < 1) { barHt = 1; } int halfHt = BufferHt / 2; int blockHt = colorcnt * barHt; if (blockHt < 1) { blockHt = 1; } int fOffset = (int)(_position * blockHt * Repeat); // : Speed * frame / 4 % blockHt); if (Direction == BarDirection.AlternateUp || Direction == BarDirection.AlternateDown) { fOffset = (int)(Math.Floor(_position * barCount) * barHt); } int indexAdjust = 1; for (y = 0; y < BufferHt; y++) { n = y + fOffset; colorIdx = ((n + indexAdjust) % blockHt) / barHt; //we need the integer division here to make things work float colorPosition = ((n + indexAdjust) / barHt) - ((n + indexAdjust) / barHt); Color c = Colors[colorIdx].GetColorAt(colorPosition); if (Highlight || Show3D) { var hsv = HSV.FromRGB(c); if (Highlight && (n + indexAdjust) % barHt == 0) { hsv.S = 0.0f; } if (Show3D) { hsv.V *= (float)(barHt - (n + indexAdjust) % barHt - 1) / barHt; } hsv.V *= level; c = hsv.ToRGB(); } else { if (level < 1) { HSV hsv = HSV.FromRGB(c); hsv.V *= level; c = hsv.ToRGB(); } } switch (Direction) { case BarDirection.Down: case BarDirection.AlternateDown: // dow if (_negPosition) { for (x = 0; x < BufferWi; x++) { frameBuffer.SetPixel(x, BufferHt - y - 1, c); } } else { for (x = 0; x < BufferWi; x++) { frameBuffer.SetPixel(x, y, c); } } break; case BarDirection.Expand: // expand if (_negPosition) { if (y <= halfHt) { for (x = 0; x < BufferWi; x++) { frameBuffer.SetPixel(x, y, c); frameBuffer.SetPixel(x, BufferHt - y - 1, c); } } } else { if (y >= halfHt) { for (x = 0; x < BufferWi; x++) { frameBuffer.SetPixel(x, y, c); frameBuffer.SetPixel(x, BufferHt - y - 1, c); } } } break; case BarDirection.Compress: // compress if (!_negPosition) { if (y <= halfHt) { for (x = 0; x < BufferWi; x++) { frameBuffer.SetPixel(x, y, c); frameBuffer.SetPixel(x, BufferHt - y - 1, c); } } } else { if (y >= halfHt) { for (x = 0; x < BufferWi; x++) { frameBuffer.SetPixel(x, y, c); frameBuffer.SetPixel(x, BufferHt - y - 1, c); } } } break; default: // up & AlternateUp if (!_negPosition) { for (x = 0; x < BufferWi; x++) { frameBuffer.SetPixel(x, BufferHt - y - 1, c); } } else { for (x = 0; x < BufferWi; x++) { frameBuffer.SetPixel(x, y, c); } } break; } } } else { int barWi = BufferWi / barCount + 1; if (barWi < 1) { barWi = 1; } int halfWi = BufferWi / 2; int blockWi = colorcnt * barWi; if (blockWi < 1) { blockWi = 1; } int fOffset = (int)(_position * blockWi * Repeat); if (Direction > BarDirection.AlternateDown) { fOffset = (int)(Math.Floor(_position * barCount) * barWi); } for (x = 0; x < BufferWi; x++) { n = x + fOffset; colorIdx = ((n + 1) % blockWi) / barWi; //we need the integer division here to make things work float colorPosition = ((n + 1) / barWi) - ((n + 1) / barWi); Color c = Colors[colorIdx].GetColorAt(colorPosition); if (Highlight || Show3D) { var hsv = HSV.FromRGB(c); if (Highlight && n % barWi == 0) { hsv.S = 0.0f; } if (Show3D) { hsv.V *= (float)(barWi - n % barWi - 1) / barWi; } hsv.V *= level; c = hsv.ToRGB(); } else { if (level < 1) { HSV hsv = HSV.FromRGB(c); hsv.V *= level; c = hsv.ToRGB(); } } switch (Direction) { case BarDirection.Right: case BarDirection.AlternateRight: // right for (y = 0; y < BufferHt; y++) { frameBuffer.SetPixel(BufferWi - x - 1, y, c); } break; case BarDirection.HExpand: // H-expand if (x <= halfWi) { for (y = 0; y < BufferHt; y++) { frameBuffer.SetPixel(x, y, c); frameBuffer.SetPixel(BufferWi - x - 1, y, c); } } break; case BarDirection.HCompress: // H-compress if (x >= halfWi) { for (y = 0; y < BufferHt; y++) { frameBuffer.SetPixel(x, y, c); frameBuffer.SetPixel(BufferWi - x - 1, y, c); } } break; default: // left & AlternateLeft for (y = 0; y < BufferHt; y++) { frameBuffer.SetPixel(x, y, c); } break; } } } }
protected override void RenderEffect(int frame, IPixelFrameBuffer frameBuffer) { var intervalPos = GetEffectTimeIntervalPosition(frame); var intervalPosFactor = intervalPos * 100; double level = LevelCurve.GetValue(intervalPosFactor) / 100; int width, height; int pixelSpacing = CalculateSpacing(intervalPosFactor) * BufferHt / 100 + 3; if (Direction == GarlandsDirection.Up || Direction == GarlandsDirection.Down) { width = BufferWi; height = BufferHt; } else { width = BufferHt; height = BufferWi; } int limit = height * pixelSpacing * 4; int garlandsState; if (MovementType == MovementType.Iterations) { garlandsState = (int)(limit - _frames * (limit / GetNumberFrames() * Iterations)) / 4; //Iterations if (garlandsState <= 0) { _frames = 0; } } else { _speed += CalculateSpeed(intervalPosFactor); garlandsState = (limit - _speed % limit) / 4; //Speed } _frames++; for (int ring = 0; ring < height; ring++) { var ratio = ring / (double)height; Color col = GetMultiColorBlend(ratio, false, frame); if (level < 1) { HSV hsv = HSV.FromRGB(col); hsv.V = hsv.V * level; col = hsv.ToRGB(); } var y = garlandsState - ring * pixelSpacing; var ylimit = height - ring - 1; for (int x = 0; x < width; x++) { var yadj = y; switch (Type) { case 1: switch (x % 5) { case 2: yadj -= 2; break; case 1: case 3: yadj -= 1; break; } break; case 2: switch (x % 5) { case 2: yadj -= 4; break; case 1: case 3: yadj -= 2; break; } break; case 3: switch (x % 6) { case 3: yadj -= 6; break; case 2: case 4: yadj -= 4; break; case 1: case 5: yadj -= 2; break; } break; case 4: switch (x % 5) { case 1: case 3: yadj -= 2; break; } break; } switch (Direction) { case GarlandsDirection.Down: if (yadj < ylimit) { yadj = ylimit; } if (yadj < BufferHt) { frameBuffer.SetPixel(x, BufferHt - 1 - yadj, col); } break; case GarlandsDirection.Up: if (yadj < ylimit) { yadj = ylimit; } if (yadj < BufferHt) { frameBuffer.SetPixel(x, yadj, col); } break; case GarlandsDirection.Left: if (yadj < ylimit) { yadj = ylimit; } if (yadj < BufferWi) { frameBuffer.SetPixel(BufferWi - 1 - yadj, x, col); } break; case GarlandsDirection.Right: if (yadj < ylimit) { yadj = ylimit; } if (yadj < BufferWi) { frameBuffer.SetPixel(yadj, x, col); } break; } } } }
protected override void RenderEffectByLocation(int numFrames, PixelLocationFrameBuffer frameBuffer) { int colorcnt = Colors.Count(); int barCount = Repeat * colorcnt; if (barCount < 1) { barCount = 1; } int barHt = BufferHt / barCount + 1; if (barHt < 1) { barHt = 1; } int blockHt = colorcnt * barHt; if (blockHt < 1) { blockHt = 1; } int barWi = BufferWi / barCount + 1; if (barWi < 1) { barWi = 1; } int blockWi = colorcnt * barWi; if (blockWi < 1) { blockWi = 1; } IEnumerable <IGrouping <int, ElementLocation> > nodes; List <IGrouping <int, ElementLocation> > reversedNodes = new List <IGrouping <int, ElementLocation> >(); switch (Direction) { case BarDirection.AlternateUp: case BarDirection.Up: nodes = frameBuffer.ElementLocations.OrderBy(x => x.Y).ThenBy(x => x.X).GroupBy(x => x.Y); break; case BarDirection.Left: case BarDirection.AlternateLeft: nodes = frameBuffer.ElementLocations.OrderByDescending(x => x.X).ThenBy(x => x.Y).GroupBy(x => x.X); break; case BarDirection.Right: case BarDirection.AlternateRight: nodes = frameBuffer.ElementLocations.OrderBy(x => x.X).ThenBy(x => x.Y).GroupBy(x => x.X); break; case BarDirection.Compress: case BarDirection.Expand: nodes = frameBuffer.ElementLocations.OrderByDescending(x => x.Y).ThenBy(x => x.X).GroupBy(x => x.Y); reversedNodes = nodes.Reverse().ToList(); break; case BarDirection.HCompress: case BarDirection.HExpand: nodes = frameBuffer.ElementLocations.OrderBy(x => x.X).ThenBy(x => x.Y).GroupBy(x => x.X); reversedNodes = nodes.Reverse().ToList(); break; default: nodes = frameBuffer.ElementLocations.OrderByDescending(x => x.Y).ThenBy(x => x.X).GroupBy(x => x.Y); break; } var nodeCount = nodes.Count(); var halfNodeCount = (nodeCount - 1) / 2; var evenHalfCount = nodeCount % 2 != 0; for (int frame = 0; frame < numFrames; frame++) { frameBuffer.CurrentFrame = frame; double intervalPosFactor = GetEffectTimeIntervalPosition(frame) * 100; double level = LevelCurve.GetValue(intervalPosFactor) / 100; if (MovementType == MovementType.Iterations) { _position = (GetEffectTimeIntervalPosition(frame) * Speed) % 1; } else { if (frame == 0) { _position = CalculateSpeed(intervalPosFactor); } _position += CalculateSpeed(intervalPosFactor) / 100; } int n; int colorIdx; if (Direction < BarDirection.Left || Direction == BarDirection.AlternateUp || Direction == BarDirection.AlternateDown) { int fOffset = (int)(_position * blockHt * Repeat); // : Speed * frame / 4 % blockHt); if (Direction == BarDirection.AlternateUp || Direction == BarDirection.AlternateDown) { fOffset = (int)(Math.Floor(_position * barCount) * barHt); } if (Direction == BarDirection.Down || Direction == BarDirection.AlternateDown || Direction == BarDirection.Expand) { fOffset = -fOffset; } int indexAdjust = 1; int i = 0; bool exitLoop = false; foreach (IGrouping <int, ElementLocation> elementLocations in nodes) { int y = elementLocations.Key; n = y + fOffset; colorIdx = Math.Abs(((n + indexAdjust) % blockHt) / barHt); //we need the integer division here to make things work double colorPosition = Math.Abs((double)(n + indexAdjust) / barHt - (n + indexAdjust) / barHt); Color c = Colors[colorIdx].GetColorAt(colorPosition); if (Highlight || Show3D) { var hsv = HSV.FromRGB(c); if (Highlight && (n + indexAdjust) % barHt == 0) { hsv.S = 0.0f; } if (Show3D) { hsv.V *= (float)(barHt - (n + indexAdjust) % barHt - 1) / barHt; } hsv.V *= level; c = hsv.ToRGB(); } else { if (level < 1) { HSV hsv = HSV.FromRGB(c); hsv.V *= level; c = hsv.ToRGB(); } } switch (Direction) { case BarDirection.Expand: case BarDirection.Compress: // expand / compress if (i <= halfNodeCount) { foreach (var elementLocation in elementLocations) { frameBuffer.SetPixel(elementLocation.X, y, c); } if (i == halfNodeCount & evenHalfCount) { i++; continue; } foreach (var elementLocation in reversedNodes[i]) { frameBuffer.SetPixel(elementLocation.X, elementLocation.Y, c); } i++; } else { exitLoop = true; } break; default: foreach (var elementLocation in elementLocations) { frameBuffer.SetPixel(elementLocation.X, y, c); } break; } if (exitLoop) { break; } } } else { int fOffset = (int)(_position * blockWi * Repeat); if (Direction > BarDirection.AlternateDown) { fOffset = (int)(Math.Floor(_position * barCount) * barWi); } if (Direction == BarDirection.Right || Direction == BarDirection.AlternateRight || Direction == BarDirection.HCompress) { fOffset = -fOffset; } int i = 0; foreach (IGrouping <int, ElementLocation> elementLocations in nodes) { int x = elementLocations.Key; n = x + fOffset; colorIdx = Math.Abs(((n + 1) % blockWi) / barWi); //we need the integer division here to make things work double colorPosition = Math.Abs((double)(n + 1) / barWi - (n + 1) / barWi); Color c = Colors[colorIdx].GetColorAt(colorPosition); if (Highlight || Show3D) { var hsv = HSV.FromRGB(c); if (Highlight && n % barWi == 0) { hsv.S = 0.0f; } if (Show3D) { hsv.V *= (float)(barWi - n % barWi - 1) / barWi; } hsv.V *= level; c = hsv.ToRGB(); } else { if (level < 1) { HSV hsv = HSV.FromRGB(c); hsv.V *= level; c = hsv.ToRGB(); } } switch (Direction) { case BarDirection.HExpand: case BarDirection.HCompress: if (i <= halfNodeCount) { foreach (var elementLocation in elementLocations) { frameBuffer.SetPixel(x, elementLocation.Y, c); } if (i == halfNodeCount & evenHalfCount) { i++; continue; } foreach (var elementLocation in reversedNodes[i]) { frameBuffer.SetPixel(elementLocation.X, elementLocation.Y, c); } i++; } break; default: foreach (var elementLocation in elementLocations) { frameBuffer.SetPixel(x, elementLocation.Y, c); } break; } } } } }
protected override void RenderEffect(int frame, IPixelFrameBuffer frameBuffer) { double position = (GetEffectTimeIntervalPosition(frame) * Speed) % 1; double level = LevelCurve.GetValue(GetEffectTimeIntervalPosition(frame) * 100) / 100; // If we don't have any pictures, do nothing! if (_moviePicturesFileList == null || !_moviePicturesFileList.Any()) { return; } int pictureCount = _moviePicturesFileList.Count; if (PlayBackSpeed > 0) { _currentMovieImageNum += ((PlayBackSpeed * .01) + 1); } else if (PlayBackSpeed < 0) { _currentMovieImageNum += (100 + PlayBackSpeed) * .01; } else { _currentMovieImageNum++; } int currentImage = Convert.ToInt32(_currentMovieImageNum); if (currentImage >= pictureCount || currentImage < 0) { _currentMovieImageNum = currentImage = 0; } // copy image to buffer Bitmap resizeImage = new Bitmap(Image.FromFile(_moviePicturesFileList[currentImage])); FastPixel.FastPixel currentMovieImage = new FastPixel.FastPixel(new Bitmap(resizeImage)); int imgwidth = currentMovieImage.Width; int imght = currentMovieImage.Height; int yoffset = (BufferHt + imght) / 2; int xoffset = (imgwidth - BufferWi) / 2; int xOffsetAdj = XOffset * BufferWi / 100; int yOffsetAdj = YOffset * BufferHt / 100; switch (Type) { case EffectType.RenderPicturePeekaboo0: case EffectType.RenderPicturePeekaboo180: //Peek a boo yoffset = -(BufferHt) + (int)((BufferHt + 5) * position * 2); if (yoffset > 10) { yoffset = -yoffset + 10; //reverse direction } else if (yoffset >= -1) { yoffset = -1; //pause in middle } break; case EffectType.RenderPictureWiggle: if (position >= 0.5) { xoffset += (int)(BufferWi * ((1.0 - position) * 2.0 - 0.5)); } else { xoffset += (int)(BufferWi * (position * 2.0 - 0.5)); } break; case EffectType.RenderPicturePeekaboo90: //peekaboo 90 case EffectType.RenderPicturePeekaboo270: //peekaboo 270 if (Orientation == StringOrientation.Vertical) { yoffset = (imght - BufferWi) / 2; //adjust offsets for other axis xoffset = -(BufferHt) + (int)((BufferHt + 5) * position * 2); } else { yoffset = (imgwidth - BufferHt) / 2; //adjust offsets for other axis xoffset = -(BufferWi) + (int)((BufferWi + 5) * position * 2); } if (xoffset > 10) { xoffset = -xoffset + 10; //reverse direction } else if (xoffset >= -1) { xoffset = -1; //pause in middle } break; } currentMovieImage.Lock(); Color fpColor = new Color(); for (int x = 0; x < imgwidth; x++) { for (int y = 0; y < imght; y++) { fpColor = currentMovieImage.GetPixel(x, y); if (fpColor != Color.Transparent && fpColor != Color.Black) { var hsv = HSV.FromRGB(fpColor); double tempV = hsv.V * level * ((double)(IncreaseBrightness) / 10); if (tempV > 1) { tempV = 1; } hsv.V = tempV; int leftX, rightX, upY, downY; switch (_data.EffectType) { case EffectType.RenderPictureLeft: // left leftX = x + (BufferWi - (int)(position * (imgwidth + BufferWi))); frameBuffer.SetPixel(leftX + xOffsetAdj, yoffset - y + yOffsetAdj, hsv); break; case EffectType.RenderPictureRight: // right rightX = x + -imgwidth + (int)(position * (imgwidth + BufferWi)); frameBuffer.SetPixel(rightX + xOffsetAdj, yoffset - y + yOffsetAdj, hsv); break; case EffectType.RenderPictureUp: // up upY = (int)((imght + BufferHt) * position) - y; frameBuffer.SetPixel(x - xoffset + xOffsetAdj, upY + yOffsetAdj, hsv); break; case EffectType.RenderPictureDown: // down downY = (BufferHt + imght - 1) - (int)((imght + BufferHt) * position) - y; frameBuffer.SetPixel(x - xoffset + xOffsetAdj, downY + yOffsetAdj, hsv); break; case EffectType.RenderPictureUpleft: // up-left leftX = x + (BufferWi - (int)(position * (imgwidth + BufferWi))); upY = (int)((imght + BufferHt) * position) - y; frameBuffer.SetPixel(leftX + xOffsetAdj, upY + yOffsetAdj, hsv); break; case EffectType.RenderPictureDownleft: // down-left leftX = x + (BufferWi - (int)(position * (imgwidth + BufferWi))); downY = (BufferHt + imght - 1) - (int)((imght + BufferHt) * position) - y; frameBuffer.SetPixel(leftX + xOffsetAdj, downY + yOffsetAdj, hsv); break; case EffectType.RenderPictureUpright: // up-right upY = (int)((imght + BufferHt) * position) - y; rightX = x + -imgwidth + (int)(position * (imgwidth + BufferWi)); frameBuffer.SetPixel(rightX + xOffsetAdj, upY + yOffsetAdj, hsv); break; case EffectType.RenderPictureDownright: // down-right downY = (BufferHt + imght - 1) - (int)((imght + BufferHt) * position) - y; rightX = x + -imgwidth + (int)(position * (imgwidth + BufferWi)); frameBuffer.SetPixel(rightX + xOffsetAdj, downY + yOffsetAdj, hsv); break; case EffectType.RenderPicturePeekaboo0: // Peek a boo 0 frameBuffer.SetPixel(x - xoffset + xOffsetAdj, BufferHt + yoffset - y + yOffsetAdj, hsv); break; case EffectType.RenderPictureWiggle: // Wiggle frameBuffer.SetPixel(x + xoffset + xOffsetAdj, yoffset - y + yOffsetAdj, hsv); break; case EffectType.RenderPicturePeekaboo90: // Peekaboo90 frameBuffer.SetPixel(BufferWi + xoffset - y + xOffsetAdj, x - yoffset + yOffsetAdj, hsv); break; case EffectType.RenderPicturePeekaboo180: // Peekaboo180 frameBuffer.SetPixel(x - xoffset + xOffsetAdj, y - yoffset + yOffsetAdj, hsv); break; case EffectType.RenderPicturePeekaboo270: // Peekaboo270 frameBuffer.SetPixel(y - xoffset + xOffsetAdj, BufferHt + yoffset - x + yOffsetAdj, hsv); break; default: // no movement - centered frameBuffer.SetPixel(x - xoffset + xOffsetAdj, yoffset - y + yOffsetAdj, hsv); break; } } } } currentMovieImage.Unlock(false); currentMovieImage.Dispose(); resizeImage.Dispose(); }
protected override void RenderEffect(int frame, IPixelFrameBuffer frameBuffer) { if (_image != null) { var dir = 360 - Direction; var intervalPos = GetEffectTimeIntervalPosition(frame); var intervalPosFactor = intervalPos * 100; double level = LevelCurve.GetValue(intervalPosFactor) / 100; double adjustedBrightness = (double)(CalculateIncreaseBrightness(intervalPosFactor)) / 10; int speedFactor = 4; int state = MovementRate * frame; if (Type != EffectType.RenderPictureTiles && Type != EffectType.RenderPictureNone) { _position = ((GetEffectTimeIntervalPosition(frame) * Speed) % 1); } else if (frame == 0) { _position = ((GetEffectTimeIntervalPosition(frame + 1) * Speed) % 1); } CalculateImageNumberByPosition((GetEffectTimeIntervalPosition(frame) * GifSpeed) % 1); _image.SelectActiveFrame(_dimension, (int)_currentGifImageNum); _scaledImage = ScaleToGrid ? ScalePictureImage(_image, BufferWi, BufferHt) : ScaleImage(_image, (double)ScalePercent / 100); if (ColorEffect == ColorEffect.GreyScale) { _scaledImage = (Bitmap)ConvertToGrayScale(_scaledImage); } _fp = new FastPixel.FastPixel(_scaledImage); if (_fp != null) { int imageWidth = _fp.Width; int imageHeight = _fp.Height; double deltaX = 0; double deltaY = 0; double angleOffset; if (dir > 45 && dir <= 90) { angleOffset = -(dir - 90); } else if (dir > 90 && dir <= 135) { angleOffset = dir - 90; } else if (dir > 135 && dir <= 180) { angleOffset = -(dir - 180); } else if (dir > 180 && dir <= 225) { angleOffset = dir - 180; } else if (dir > 225 && dir <= 270) { angleOffset = -(dir - 270); } else if (dir > 270 && dir <= 315) { angleOffset = dir - 270; } else if (dir > 315 && dir <= 360) { angleOffset = -(dir - 360); } else { angleOffset = dir; } double imageSpeed = _position * (imageWidth / (Math.Cos((Math.PI / 180) * angleOffset))); //Moving left and right if (dir > 0 && dir <= 90) { deltaX = ((double)dir / 90) * (imageSpeed); } else if (dir > 90 && dir <= 180) { deltaX = ((double)Math.Abs(dir - 180) / 90) * (imageSpeed); } else if (dir > 180 && dir <= 270) { deltaX = -1 * (((double)Math.Abs(dir - 180) / 90) * (imageSpeed)); } else if (dir > 270 && dir <= 360) { deltaX = -1 * (((double)Math.Abs(dir - 360) / 90) * (imageSpeed)); } //Moving up and down if (dir >= 0 && dir <= 90) { deltaY = (((double)Math.Abs(dir - 90) / 90)) * (imageSpeed); } else if (dir > 90 && dir <= 180) { deltaY = -1 * (((double)Math.Abs(dir - 90) / 90) * (imageSpeed)); } else if (dir > 180 && dir <= 270) { deltaY = -1 * (((double)Math.Abs(dir - 270) / 90) * (imageSpeed)); } else if (dir > 270 && dir <= 360) { deltaY = ((double)Math.Abs(270 - dir) / 90) * (imageSpeed); } _movementX += deltaX; _movementY += deltaY; _fp.Lock(); Color fpColor = new Color(); int yoffset = (BufferHt + imageHeight) / 2; int xoffset = (imageWidth - BufferWi) / 2; int xOffsetAdj = CalculateXOffset(intervalPosFactor) * BufferWi / 100; int yOffsetAdj = CalculateYOffset(intervalPosFactor) * BufferHt / 100; int imageHt = imageHeight; int imageWi = imageWidth; switch (Type) { case EffectType.RenderPicturePeekaboo0: case EffectType.RenderPicturePeekaboo180: //Peek a boo yoffset = -(BufferHt) + (int)((BufferHt + 5) * _position * 2); if (yoffset > 10) { yoffset = -yoffset + 10; //reverse direction } else if (yoffset >= -1) { yoffset = -1; //pause in middle } break; case EffectType.RenderPictureWiggle: if (_position >= 0.5) { xoffset += (int)(BufferWi * ((1.0 - _position) * 2.0 - 0.5)); } else { xoffset += (int)(BufferWi * (_position * 2.0 - 0.5)); } break; case EffectType.RenderPicturePeekaboo90: //peekaboo 90 case EffectType.RenderPicturePeekaboo270: //peekaboo 270 if (Orientation == StringOrientation.Vertical) { yoffset = (imageHt - BufferWi) / 2; //adjust offsets for other axis } else { yoffset = (imageWi - BufferHt) / 2; //adjust offsets for other axis } if (Orientation == StringOrientation.Vertical) { xoffset = -(BufferHt) + (int)((BufferHt + 5) * _position * 2); } else { xoffset = -(BufferWi) + (int)((BufferWi + 5) * _position * 2); } if (xoffset > 10) { xoffset = -xoffset + 10; //reverse direction } else if (xoffset >= -1) { xoffset = -1; //pause in middle } break; case EffectType.RenderPictureTiles: imageHt = BufferHt; imageWi = BufferWi; break; } for (int x = 0; x < imageWi; x++) { for (int y = 0; y < imageHt; y++) { if (Type != EffectType.RenderPictureTiles) // change this so only when tiles are disabled { fpColor = _fp.GetPixel(x, y); } var hsv = HSV.FromRGB(fpColor); double tempV = hsv.V * level * adjustedBrightness; if (tempV > 1) { tempV = 1; } hsv.V = tempV; switch (Type) { case EffectType.RenderPicturePeekaboo0: if (fpColor != Color.Transparent) { //Peek a boo hsv = CustomColor(hsv, frame, level, fpColor, adjustedBrightness); frameBuffer.SetPixel(x - xoffset + xOffsetAdj, BufferHt + yoffset - y + yOffsetAdj, hsv); } break; case EffectType.RenderPictureWiggle: hsv = CustomColor(hsv, frame, level, fpColor, adjustedBrightness); frameBuffer.SetPixel(x + xoffset + xOffsetAdj, yoffset - y + yOffsetAdj, hsv); break; case EffectType.RenderPicturePeekaboo90: hsv = CustomColor(hsv, frame, level, fpColor, adjustedBrightness); frameBuffer.SetPixel(BufferWi + xoffset - y + xOffsetAdj, BufferHt - x - yoffset + yOffsetAdj, hsv); break; case EffectType.RenderPicturePeekaboo180: hsv = CustomColor(hsv, frame, level, fpColor, adjustedBrightness); if (StringOrientation == StringOrientation.Vertical) { frameBuffer.SetPixel((BufferWi - x) - xoffset + xOffsetAdj, y - yoffset + yOffsetAdj, hsv); } else { frameBuffer.SetPixel((BufferWi - x) - xoffset + xOffsetAdj - (BufferWi / 2), y - yoffset + yOffsetAdj, hsv); } break; case EffectType.RenderPicturePeekaboo270: hsv = CustomColor(hsv, frame, level, fpColor, adjustedBrightness); frameBuffer.SetPixel(y - xoffset + xOffsetAdj, BufferHt + yoffset - (BufferHt - x) + yOffsetAdj, hsv); break; case EffectType.RenderPictureLeft: // left int leftX = x + (BufferWi - (int)(_position * (imageWi + BufferWi))); hsv = CustomColor(hsv, frame, level, fpColor, adjustedBrightness); frameBuffer.SetPixel(leftX + xOffsetAdj, yoffset - y + yOffsetAdj, hsv); break; case EffectType.RenderPictureRight: // right int rightX = x + -imageWi + (int)(_position * (imageWi + BufferWi)); hsv = CustomColor(hsv, frame, level, fpColor, adjustedBrightness); frameBuffer.SetPixel(rightX + xOffsetAdj, yoffset - y + yOffsetAdj, hsv); break; case EffectType.RenderPictureUp: // up int upY = (int)((imageHt + BufferHt) * _position) - y; hsv = CustomColor(hsv, frame, level, fpColor, adjustedBrightness); frameBuffer.SetPixel(x - xoffset + xOffsetAdj, upY + yOffsetAdj, hsv); break; case EffectType.RenderPictureUpleft: int upLeftY = (int)((imageHt + BufferHt) * _position) - y; hsv = CustomColor(hsv, frame, level, fpColor, adjustedBrightness); frameBuffer.SetPixel( Convert.ToInt32(x + BufferWi - (state % ((imageWi + BufferWi) * speedFactor)) / speedFactor) + xOffsetAdj, upLeftY + yOffsetAdj, hsv); break; // up-left case EffectType.RenderPictureDownleft: int downLeftY = BufferHt + imageHt - (int)((imageHt + BufferHt) * _position) - y; hsv = CustomColor(hsv, frame, level, fpColor, adjustedBrightness); frameBuffer.SetPixel( Convert.ToInt32(x + BufferWi - (state % ((imageWi + BufferWi) * speedFactor)) / speedFactor) + xOffsetAdj, downLeftY + yOffsetAdj, hsv); break; // down-left case EffectType.RenderPictureUpright: int upRightY = (int)((imageHt + BufferHt) * _position) - y; hsv = CustomColor(hsv, frame, level, fpColor, adjustedBrightness); frameBuffer.SetPixel( Convert.ToInt32(x + (state % ((imageWi + BufferWi) * speedFactor)) / speedFactor - imageWi) + xOffsetAdj, upRightY + yOffsetAdj, hsv); break; // up-right case EffectType.RenderPictureDownright: int downRightY = BufferHt + imageHt - (int)((imageHt + BufferHt) * _position) - y; hsv = CustomColor(hsv, frame, level, fpColor, adjustedBrightness); frameBuffer.SetPixel( Convert.ToInt32(x + (state % ((imageWi + BufferWi) * speedFactor)) / speedFactor - imageWi) + xOffsetAdj, downRightY + yOffsetAdj, hsv); break; // down-right case EffectType.RenderPictureDown: // down int downY = (BufferHt + imageHt - 1) - (int)((imageHt + BufferHt) * _position) - y; hsv = CustomColor(hsv, frame, level, fpColor, adjustedBrightness); frameBuffer.SetPixel(x - xoffset + xOffsetAdj, downY + yOffsetAdj, hsv); break; case EffectType.RenderPictureNone: hsv = CustomColor(hsv, frame, level, fpColor, adjustedBrightness); frameBuffer.SetPixel(x - xoffset + xOffsetAdj, yoffset - y + yOffsetAdj, hsv); break; case EffectType.RenderPictureTiles: int colorX = x + Convert.ToInt32(_movementX) - (xOffsetAdj * BufferWi / 100); int colorY = y + Convert.ToInt32(_movementY) + (yOffsetAdj * BufferHt / 100); if (colorX >= 0) { colorX = colorX % imageWidth; } else if (colorX < 0) { colorX = Convert.ToInt32(colorX % imageWidth) + imageWidth - 1; } if (colorY >= 0) { colorY = Convert.ToInt32((colorY % imageHeight)); } else if (colorY < 0) { colorY = Convert.ToInt32(colorY % imageHeight) + imageHeight - 1; } if (colorX <= _fp.Width && colorY <= _fp.Height) { fpColor = _fp.GetPixel(colorX, colorY); hsv = HSV.FromRGB(fpColor); hsv = CustomColor(hsv, frame, level, fpColor, adjustedBrightness); frameBuffer.SetPixel(x, BufferHt - y - 1, hsv); } break; } } } _fp.Unlock(false); _fp.Dispose(); _scaledImage.Dispose(); } } }
protected override void RenderEffectByLocation(int numFrames, PixelLocationFrameBuffer frameBuffer) { var swagArray = new List <int>(); int swaglen = BufferHt > 1 ? Swag * BufferWi / 40 : 0; var swagBufferHt = BufferHt; switch (Edge) { case CurtainEdge.Middle: case CurtainEdge.Top: case CurtainEdge.Bottom: swagBufferHt = BufferWi; break; } for (int effectFrame = 0; effectFrame < numFrames; effectFrame++) { frameBuffer.CurrentFrame = effectFrame; var timeIntervalPosition = GetEffectTimeIntervalPosition(effectFrame); double position = (timeIntervalPosition * Speed) % 1; double level = LevelCurve.GetValue(timeIntervalPosition * 100) / 100; if (swaglen > 0) { swagArray.Clear(); double a = (double)(swagBufferHt) / (swaglen * swaglen); for (int x = 0; x < swaglen; x++) { swagArray.Add((int)(a * x * x)); } } int xlimit; int ylimit; if (Direction < CurtainDirection.CurtainOpenClose) { if (Direction == CurtainDirection.CurtainOpen) { xlimit = (int)((position * BufferWi) + (swaglen * position * 2)); ylimit = (int)((position * BufferHt) + (swaglen * position * 2)); } else { xlimit = (int)((position * BufferWi) - (swaglen * (1 - position) * 2)); ylimit = (int)((position * BufferHt) - (swaglen * (1 - position) * 2)); } } else { if (Direction == CurtainDirection.CurtainOpenClose) { xlimit = (int)(position <= .5 ? (position * 2 * BufferWi) + (swaglen * position * 4) : ((position - .5) * 2 * BufferWi) - (swaglen * (1 - position) * 4)); ylimit = (int)(position <= .5 ? (position * 2 * BufferHt) + (swaglen * position * 4) : ((position - .5) * 2 * BufferHt) - (swaglen * (1 - position) * 4)); } else { xlimit = (int)(position <= .5 ? (position * 2 * BufferWi) - (swaglen * (0.5 - position) * 4) : ((position - .5) * 2 * BufferWi) + (swaglen * position * 2)); ylimit = (int)(position <= .5 ? (position * 2 * BufferHt) - (swaglen * (0.5 - position) * 4) : ((position - .5) * 2 * BufferHt) + (swaglen * position * 2)); } } int curtainDir; if (Direction < CurtainDirection.CurtainOpenClose) { curtainDir = (int)Direction % 2; } else if (xlimit < _lastCurtainLimit - swaglen * 2) { curtainDir = 1 - _lastCurtainDir; } else { curtainDir = _lastCurtainDir; } _lastCurtainDir = curtainDir; _lastCurtainLimit = xlimit; if (curtainDir == 0) { xlimit = BufferWi - xlimit; ylimit = BufferHt - ylimit; } int middle; switch (Edge) { case CurtainEdge.Left: // left DrawCurtainLocation(true, xlimit, swagArray, frameBuffer, level, BufferWi); break; case CurtainEdge.Center: // center middle = xlimit / 2; DrawCurtainLocation(true, middle, swagArray, frameBuffer, level, BufferWi / 2); DrawCurtainLocation(false, middle, swagArray, frameBuffer, level, BufferWi / 2); break; case CurtainEdge.Right: // right DrawCurtainLocation(false, xlimit, swagArray, frameBuffer, level, BufferWi); break; case CurtainEdge.Bottom: // bottom DrawCurtainVerticalLocation(false, ylimit, swagArray, frameBuffer, level, BufferHt); break; case CurtainEdge.Middle: // middle middle = ylimit / 2; DrawCurtainVerticalLocation(true, middle, swagArray, frameBuffer, level, BufferHt / 2); DrawCurtainVerticalLocation(false, middle, swagArray, frameBuffer, level, BufferHt / 2); break; case CurtainEdge.Top: // top DrawCurtainVerticalLocation(true, ylimit, swagArray, frameBuffer, level, BufferHt); break; } } }
protected override void RenderEffect(int effectFrame, ref PixelFrameBuffer frameBuffer) { int repeat = Repeat; switch (ButterflyType) { case ButterflyType.Type1: case ButterflyType.Type5: repeat = Repeat * 3; break; case ButterflyType.Type4: repeat = Repeat * 6; break; } double h = 0.0; int maxframe = BufferHt; double position = (GetEffectTimeIntervalPosition(effectFrame) * Iterations) % 1; int curState = (int)(TimeSpan.TotalMilliseconds * position * repeat); int frame = (BufferHt * curState / (int)TimeSpan.TotalMilliseconds) % maxframe; double offset = curState / TimeSpan.TotalMilliseconds; if (Direction == Direction.Forward) { offset = -offset; } for (int x = 0; x < BufferWi; x++) { int y; for (y = 0; y < BufferHt; y++) { double n; double x1; double y1; double f; int d; int x0; int y0; switch (ButterflyType) { case ButterflyType.Type1: // http://mathworld.wolfram.com/ButterflyFunction.html n = Math.Abs((x * x - y * y) * Math.Sin(offset + ((x + y) * pi2 / (BufferHt + BufferWi)))); d = x * x + y * y; // This section is to fix the colors on pixels at {0,1} and {1,0} x0 = x + 1; y0 = y + 1; if ((x == 0 && y == 1)) { n = Math.Abs((x * x - y0 * y0) * Math.Sin(offset + ((x + y0) * pi2 / (BufferHt + BufferWi)))); d = x * x + y0 * y0; } if ((x == 1 && y == 0)) { n = Math.Abs((x0 * x0 - y * y) * Math.Sin(offset + ((x0 + y) * pi2 / (BufferHt + BufferWi)))); d = x0 * x0 + y * y; } // end of fix h = d > 0.001 ? n / d : 0.0; break; case ButterflyType.Type2: 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 ButterflyType.Type3: 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; case ButterflyType.Type4: // http://mathworld.wolfram.com/ButterflyFunction.html n = ((x * x - y * y) * Math.Sin(offset + ((x + y) * pi2 / (BufferHt + BufferWi)))); d = x * x + y * y; // This section is to fix the colors on pixels at {0,1} and {1,0} x0 = x + 1; y0 = y + 1; if ((x == 0 && y == 1)) { n = ((x * x - y0 * y0) * Math.Sin(offset + ((x + y0) * pi2 / (BufferHt + BufferWi)))); d = x * x + y0 * y0; } if ((x == 1 && y == 0)) { n = ((x0 * x0 - y * y) * Math.Sin(offset + ((x0 + y) * pi2 / (BufferHt + BufferWi)))); d = x0 * x0 + y * y; } // end of fix h = d > 0.001 ? n / d : 0.0; var fractpart = h - (Math.Floor(h)); h = fractpart; if (h < 0) { h = 1.0 + h; } break; case ButterflyType.Type5: // http://mathworld.wolfram.com/ButterflyFunction.html n = Math.Abs((x * x - y * y) * Math.Sin(offset + ((x + y) * pi2 / (BufferHt * BufferWi)))); d = x * x + y * y; // This section is to fix the colors on pixels at {0,1} and {1,0} x0 = x + 1; y0 = y + 1; if ((x == 0 && y == 1)) { n = Math.Abs((x * x - y0 * y0) * Math.Sin(offset + ((x + y0) * pi2 / (BufferHt * BufferWi)))); d = x * x + y0 * y0; } if ((x == 1 && y == 0)) { n = Math.Abs((x0 * x0 - y * y) * Math.Sin(offset + ((x0 + y) * pi2 / (BufferHt * BufferWi)))); d = x0 * x0 + y * y; } // end of fix h = d > 0.001 ? n / d : 0.0; break; } HSV hsv = new HSV(h, 1.0, 1.0); double level = LevelCurve.GetValue(GetEffectTimeIntervalPosition(effectFrame) * 100) / 100; if (BackgroundChunks <= 1 || (int)(h * BackgroundChunks) % BackgroundSkips != 0) { if (ColorScheme == ColorScheme.Gradient) { Color color = Color.GetColorAt(h); hsv = HSV.FromRGB(color); } hsv.V = hsv.V * level; frameBuffer.SetPixel(x, y, hsv); } } } }
protected override void RenderEffect(int frame, IPixelFrameBuffer frameBuffer) { int colorcntOutSide = OutSideColor.Count; int colorcntInside = InnerColor.Count; int minDirection = 1; int maxDirection = 360; var intervalPosFactor = GetEffectTimeIntervalPosition(frame) * 100; double level = LevelCurve.GetValue(intervalPosFactor) / 100; // create new SnowFlakes and maintain maximum number as per users selection. int flakeCount = (int)(SnowflakeEffect == SnowflakeEffect.Explode && frame < CalculateCount(intervalPosFactor) ? 1 : CalculateCount(intervalPosFactor)); int initialBuildUp = !SnowBuildUp ? 0 : (int)(CalculateInitialBuildUp() + (CalculateBuildUpSpeed(intervalPosFactor) * (frame / (double)100))); var centerSpeed = CalculateCenterSpeed(intervalPosFactor); var spreadSpeed = CalculateSpeedVariation(intervalPosFactor); var minSpeed = centerSpeed - (spreadSpeed / 2); var maxSpeed = centerSpeed + (spreadSpeed / 2); if (minSpeed < 1) { minSpeed = 1; } if (maxSpeed > 60) { maxSpeed = 60; } for (int i = 0; i < flakeCount; i++) { if (_snowFlakes.Count >= CalculateCount(intervalPosFactor) + _increaseFlakeCount - _snowfalakeCountAdjust) { break; } double position = (RandDouble() * ((maxSpeed + 1) - minSpeed) + minSpeed) / 5; SnowFlakeClass m = new SnowFlakeClass(); if (SnowflakeEffect == SnowflakeEffect.RandomDirection) { minDirection = MinDirection; maxDirection = MaxDirection; } int direction; if (SnowflakeEffect == SnowflakeEffect.None) { direction = Rand(145, 215); //Set Range for standard Snowflakes as we don't want to just have them going straight down or two dirctions like the original Snowflake effect. } else { //This is to generate random directions between the Min and Max values //However if Someone makes the MaxDirection lower then the Min Direction then //the new direction will be the inverserve of the Min and Max effectively changing //the range from a downward motion to an upward motion, increasing the feature capability. direction = maxDirection <= minDirection ? (Rand(1, 3) == 1 ? Rand(1, maxDirection) : Rand(minDirection, 360)) : Rand(minDirection, maxDirection); } //Moving (direction) if (direction > 0 && direction <= 90) { m.DeltaX = ((double)direction / 90) * position; m.DeltaY = ((double)Math.Abs(direction - 90) / 90) * position; } else if (direction > 90 && direction <= 180) { m.DeltaX = ((double)Math.Abs(direction - 180) / 90) * position; m.DeltaY = (-1 * ((double)Math.Abs(direction - 90) / 90)) * position; } else if (direction > 180 && direction <= 270) { m.DeltaX = (-1 * ((double)Math.Abs(direction - 180) / 90)) * position; m.DeltaY = (-1 * ((double)Math.Abs(direction - 270) / 90)) * position; } else if (direction > 270 && direction <= 360) { m.DeltaX = (-1 * ((double)Math.Abs(direction - 360) / 90)) * position; m.DeltaY = ((double)Math.Abs(270 - direction) / 90) * position; } //Start position for Snowflake if (SnowflakeEffect == SnowflakeEffect.Explode) //Will start in the centre of the grid { m.X = BufferWi / 2; m.Y = BufferHt / 2; } else { m.X = Rand() % BufferWi; if (frame == 0) { m.Y = Rand() % BufferHt; //This is used so for the first lot of Snowflakes they will start in a random position and then fall from the edge. } else { m.Y = BufferHt; } } m.DeltaXOrig = m.DeltaX; m.DeltaYOrig = m.DeltaY; m.Type = SnowflakeType == SnowflakeType.Random ? RandomFlakeType <SnowflakeType>() : SnowflakeType; //Set the SnowFlake colors during the creation of the snowflake. switch (ColorType) { case SnowflakeColorType.Range: //Random two colors are selected from the list for each SnowFlake and then the color range between them are used. m.OuterHsv = SetRangeColor(HSV.FromRGB(OutSideColor[Rand() % colorcntOutSide].GetColorAt((intervalPosFactor) / 100)), HSV.FromRGB(OutSideColor[Rand() % colorcntOutSide].GetColorAt((intervalPosFactor) / 100))); m.InnerHsv = SetRangeColor(HSV.FromRGB(InnerColor[Rand() % colorcntInside].GetColorAt((intervalPosFactor) / 100)), HSV.FromRGB(InnerColor[Rand() % colorcntInside].GetColorAt((intervalPosFactor) / 100))); break; case SnowflakeColorType.Palette: //All user colors are used m.OuterHsv = HSV.FromRGB(OutSideColor[Rand() % colorcntOutSide].GetColorAt((intervalPosFactor) / 100)); m.InnerHsv = HSV.FromRGB(InnerColor[Rand() % colorcntInside].GetColorAt((intervalPosFactor) / 100)); break; default: m.InnerHsv = HSV.FromRGB(InnerColor[Rand() % colorcntInside].GetColorAt((intervalPosFactor) / 100)); break; } m.HsvBrightness = RandomBrightness ? RandDouble() * (1.0 - .20) + .20 : 1; //Adds a random brightness to each Snowflake making it look more realistic m.BuildUp = false; _snowFlakes.Add(m); } if (SnowBuildUp) { //Renders the Snow on the ground based off the cuurrent height. Color col = OutSideColor[0].GetColorAt((intervalPosFactor) / 100); if (level < 1) { HSV hsv = HSV.FromRGB(col); hsv.V *= level; col = hsv.ToRGB(); } for (int x = 0; x < BufferWi; x++) { for (int y = 0; y < initialBuildUp; y++) { //The ground color will be use the first outside color of the snowflakes. frameBuffer.SetPixel(x, y, col); } } } int snowflakeWidth; // render all SnowFlakes foreach (SnowFlakeClass snowFlakes in _snowFlakes) { snowFlakes.DeltaX += snowFlakes.DeltaXOrig; snowFlakes.DeltaY += snowFlakes.DeltaYOrig; switch (snowFlakes.Type) { case SnowflakeType.Five: case SnowflakeType.Nine: snowflakeWidth = 2; break; case SnowflakeType.Thirteen: case SnowflakeType.FortyFive: snowflakeWidth = 3; break; default: snowflakeWidth = 1; break; } int snowflakeOverShoot = snowflakeWidth * 2; for (int c = 0; c < 1; c++) { int colorX; int colorY; if (!snowFlakes.BuildUp) //Skips the location processing part to not waste time as the Snowflake is no longer moving and sitting on the bottom. { //Sets the new position the SnowFlake is moving to colorX = snowFlakes.X + (int)snowFlakes.DeltaX - BufferWi / 100; colorY = snowFlakes.Y + (int)snowFlakes.DeltaY + BufferHt / 100; if (SnowflakeEffect != SnowflakeEffect.Explode) { //Modifies the colorX and colorY when the Explode effect is not used. colorX = colorX % BufferWi; colorY = colorY % BufferHt; if (SnowBuildUp) //Will detect snowflake hits up to 3 pixels wide { //If BuildUp is checked then check to see if a flake lands on another flake that's already at the bottom. foreach ( SnowFlakeClass snowFlake in _snowFlakes.Where( snowFlake => snowFlake.BuildUp && (colorX >= snowFlake.BuildUpX - 1 && colorX <= snowFlake.BuildUpX + 1) && colorY <= snowFlake.BuildUpY)) { snowFlakes.BuildUp = true; snowFlakes.BuildUpX = colorX; snowFlakes.InnerHsv = HSV.FromRGB(InnerColor[0].GetColorAt((intervalPosFactor) / 100)); snowFlakes.OuterHsv = HSV.FromRGB(OutSideColor[0].GetColorAt((intervalPosFactor) / 100)); snowFlakes.BuildUpY = snowflakeWidth < 3 ? snowFlake.BuildUpY + 1 : snowFlake.BuildUpY + 2; _increaseFlakeCount++; //Ensures a new Snowflake is added on the next frame to replace this one as its now resting on the bottom of the grid. break; } } } if (ColorType == SnowflakeColorType.RainBow && !snowFlakes.BuildUp) //No user colors are used for Rainbow effect. Color selection for user will be hidden. { snowFlakes.OuterHsv.H = (float)(Rand() % 1000) / 1000.0f; snowFlakes.OuterHsv.S = 1.0f; snowFlakes.OuterHsv.V = 1.0f; } if (colorX >= BufferWi + snowflakeOverShoot || colorY >= BufferHt + snowflakeOverShoot || colorX <= -snowflakeOverShoot || colorY <= initialBuildUp - snowflakeOverShoot) { //Flags SnowFlakes that have reached the end of the grid as expiried unless Buildup is checked and then record the Snowflake //position to be used in future frames. Allows new Snowflakes to be created. if (SnowBuildUp && colorY <= initialBuildUp && !snowFlakes.BuildUp && SnowflakeEffect != SnowflakeEffect.Explode) { snowFlakes.BuildUp = true; snowFlakes.BuildUpX = colorX; snowFlakes.BuildUpY = initialBuildUp + 1; snowFlakes.InnerHsv = HSV.FromRGB(InnerColor[0].GetColorAt((intervalPosFactor) / 100)); snowFlakes.OuterHsv = HSV.FromRGB(OutSideColor[0].GetColorAt((intervalPosFactor) / 100)); _increaseFlakeCount++; //Ensures a new Snowflake is added on the next frame to replace this one as its now resting on the bottom of the grid. } else { if (!snowFlakes.BuildUp) { snowFlakes.Expired = true; } } break; } } else { //Sets the color location of the snowflake if building up at the bottom. colorX = snowFlakes.BuildUpX; colorY = snowFlakes.BuildUpY; } //Added the color and then adjusts brightness based on effect time position, randon Brightness and over all brightness level. HSV hsvInner = snowFlakes.OuterHsv; HSV hsvOuter = snowFlakes.InnerHsv; hsvInner.V *= snowFlakes.HsvBrightness * level; Color innerColor = hsvInner.ToRGB(); hsvOuter.V *= snowFlakes.HsvBrightness * level; Color outerColor = hsvOuter.ToRGB(); if (initialBuildUp < BufferHt && colorY >= initialBuildUp - snowflakeOverShoot) { if (snowFlakes.BuildUp) { //Renders a flat Snowflake on the ground with a width based of size of the flake. for (int y = 0; y <= colorY - initialBuildUp; y++) { for (int x = -y - snowflakeWidth; x <= y + snowflakeWidth; x++) { frameBuffer.SetPixel(colorX + x, colorY - y, innerColor); } } } else { //Renders the falling Snowflake switch (snowFlakes.Type) { case SnowflakeType.Single: // single node frameBuffer.SetPixel(colorX, colorY, innerColor); break; case SnowflakeType.Five: // 5 nodes frameBuffer.SetPixel(colorX, colorY, outerColor); //Inner point of the Flake frameBuffer.SetPixel(colorX - 1, colorY, innerColor); frameBuffer.SetPixel(colorX + 1, colorY, innerColor); frameBuffer.SetPixel(colorX, colorY - 1, innerColor); frameBuffer.SetPixel(colorX, colorY + 1, innerColor); break; case SnowflakeType.Three: // 3 nodes frameBuffer.SetPixel(colorX, colorY, outerColor); //Inner point of the Flake if (Rand() % 100 > 50) { frameBuffer.SetPixel(colorX - 1, colorY, innerColor); frameBuffer.SetPixel(colorX + 1, colorY, innerColor); } else { frameBuffer.SetPixel(colorX, colorY - 1, innerColor); frameBuffer.SetPixel(colorX, colorY + 1, innerColor); } break; case SnowflakeType.Nine: // 9 nodes frameBuffer.SetPixel(colorX, colorY, outerColor); //Inner point of the Flake int i; for (i = 1; i <= 2; i++) { frameBuffer.SetPixel(colorX - i, colorY, innerColor); frameBuffer.SetPixel(colorX + i, colorY, innerColor); frameBuffer.SetPixel(colorX, colorY - i, innerColor); frameBuffer.SetPixel(colorX, colorY + i, innerColor); } break; case SnowflakeType.Thirteen: // 13 nodes frameBuffer.SetPixel(colorX, colorY, outerColor); //Inner point of the Flake frameBuffer.SetPixel(colorX - 1, colorY, innerColor); frameBuffer.SetPixel(colorX + 1, colorY, innerColor); frameBuffer.SetPixel(colorX, colorY - 1, innerColor); frameBuffer.SetPixel(colorX, colorY + 1, innerColor); frameBuffer.SetPixel(colorX - 1, colorY + 2, innerColor); frameBuffer.SetPixel(colorX + 1, colorY + 2, innerColor); frameBuffer.SetPixel(colorX - 1, colorY - 2, innerColor); frameBuffer.SetPixel(colorX + 1, colorY - 2, innerColor); frameBuffer.SetPixel(colorX + 2, colorY - 1, innerColor); frameBuffer.SetPixel(colorX + 2, colorY + 1, innerColor); frameBuffer.SetPixel(colorX - 2, colorY - 1, innerColor); frameBuffer.SetPixel(colorX - 2, colorY + 1, innerColor); break; case SnowflakeType.FortyFive: // 45 nodes int ii = 4; for (int j = -4; j < 5; j++) { frameBuffer.SetPixel(colorX + j, colorY + ii, innerColor); ii--; } for (int j = -4; j < 5; j++) { frameBuffer.SetPixel(colorX + j, colorY + j, innerColor); } frameBuffer.SetPixel(colorX - 2, colorY + 3, innerColor); frameBuffer.SetPixel(colorX - 3, colorY + 2, innerColor); frameBuffer.SetPixel(colorX - 3, colorY - 2, innerColor); frameBuffer.SetPixel(colorX - 2, colorY - 3, innerColor); frameBuffer.SetPixel(colorX + 2, colorY + 3, innerColor); frameBuffer.SetPixel(colorX + 2, colorY - 3, innerColor); frameBuffer.SetPixel(colorX + 3, colorY + 2, innerColor); frameBuffer.SetPixel(colorX + 3, colorY - 2, innerColor); for (int j = -5; j < 6; j++) { frameBuffer.SetPixel(colorX, colorY + j, innerColor); } for (int j = -5; j < 6; j++) { frameBuffer.SetPixel(colorX + j, colorY, innerColor); } frameBuffer.SetPixel(colorX, colorY, outerColor); //Inner point of the Flake break; } } } } } // Deletes SnowFlakes that have expired when reaching the edge of the grid, allowing new Snowflakes to be created. int snowFlakeNum = 0; while (snowFlakeNum < _snowFlakes.Count) { if (_snowFlakes[snowFlakeNum].Expired) { _snowFlakes.RemoveAt(snowFlakeNum); } else { snowFlakeNum++; } } }
// renders the given node to the internal ElementData dictionary. If the given node is // not a element, will recursively descend until we render its elements. private void RenderNode(ElementNode node) { foreach (Element element in node) { // this is probably always going to be a single element for the given node, as // we have iterated down to leaf nodes in RenderNode() above. May as well do // it this way, though, in case something changes in future. if (element == null) { continue; } double[] allPointsTimeOrdered = _GetAllSignificantDataPoints().ToArray(); Debug.Assert(allPointsTimeOrdered.Length > 1); double lastPosition = allPointsTimeOrdered[0]; for (int i = 1; i < allPointsTimeOrdered.Length; i++) { double position = allPointsTimeOrdered[i]; LightingValue startValue = new LightingValue(ColorGradient.GetColorAt(lastPosition), (float)LevelCurve.GetValue(lastPosition * 100) / 100); LightingValue endValue = new LightingValue(ColorGradient.GetColorAt(position), (float)LevelCurve.GetValue(position * 100) / 100); TimeSpan startTime = TimeSpan.FromMilliseconds(TimeSpan.TotalMilliseconds * lastPosition); TimeSpan timeSpan = TimeSpan.FromMilliseconds(TimeSpan.TotalMilliseconds * (position - lastPosition)); IIntent intent = new LightingIntent(startValue, endValue, timeSpan); _elementData.AddIntentForElement(element.Id, intent, startTime); lastPosition = position; } } }
protected override void RenderEffect(int frame, IPixelFrameBuffer frameBuffer) { if (frame == 0) { _meteors.Clear(); } int colorcnt = Colors.Count(); int tailLength = (BufferHt < 10) ? Length / 10 : BufferHt * Length / 100; int minDirection = 1; int maxDirection = 360; if (tailLength < 1) { tailLength = 1; } int tailStart = BufferHt; if (tailStart < 1) { tailStart = 1; } // create new meteors and maintain maximum number as per users selection. HSV hsv = new HSV(); int pixelCount = frame < PixelCount ? (!RandomMeteorPosition && frame > PixelCount ? 1 : (PixelCount < 10 ? PixelCount : PixelCount / 10)) : PixelCount; for (int i = 0; i < pixelCount; i++) { double position = RandomSpeed ? (double)_random.Next(MinSpeed, MaxSpeed + 1) / 20 : (double)Speed / 20; if (_meteors.Count >= PixelCount) { continue; } MeteorClass m = new MeteorClass(); if (MeteorEffect == MeteorsEffect.RandomDirection) { minDirection = MinDirection; maxDirection = MaxDirection; } int direction; if (MeteorEffect == MeteorsEffect.None) { direction = Direction; //Set Range for standard Meteor as we don't want to just have them going straight down or two dirctions like the original Meteor effect. } else { //This is to generate random directions between the Min and Max values //However if Someone makes the MaxDirection lower then the Min Direction then //the new direction will be the inverserve of the Min and Max effectively changing //the range from a downward motion to an upward motion, increasing the feature capability. if (maxDirection <= minDirection) { //used for the Upward movement of the Meteor (added feature) direction = _random.Next(1, 3) == 1 ? _random.Next(1, maxDirection) : _random.Next(minDirection, 360); } else { //used for the downward movemnet of the Meteor (standard way) direction = _random.Next(minDirection, maxDirection); } } //Moving m.X = rand() % BufferWi; m.Y = rand() % BufferHt; if (direction >= 0 && direction <= 90) { m.TailX = ((double)direction / 90); m.DeltaX = m.TailX * position; m.TailY = ((double)Math.Abs(direction - 90) / 90); m.DeltaY = m.TailY * position; if (_random.NextDouble() >= (double)(90 - direction) / 100) { m.X = 0; m.Y = rand() % BufferHt; } else { m.X = rand() % BufferWi; m.Y = 0; } } else if (direction > 90 && direction <= 180) { m.TailX = ((double)Math.Abs(direction - 180) / 90); m.DeltaX = m.TailX * position; m.TailY = -1 * ((double)Math.Abs(direction - 90) / 90); m.DeltaY = m.TailY * position; if (_random.NextDouble() >= (double)(180 - direction) / 100) { m.X = rand() % BufferWi; m.Y = BufferHt; } else { m.X = 0; m.Y = rand() % BufferHt; } } else if (direction > 180 && direction <= 270) { m.TailX = -1 * ((double)Math.Abs(direction - 180) / 90); m.DeltaX = m.TailX * position; m.TailY = -1 * ((double)Math.Abs(direction - 270) / 90); m.DeltaY = m.TailY * position; if (_random.NextDouble() >= (double)(270 - direction) / 100) { m.X = BufferWi; m.Y = rand() % BufferHt; } else { m.X = rand() % BufferWi; m.Y = BufferHt; } } else if (direction > 270 && direction <= 360) { m.TailX = -1 * ((double)Math.Abs(direction - 360) / 90); m.DeltaX = m.TailX * position; m.TailY = ((double)Math.Abs(270 - direction) / 90); m.DeltaY = m.TailY * position; if (_random.NextDouble() >= (double)(360 - direction) / 100) { m.X = rand() % BufferWi; m.Y = 0; } else { m.X = BufferWi; m.Y = rand() % BufferHt; } } if (MeteorEffect == MeteorsEffect.Explode) { m.X = BufferWi / 2; m.Y = BufferHt / 2; } else { if (RandomMeteorPosition || frame < PixelCount) { m.X = rand() % BufferWi; m.Y = (BufferHt - 1 - (rand() % tailStart)); } } m.DeltaXOrig = m.DeltaX; m.DeltaYOrig = m.DeltaY; switch (ColorType) { case MeteorsColorType.Range: //Random two colors are selected from the list for each meteor. m.Hsv = SetRangeColor(HSV.FromRGB(Colors[rand() % colorcnt].GetColorAt((GetEffectTimeIntervalPosition(frame) * 100) / 100)), HSV.FromRGB(Colors[rand() % colorcnt].GetColorAt((GetEffectTimeIntervalPosition(frame) * 100) / 100))); break; case MeteorsColorType.Palette: //All colors are used m.Hsv = HSV.FromRGB(Colors[rand() % colorcnt].GetColorAt((GetEffectTimeIntervalPosition(frame) * 100) / 100)); break; case MeteorsColorType.Gradient: m.Color = rand() % colorcnt; _gradientPosition = 100 / (double)tailLength / 100; m.Hsv = HSV.FromRGB(Colors[m.Color].GetColorAt(0)); break; } m.HsvBrightness = RandomBrightness ? _random.NextDouble() * (1.0 - .25) + .25 : 1; _meteors.Add(m); } // render meteors foreach (MeteorClass meteor in _meteors) { meteor.DeltaX += meteor.DeltaXOrig; meteor.DeltaY += meteor.DeltaYOrig; int colorX = (meteor.X + Convert.ToInt32(meteor.DeltaX) - (BufferWi / 100)); int colorY = (meteor.Y + Convert.ToInt32(meteor.DeltaY) + (BufferHt / 100)); for (int ph = 0; ph < tailLength; ph++) { switch (ColorType) { case MeteorsColorType.RainBow: //No user colors are used for Rainbow effect. meteor.Hsv.H = (float)(rand() % 1000) / 1000.0f; meteor.Hsv.S = 1.0f; meteor.Hsv.V = 1.0f; break; case MeteorsColorType.Gradient: meteor.Hsv = HSV.FromRGB(Colors[meteor.Color].GetColorAt(_gradientPosition * ph)); break; } hsv = meteor.Hsv; hsv.V *= meteor.HsvBrightness; hsv.V *= (float)(1.0 - ((double)ph / tailLength) * 0.75); //Adjusts the brightness based on the level curve hsv.V = hsv.V * LevelCurve.GetValue(GetEffectTimeIntervalPosition(frame) * 100) / 100; var decPlaces = (int)(((decimal)(meteor.TailX * ph) % 1) * 100); if (decPlaces <= 40 || decPlaces >= 60) { frameBuffer.SetPixel(colorX - (int)(Math.Round(meteor.TailX * ph)), colorY - (int)(Math.Round(meteor.TailY * ph)), hsv); } } if (colorX >= BufferWi + tailLength || colorY >= BufferHt + tailLength || colorX < 0 - tailLength || colorY < 0 - tailLength) { meteor.Expired = true; //flags Meteors that have reached the end of the grid as expiried. // break; } } // delete old meteors int meteorNum = 0; while (meteorNum < _meteors.Count) { if (_meteors[meteorNum].Expired) { _meteors.RemoveAt(meteorNum); } else { meteorNum++; } } }
protected override void RenderEffect(int frame, ref PixelFrameBuffer frameBuffer) { if (_image == null) { return; } const int speedfactor = 4; double position = (GetEffectTimeIntervalPosition(frame) * Speed) % 1; double level = LevelCurve.GetValue(GetEffectTimeIntervalPosition(frame) * 100) / 100; CalculateImageNumberByPosition(position); _image.SelectActiveFrame(_dimension, (int)_currentGifImageNum); _scaledImage = ScaleToGrid ? ScaleImage(_image, BufferWi, BufferHt) : ScaleImage(_image, _image.Width * ScalePercent / 100, _image.Height * ScalePercent / 100); _fp = new FastPixel.FastPixel(_scaledImage); int imgwidth = _fp.Width; int imght = _fp.Height; int yoffset = (BufferHt + imght) / 2; int xoffset = (imgwidth - BufferWi) / 2; int state = Speed * frame; int xOffsetAdj = XOffset * BufferWi / 100; int yOffsetAdj = YOffset * BufferHt / 100; switch (Type) { case EffectType.RenderPicturePeekaboo0: case EffectType.RenderPicturePeekaboo180: //Peek a boo yoffset = -(BufferHt) + (int)((BufferHt + 5) * position * 2); if (yoffset > 10) { yoffset = -yoffset + 10; //reverse direction } else if (yoffset >= -1) { yoffset = -1; //pause in middle } break; case EffectType.RenderPictureWiggle: if (position >= 0.5) { xoffset += (int)(BufferWi * ((1.0 - position) * 2.0 - 0.5)); } else { xoffset += (int)(BufferWi * (position * 2.0 - 0.5)); } break; case EffectType.RenderPicturePeekaboo90: //peekaboo 90 case EffectType.RenderPicturePeekaboo270: //peekaboo 270 if (Orientation == StringOrientation.Vertical) { yoffset = (imght - BufferWi) / 2; //adjust offsets for other axis } else { yoffset = (imgwidth - BufferHt) / 2; //adjust offsets for other axis } if (Orientation == StringOrientation.Vertical) { xoffset = -(BufferHt) + (int)((BufferHt + 5) * position * 2); } else { xoffset = -(BufferWi) + (int)((BufferWi + 5) * position * 2); } if (xoffset > 10) { xoffset = -xoffset + 10; //reverse direction } else if (xoffset >= -1) { xoffset = -1; //pause in middle } break; } _fp.Lock(); for (int x = 0; x < imgwidth; x++) { for (int y = 0; y < imght; y++) { //if (!image.IsTransparent(x,y)) Color color = _fp.GetPixel(x, y); if (color != Color.Transparent) { var hsv = HSV.FromRGB(color); hsv.V = hsv.V * level; switch (Type) { case EffectType.RenderPictureLeft: // left int leftX = x + (BufferWi - (int)(position * (imgwidth + BufferWi))); frameBuffer.SetPixel(leftX + xOffsetAdj, yoffset - y + yOffsetAdj, hsv); break; case EffectType.RenderPictureRight: // right int rightX = x + -imgwidth + (int)(position * (imgwidth + BufferWi)); frameBuffer.SetPixel(rightX + xOffsetAdj, yoffset - y + yOffsetAdj, hsv); break; case EffectType.RenderPictureUp: // up int upY = (int)((imght + BufferHt) * position) - y; frameBuffer.SetPixel(x - xoffset + xOffsetAdj, upY + yOffsetAdj, hsv); break; case EffectType.RenderPictureDown: // down int downY = (BufferHt + imght - 1) - (int)((imght + BufferHt) * position) - y; frameBuffer.SetPixel(x - xoffset + xOffsetAdj, downY + yOffsetAdj, hsv); break; case EffectType.RenderPictureUpleft: int upLeftY = (int)((imght + BufferHt) * position) - y; frameBuffer.SetPixel(Convert.ToInt32(x + BufferWi - (state % ((imgwidth + BufferWi) * speedfactor)) / speedfactor) + xOffsetAdj, upLeftY + yOffsetAdj, hsv); break; // up-left case EffectType.RenderPictureDownleft: int downLeftY = BufferHt + imght - (int)((imght + BufferHt) * position) - y; frameBuffer.SetPixel(Convert.ToInt32(x + BufferWi - (state % ((imgwidth + BufferWi) * speedfactor)) / speedfactor) + xOffsetAdj, downLeftY + yOffsetAdj, hsv); break; // down-left case EffectType.RenderPictureUpright: int upRightY = (int)((imght + BufferHt) * position) - y; frameBuffer.SetPixel(Convert.ToInt32(x + (state % ((imgwidth + BufferWi) * speedfactor)) / speedfactor - imgwidth) + xOffsetAdj, upRightY + yOffsetAdj, hsv); break; // up-right case EffectType.RenderPictureDownright: int downRightY = BufferHt + imght - (int)((imght + BufferHt) * position) - y; frameBuffer.SetPixel(Convert.ToInt32(x + (state % ((imgwidth + BufferWi) * speedfactor)) / speedfactor - imgwidth) + xOffsetAdj, downRightY + yOffsetAdj, hsv); break; // down-right case EffectType.RenderPicturePeekaboo0: //Peek a boo frameBuffer.SetPixel(x - xoffset + xOffsetAdj, BufferHt + yoffset - y + yOffsetAdj, hsv); break; case EffectType.RenderPictureWiggle: frameBuffer.SetPixel(x + xoffset + xOffsetAdj, yoffset - y + yOffsetAdj, hsv); break; case EffectType.RenderPicturePeekaboo90: frameBuffer.SetPixel(BufferWi + xoffset - y + xOffsetAdj, x - yoffset + yOffsetAdj, hsv); break; case EffectType.RenderPicturePeekaboo180: frameBuffer.SetPixel(x - xoffset + xOffsetAdj, y - yoffset + yOffsetAdj, hsv); break; case EffectType.RenderPicturePeekaboo270: frameBuffer.SetPixel(y - xoffset + xOffsetAdj, BufferHt + yoffset - x + yOffsetAdj, hsv); break; default: // no movement - centered frameBuffer.SetPixel(x - xoffset + xOffsetAdj, yoffset - y + yOffsetAdj, hsv); break; } } } } _fp.Unlock(false); _fp.Dispose(); _scaledImage.Dispose(); }
protected override void RenderEffect(int frame, IPixelFrameBuffer frameBuffer) { int colorcnt = Colors.Count; var intervalPosFactor = GetEffectTimeIntervalPosition(frame) * 100; double level = LevelCurve.GetValue(intervalPosFactor) / 100; var length = CalculateLength(intervalPosFactor); int tailLength = BufferHt < 10 ? length / 10 : BufferHt * length / 100; int minDirection = 1; int maxDirection = 360; int pixelCount = CalculatePixelCount(intervalPosFactor); double centerSpeed = CalculateCenterSpeed(intervalPosFactor); double spreadSpeed = CalculateSpeedVariation(intervalPosFactor); double minSpeed = centerSpeed - (spreadSpeed / 2); double maxSpeed = centerSpeed + (spreadSpeed / 2); if (minSpeed < 0) { minSpeed = 0; } if (maxSpeed > 200) { maxSpeed = 200; } if (tailLength < 1) { tailLength = 1; } double xSpeedRatio = 1; double ySpeedRatio = 1; double minXSpeed = 1; double maxXSpeed = 1; double minYSpeed = 1; double maxYSpeed = 1; int minWobble = 1; int maxWobble = 1; double wobbleRatio = 1; switch (MeteorMovement) { case MeteorMovement.Speed: { // Horizontal Speed Control double xCenterSpeed = CalculateXCenterSpeed(intervalPosFactor); double xSpreadSpeed = CalculateXSpeedVariation(intervalPosFactor); minXSpeed = xCenterSpeed - (xSpreadSpeed / 2); maxXSpeed = xCenterSpeed + (xSpreadSpeed / 2); if (minXSpeed < -100) { minXSpeed = -100; } if (maxXSpeed > 100) { maxXSpeed = 100; } if (xCenterSpeed != 0) { if (frame != 0) { xSpeedRatio = xCenterSpeed / _xSpeedAdjustment; } _xSpeedAdjustment = xCenterSpeed; } // Vertical Speed Control double yCenterSpeed = CalculateYCenterSpeed(intervalPosFactor); double ySpreadSpeed = CalculateYSpeedVariation(intervalPosFactor); minYSpeed = yCenterSpeed - (ySpreadSpeed / 2); maxYSpeed = yCenterSpeed + (ySpreadSpeed / 2); if (minYSpeed < -100) { minYSpeed = -100; } if (maxYSpeed > 100) { maxYSpeed = 100; } if (yCenterSpeed != 0) { if (frame != 0) { ySpeedRatio = yCenterSpeed / _ySpeedAdjustment; } _ySpeedAdjustment = yCenterSpeed; } break; } // Wobble Control case MeteorMovement.Wobble: case MeteorMovement.Wobble2: { double wobbleCenterPosition = CalculateWobbleCenter(intervalPosFactor); double wobbleSpreadPosition = CalculateWobbleVariation(intervalPosFactor); minWobble = (int)(wobbleCenterPosition - (wobbleSpreadPosition / 2)); maxWobble = (int)(wobbleCenterPosition + (wobbleSpreadPosition / 2)); if (minWobble < -_maxBufferSize) { minWobble = -_maxBufferSize; } if (maxWobble > _maxBufferSize) { maxWobble = _maxBufferSize; } if (wobbleCenterPosition != 0) { if (frame != 0) { wobbleRatio = wobbleCenterPosition / _wobbleAdjustment; } _wobbleAdjustment = (int)wobbleCenterPosition; } break; } } // create new meteors and maintain maximum number as per users selection. HSV hsv; int adjustedPixelCount; if (frame < pixelCount) { if (MeteorStartPosition == MeteorStartPosition.InitiallyRandom && frame > pixelCount) { adjustedPixelCount = 1; } else if (MeteorStartPosition == MeteorStartPosition.ZeroPosition) { adjustedPixelCount = pixelCount; } else { adjustedPixelCount = pixelCount < 10 || MeteorMovement >= MeteorMovement.Wobble ? pixelCount : pixelCount / 10; } } else { adjustedPixelCount = pixelCount; } int stringCount = 1; if (CountPerString && MeteorPerString) { stringCount = BufferWi; } for (int i = 0; i < adjustedPixelCount; i++) { for (int j = 0; j < stringCount; j++) { if (_meteors.Count >= pixelCount * stringCount) { break; } double position = (RandDouble() * ((maxSpeed) - minSpeed) + minSpeed) / 20; MeteorClass m = new MeteorClass(); if (MeteorEffect == MeteorsEffect.RandomDirection) { minDirection = MinDirection; maxDirection = MaxDirection; } int direction; if (MeteorEffect == MeteorsEffect.None) { direction = Direction; //Set Range for standard Meteor as we don't want to just have them going straight down or two directions like the original Meteor effect. } else { //This is to generate random directions between the Min and Max values //However if Someone makes the MaxDirection lower then the Min Direction then //the new direction will be the inverse of the Min and Max effectively changing //the range from a downward motion to an upward motion, increasing the feature capability. if (maxDirection <= minDirection) { //used for the Upward movement of the Meteor (added feature) direction = Rand(1, 3) == 1 ? Rand(1, maxDirection) : Rand(minDirection, 360); } else { //used for the downward movement of the Meteor (standard way) direction = Rand(minDirection, maxDirection); } } //Moving if (!CountPerString) { m.X = Rand() % BufferWi; } m.Y = Rand() % BufferHt; if (MeteorPerString) { m.TailY = FlipDirection ? 1 : -1; if (CountPerString) { var meteorExists = false; foreach (var meteor in _meteors) { if (meteor.X == j) { meteorExists = true; break; } } if (meteorExists) { continue; } m.X = j; } m.DeltaY = m.TailY * position; m.Y = Rand() % BufferHt; m.WobbleX = -1 * ((double)Math.Abs(direction - 270) / 90); m.WobbleY = -1 * ((double)Math.Abs(direction - 360) / 90); } else if (direction >= 0 && direction <= 90) { m.TailX = ((double)direction / 90); m.DeltaX = m.TailX * position; m.TailY = ((double)Math.Abs(direction - 90) / 90); m.DeltaY = m.TailY * position; if (RandDouble() >= (double)(90 - direction) / 100) { m.X = 0; m.Y = Rand() % BufferHt; } else { m.X = Rand() % BufferWi; m.Y = 0; } m.WobbleX = ((double)Math.Abs(direction - 90) / 90); m.WobbleY = -1 * ((double)Math.Abs(direction) / 90); } else if (direction > 90 && direction <= 180) { m.TailX = ((double)Math.Abs(direction - 180) / 90); m.DeltaX = m.TailX * position; m.TailY = -1 * ((double)Math.Abs(direction - 90) / 90); m.DeltaY = m.TailY * position; if (RandDouble() >= (double)(180 - direction) / 100) { m.X = Rand() % BufferWi; m.Y = BufferHt; } else { m.X = 0; m.Y = Rand() % BufferHt; } m.WobbleX = -1 * ((double)Math.Abs(direction - 90) / 90); m.WobbleY = -1 * ((double)Math.Abs(direction - 180) / 90); } else if (direction > 180 && direction <= 270) { m.TailX = -1 * ((double)Math.Abs(direction - 180) / 90); m.DeltaX = m.TailX * position; m.TailY = -1 * ((double)Math.Abs(direction - 270) / 90); m.DeltaY = m.TailY * position; if (RandDouble() >= (double)(270 - direction) / 100) { m.X = BufferWi; m.Y = Rand() % BufferHt; } else { m.X = Rand() % BufferWi; m.Y = BufferHt; } m.WobbleX = ((double)Math.Abs(direction - 90) / 90); m.WobbleY = -1 * ((double)Math.Abs(direction - 180) / 90); } else if (direction > 270 && direction <= 360) { m.TailX = -1 * ((double)Math.Abs(direction - 360) / 90); m.DeltaX = m.TailX * position; m.TailY = ((double)Math.Abs(270 - direction) / 90); m.DeltaY = m.TailY * position; if (RandDouble() >= (double)(360 - direction) / 100) { m.X = Rand() % BufferWi; m.Y = 0; } else { m.X = BufferWi; m.Y = Rand() % BufferHt; } m.WobbleX = -1 * ((double)Math.Abs(direction - 270) / 90); m.WobbleY = -1 * ((double)Math.Abs(direction - 360) / 90); } if (MeteorEffect == MeteorsEffect.Explode) { m.X = (BufferWi - 1) / 2; m.Y = (BufferHt - 1) / 2; } else { if (MeteorStartPosition == MeteorStartPosition.ZeroPosition) { if (MeteorPerString) { m.Y = FlipDirection ? 0 : BufferHt; } } else if (MeteorStartPosition == MeteorStartPosition.Random || frame < pixelCount) { if (!MeteorPerString) { m.X = Rand() % BufferWi - 1; } m.Y = BufferHt - 1 <= _maxGroundHeight ? 0 : Rand(_maxGroundHeight, BufferHt - 1); } } m.DeltaXOrig = m.DeltaX; m.DeltaYOrig = m.DeltaY; if (MeteorMovement == MeteorMovement.Speed) { m.XSpeed = (RandDouble() * ((maxXSpeed) - minXSpeed) + minXSpeed); m.YSpeed = (RandDouble() * ((maxYSpeed) - minYSpeed) + minYSpeed); } m.Wobble = Rand(minWobble, maxWobble); if (Rand(0, 2) == 1 && MeteorMovement == MeteorMovement.Wobble2) { m.Wobble = -m.Wobble; } switch (ColorType) { case MeteorsColorType.Range: //Random two colors are selected from the list for each meteor. m.Hsv = SetRangeColor( HSV.FromRGB(Colors[Rand() % colorcnt].GetColorAt((intervalPosFactor) / 100)), HSV.FromRGB(Colors[Rand() % colorcnt].GetColorAt((intervalPosFactor) / 100))); break; case MeteorsColorType.Palette: //All colors are used m.Hsv = HSV.FromRGB(Colors[Rand() % colorcnt].GetColorAt((intervalPosFactor) / 100)); break; case MeteorsColorType.Gradient: m.Color = Rand() % colorcnt; _gradientPosition = 100 / (double)tailLength / 100; m.Hsv = HSV.FromRGB(Colors[m.Color].GetColorAt(0)); break; } m.HsvBrightness = RandomBrightness ? RandDouble() * (1.0 - .20) + .20 : 1; _meteors.Add(m); } } if (EnableGroundLevel) { hsv = HSV.FromRGB(GroundColor.GetColorAt((intervalPosFactor) / 100)); hsv.V *= LevelCurve.GetValue(intervalPosFactor) / 100; for (int x = 0; x < BufferWi; x++) { for (int y = 0; y < CalculateGroundLevel(((double)100 / BufferWi) * x); y++) { if (_tempBuffer.GetColorAt(x, y) != Color.Empty) { frameBuffer.SetPixel(x, y, hsv); } } } } // render meteors foreach (MeteorClass meteor in _meteors) { int xOffsetAdj = 0; int yOffsetAdj = 0; if (MeteorMovement >= MeteorMovement.Wobble) { xOffsetAdj = (int)(meteor.WobbleX * meteor.Wobble); yOffsetAdj = (int)(meteor.WobbleY * meteor.Wobble); } meteor.DeltaX += meteor.DeltaXOrig + meteor.XSpeed; meteor.DeltaY += meteor.DeltaYOrig + meteor.YSpeed; int colorX = xOffsetAdj + meteor.X + (int)meteor.DeltaX - BufferWi / 100; int colorY = yOffsetAdj + meteor.Y + (int)meteor.DeltaY + BufferHt / 100; if (MeteorMovement >= MeteorMovement.Wobble) { if (colorX < 0) { colorX = BufferWi + colorX; } if (colorY < 0) { colorY = BufferHt + colorY; } if (colorX > BufferWi) { colorX = colorX - BufferWi; } if (colorY > BufferHt) { colorY = colorY - BufferHt; } } for (int ph = 0; ph < tailLength; ph++) { switch (ColorType) { case MeteorsColorType.RainBow: //No user colors are used for Rainbow effect. meteor.Hsv.H = (float)(Rand() % 1000) / 1000.0f; meteor.Hsv.S = 1.0f; meteor.Hsv.V = 1.0f; break; case MeteorsColorType.Gradient: meteor.Hsv = HSV.FromRGB(Colors[meteor.Color].GetColorAt(_gradientPosition * ph)); break; } hsv = meteor.Hsv; hsv.V *= meteor.HsvBrightness * (float)(1.0 - (double)ph / tailLength) * level; //var decPlaces = (int) (((decimal) (meteor.TailX*ph)%1)*100); var decPlaces = (int)(meteor.TailX * ph % 1d * 100); if (decPlaces <= 40 || decPlaces >= 60) { if (MeteorEffect == MeteorsEffect.Explode && ph > 0 && (colorX == (BufferWi / 2) + (int)(Math.Round(meteor.TailX * ph)) || colorX == (BufferWi / 2) - (int)(Math.Round(meteor.TailX * ph)) || colorY == (BufferHt / 2) + (int)(Math.Round(meteor.TailY * ph)) || colorY == (BufferHt / 2) - (int)(Math.Round(meteor.TailY * ph)))) { break; } frameBuffer.SetPixel(colorX - (int)(Math.Round(meteor.TailX * ph)), colorY - (int)(Math.Round(meteor.TailY * ph)), hsv); } } if (colorX > 0 && colorX < BufferWi - 1 && colorY > 0 && colorY < BufferHt && EnableGroundLevel) { if (!_tempBuffer.GetColorAt(colorX, colorY).IsEmpty) { if (frame > 1) { _tempBuffer.SetPixel(colorX, colorY, Color.Empty); _tempBuffer.SetPixel(colorX, colorY - 1, Color.Empty); _tempBuffer.SetPixel(colorX - 1, colorY, Color.Empty); _tempBuffer.SetPixel(colorX + 1, colorY, Color.Empty); _tempBuffer.SetPixel(colorX, colorY + 1, Color.Empty); _tempBuffer.SetPixel(colorX + 1, colorY + 1, Color.Empty); _tempBuffer.SetPixel(colorX - 1, colorY + 1, Color.Empty); _tempBuffer.SetPixel(colorX + 1, colorY + 2, Color.Empty); _tempBuffer.SetPixel(colorX - 1, colorY + 2, Color.Empty); _tempBuffer.SetPixel(colorX + 1, colorY + 3, Color.Empty); _tempBuffer.SetPixel(colorX - 1, colorY + 3, Color.Empty); _tempBuffer.SetPixel(colorX + 2, colorY + 3, Color.Empty); _tempBuffer.SetPixel(colorX - 2, colorY + 3, Color.Empty); _tempBuffer.SetPixel(colorX + 2, colorY + 2, Color.Empty); _tempBuffer.SetPixel(colorX - 2, colorY + 2, Color.Empty); _tempBuffer.SetPixel(colorX, colorY + 2, Color.Empty); _tempBuffer.SetPixel(colorX, colorY + 3, Color.Empty); _tempBuffer.SetPixel(colorX - 2, colorY + 4, Color.Empty); _tempBuffer.SetPixel(colorX - 1, colorY + 4, Color.Empty); _tempBuffer.SetPixel(colorX, colorY + 4, Color.Empty); _tempBuffer.SetPixel(colorX + 1, colorY + 4, Color.Empty); _tempBuffer.SetPixel(colorX + 2, colorY + 4, Color.Empty); } meteor.Expired = true; } } if (colorX >= BufferWi + tailLength || colorY >= BufferHt + tailLength || colorX < 0 - tailLength || colorY < 0 - tailLength) { meteor.Expired = true; //flags Meteors that have reached the end of the grid as expiried. // break; } meteor.XSpeed = meteor.XSpeed * xSpeedRatio; meteor.YSpeed = meteor.YSpeed * ySpeedRatio; meteor.Wobble = meteor.Wobble * wobbleRatio; switch (MeteorMovement) { case MeteorMovement.Speed when meteor.Expired: case MeteorMovement.Wobble when meteor.Expired: case MeteorMovement.Wobble2 when meteor.Expired: case MeteorMovement.Wrap when meteor.Expired: { if (colorX < 0) { meteor.DeltaX = 0; meteor.X = BufferWi; } if (colorY < 0) { meteor.DeltaY = 0; meteor.Y = BufferHt; } if (colorX > BufferWi) { meteor.DeltaX = 0; meteor.X = 0; } if (colorY > BufferHt) { meteor.DeltaY = 0; meteor.Y = 0; } meteor.Expired = false; break; } case MeteorMovement.Bounce when meteor.Expired: { if (colorX < 0) { meteor.X = 0; meteor.DeltaX = 0; meteor.DeltaXOrig = -meteor.DeltaXOrig; meteor.TailX = -meteor.TailX; meteor.XSpeed = -meteor.XSpeed; } if (colorY < 0) { meteor.Y = 0; meteor.DeltaY = 0; meteor.DeltaYOrig = -meteor.DeltaYOrig; meteor.TailY = -meteor.TailY; meteor.YSpeed = -meteor.YSpeed; } if (colorX > BufferWi) { meteor.X = BufferWi; meteor.DeltaX = 0; meteor.DeltaXOrig = -meteor.DeltaXOrig; meteor.TailX = -meteor.TailX; meteor.XSpeed = -meteor.XSpeed; } if (colorY > BufferHt) { meteor.Y = BufferHt; meteor.DeltaY = 0; meteor.DeltaYOrig = -meteor.DeltaYOrig; meteor.TailY = -meteor.TailY; meteor.YSpeed = -meteor.YSpeed; } meteor.Expired = false; break; } } } if (MeteorMovement == MeteorMovement.None) { // delete old meteors int meteorNum = 0; while (meteorNum < _meteors.Count) { if (_meteors[meteorNum].Expired) { _meteors.RemoveAt(meteorNum); } else { meteorNum++; } } } }
protected override void RenderEffect(int frame, IPixelFrameBuffer frameBuffer) { int colorcnt = Colors.Count; var intervalPos = GetEffectTimeIntervalPosition(frame); var intervalPosFactor = intervalPos * 100; var adjustSpeed = CalculateSpeed(intervalPosFactor); int count = Convert.ToInt32(BufferWi * BufferHt * CalculateCount(intervalPosFactor) / 2000) + 1; int tailLength = (int)Math.Round(BufferWi * BufferHt * CalculateLength(intervalPosFactor) / 2000 + 2); double level = LevelCurve.GetValue(intervalPosFactor) / 100; Point xy = new Point(); int r; if (frame == 0) { _snowstormItems.Clear(); } // create snowstorm elements for (int i = 0; i < count; i++) { if (_snowstormItems.Count < count) { var ssItem = new SnowstormClass(); ssItem.Idx = i; ssItem.SsDecay = 0; ssItem.Points.Clear(); switch (ColorType) { case SnowStormColorType.Range: //Random two colors are selected from the list for each Snowstorms. ssItem.Hsv = SetRangeColor(HSV.FromRGB(Colors[rand() % colorcnt].GetColorAt((intervalPosFactor) / 100)), HSV.FromRGB(Colors[rand() % colorcnt].GetColorAt((intervalPosFactor) / 100))); break; case SnowStormColorType.Palette: //All colors are used ssItem.Hsv = HSV.FromRGB(Colors[rand() % colorcnt].GetColorAt((intervalPosFactor) / 100)); break; case SnowStormColorType.Gradient: ssItem.Color = rand()%colorcnt; _gradientPosition = 100/(double) tailLength/100; ssItem.Hsv = HSV.FromRGB(Colors[ssItem.Color].GetColorAt(0)); break; } // start in a random state r = rand()%(2*tailLength); if (r > 0) { xy.X = rand()%BufferWi; xy.Y = rand()%BufferHt; //ssItem.points.push_back(xy); ssItem.Points.Add(xy); } if (r >= tailLength) { ssItem.SsDecay = r - tailLength; r = tailLength; } for (int j = 1; j < r; j++) { SnowstormAdvance(ssItem); } _snowstormItems.Add(ssItem); } } // render Snowstorm Items foreach (SnowstormClass it in _snowstormItems) { if (it.Points.Count == 0) { xy.X = rand() % BufferWi; xy.Y = rand() % BufferHt; it.Points.Add(xy); } else if (rand() % 20 < adjustSpeed) { SnowstormAdvance(it); } var sz = it.Points.Count(); for (int pt = 0; pt < sz; pt++) { switch (ColorType) { case SnowStormColorType.RainBow: //No user colors are used for Rainbow effect. it.Hsv.H = (float)(rand() % 1000) / 1000.0f; it.Hsv.S = 1.0f; it.Hsv.V = 1.0f; break; case SnowStormColorType.Gradient: it.Hsv = HSV.FromRGB(Colors[it.Color].GetColorAt(_gradientPosition * pt)); break; } var hsv = it.Hsv; hsv.V = (float)(1.0 - (double)(sz - pt + it.SsDecay) / tailLength); hsv.V *= level; if (it.Points[pt].X >= BufferWi - 1 || it.Points[pt].Y >= BufferHt - 1 || it.Points[pt].X <= 1 || it.Points[pt].Y <= 1) { it.Expired = true; //flags Snowstorms that have reached the end of the grid as expiried. break; } if (hsv.V < 0.0) hsv.V = 0.0f; if (!ReverseDirection) { frameBuffer.SetPixel(it.Points[pt].X, it.Points[pt].Y, hsv); } else { frameBuffer.SetPixel(BufferWi - it.Points[pt].X, it.Points[pt].Y, hsv); } } } // delete old Snowstorms int snowStorms = 0; while (snowStorms < _snowstormItems.Count) { if (_snowstormItems[snowStorms].Expired) { _snowstormItems.RemoveAt(snowStorms); } else { snowStorms++; } } }
protected override void RenderEffect(int frame, IPixelFrameBuffer frameBuffer) { var intervalPos = GetEffectTimeIntervalPosition(frame); var intervalPosFactor = intervalPos * 100; int colorcnt = Colors.Count(); int spiralCount = colorcnt * Repeat; int deltaStrands = BufferWi / spiralCount; int spiralThickness = (deltaStrands * CalculateThickness(intervalPosFactor) / 100) + 1; double adjustRotation = CalculateRotation(intervalPosFactor); int spiralGap = deltaStrands - spiralThickness; int thicknessState = 0; int spiralState = 0; double position = (intervalPos * Speed) % 1; switch (Direction) { case SpiralDirection.Forward: spiralState = (int)(position * BufferWi * 10); break; case SpiralDirection.Backwards: spiralState = (int)(position * BufferWi * -10); break; } if (Grow && Shrink) { thicknessState = (int)(position <= 0.5 ? spiralGap * (position * 2) : spiralGap * ((1 - position) * 2)); } else if (Grow) { thicknessState = (int)(spiralGap * position); } else if (Shrink) { thicknessState = (int)(spiralGap * (1.0 - position)); } spiralThickness += thicknessState; double level = LevelCurve.GetValue(intervalPos * 100) / 100; for (int ns = 0; ns < spiralCount; ns++) { var strandBase = ns * deltaStrands; int colorIdx = ns % colorcnt; int thick; for (thick = 0; thick < spiralThickness; thick++) { var strand = (strandBase + thick) % BufferWi; int y; for (y = 0; y < BufferHt; y++) { Color color; var x = (strand + (spiralState / 10) + (y * (int)adjustRotation / BufferHt)) % BufferWi; if (x < 0) { x += BufferWi; } if (Blend) { color = Colors[colorIdx].GetColorAt((double)(BufferHt - y - 1) / BufferHt); } else { color = Colors[colorIdx].GetColorAt((double)thick / spiralThickness); } if (Show3D) { var hsv = HSV.FromRGB(color); if (Direction != SpiralDirection.Backwards) { hsv.V = (float)((double)(thick + 1) / spiralThickness); } else { hsv.V = (float)((double)(spiralThickness - thick) / spiralThickness); } hsv.V = hsv.V * level; frameBuffer.SetPixel(x, y, hsv); } else { var hsv = HSV.FromRGB(color); hsv.V = hsv.V * level; frameBuffer.SetPixel(x, y, hsv); } } } } }
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); } } }