public Color[,] RenderEffect(Color[,] buffer, Color[] palette, int eventToRender) { const int speedFactor = 200; var bufferHeight = buffer.GetLength(Utils.IndexRowsOrHeight); var bufferWidth = buffer.GetLength(Utils.IndexColsOrWidth); Color color; var hsv2 = new HSV(); var colorcnt = palette.Length; var cycleLen = colorcnt * speedFactor; var count = tbCount.Value; if (eventToRender > (colorcnt - 1) * speedFactor * count && count < 10) { color = palette.GetMultiColorBlend(count % 2, false); } else { color = palette.GetMultiColorBlend(eventToRender % cycleLen / (double)cycleLen, true); } var hsv = color.ToHSV(); var halfHeight = (bufferHeight - 1) / 2.0; var halfWidth = (bufferWidth - 1) / 2.0; for (var col = 0; col < bufferWidth; col++) { for (var row = 0; row < bufferHeight; row++) { hsv2.SetToHSV(hsv); if (chkBoxHFade.Checked) hsv2.Value *= (float)(1.0 - Math.Abs(halfWidth - col) / halfWidth); if (chkBoxVFade.Checked) hsv2.Value *= (float)(1.0 - Math.Abs(halfHeight - row) / halfHeight); buffer[row, col] = hsv2.ToColor(); } } return buffer; }
public Color[,] RenderEffect(Color[,] buffer, Color[] palette, int eventToRender) { var h = 0.0; var bufferHeight = buffer.GetLength(Utils.IndexRowsOrHeight); var bufferWidth = buffer.GetLength(Utils.IndexColsOrWidth); var hsv = new HSV(); var maxframe = bufferHeight*2; var frame = (int) ((bufferHeight*(double) eventToRender/200.0)%maxframe); var offset = eventToRender/100.0; for (var col = 0; col < bufferWidth; col++) { for (var row = 0; row < bufferHeight; row++) { double x1; double y1; double f; switch (tbStyle.Value) { case 1: var n = Math.Abs((col*col - row*row)* Math.Sin(offset + ((col + row)*Pi2/(bufferHeight + bufferWidth)))); var d = col*col + row*row + 1; h = n/d; break; case 2: f = (frame < maxframe/2) ? frame + 1 : maxframe - frame; x1 = (col - bufferWidth/2.0)/f; y1 = (row - bufferHeight/2.0)/f; h = Math.Sqrt(x1*x1 + y1*y1); break; case 3: f = (frame < maxframe/2) ? frame + 1 : maxframe - frame; f = f*0.1 + bufferHeight/60.0; x1 = (col - bufferWidth/2.0)/f; y1 = (row - bufferHeight/2.0)/f; h = Math.Sin(x1)*Math.Cos(y1); break; } hsv.Saturation = 1.0f; hsv.Value = 1.0f; var chunks = tbChunks.Value; var skip = tbSkip.Value; if (chunks > 1 && ((int) (h*chunks))%skip == 0) { continue; } Color color; if (cbColors.SelectedIndex == 0) { hsv.Hue = (float) h; color = hsv.ToColor(); } else { color = palette.GetMultiColorBlend(h, false); } buffer[row, col] = color; } } return buffer; }
private void InitFirePalette(float hue) { _firePalette = new Color[200]; var hsv = new HSV {Hue = hue, Saturation = 1.0f}; for (var i = 0; i < 100; i++) { hsv.Value = i / 100.0f; _firePalette[i] = hsv.ToColor(); } hsv.Value = 1.0f; for (var i = 0; i < 100; i++) { _firePalette[i + 100] = hsv.ToColor(); hsv.Hue = (hsv.Hue + 0.00166666f) % 1f; } }
public static HSV CreateRangeTo(this HSV hsv1, HSV hsv2) { var newHsv = new HSV(RandomRange(hsv1.Hue, hsv2.Hue), RandomRange(hsv1.Saturation, hsv2.Saturation), 1.0f); return newHsv; }
public static HSV CreateRangeTo(this HSV hsv1, HSV hsv2) { var newHsv = new HSV(RandomRange(hsv1.Hue, hsv2.Hue), RandomRange(hsv1.Saturation, hsv2.Saturation), 1.0f); return(newHsv); }
public Color[,] RenderEffect(Color[,] buffer, Color[] palette, int eventToRender) { if (eventToRender == 0) _meteors.Clear(); var bufferHeight = buffer.GetLength(Utils.IndexRowsOrHeight); var bufferWidth = buffer.GetLength(Utils.IndexColsOrWidth); var mspeed = eventToRender - _lastRenderedEvent; _lastRenderedEvent = eventToRender; // create new meteors var hsv = new HSV(); var hsv0 = palette[0].ToHSV(); var hsv1 = (palette.Length > 1 ? palette[1] : palette[0]).ToHSV(); var colorcnt = palette.Length; var count = bufferWidth * tbCount.Value / 100; var tailLength = (bufferHeight < 10) ? tbTrailLength.Value / 10 : bufferHeight * tbTrailLength.Value / 100; if (tailLength < 1) tailLength = 1; var tailStart = bufferHeight - tailLength; if (tailStart < 1) tailStart = 1; for (var i = 0; i < count; i++) { var m = new MeteorClass {X = _random.Next() % bufferWidth, Y = bufferHeight - 1 - (_random.Next() % tailStart)}; switch (cbType.SelectedIndex) { case 1: m.HSV = hsv0.CreateRangeTo(hsv1); break; case 2: m.HSV = palette[_random.Next() % colorcnt].ToHSV() ; break; } _meteors.Add(m); } // render meteors foreach (var meteor in _meteors) { { for (var ph = 0; ph < tailLength; ph++) { switch (cbType.SelectedIndex) { case 0: hsv.Hue = _random.Next() % 1000 / 1000.0f; hsv.Saturation = 1.0f; hsv.Value = 1.0f; break; default: hsv.SetToHSV(meteor.HSV); break; } hsv.Value *= (float)(1.0 - (double)ph / tailLength); if (meteor.X < 0 || meteor.X >= bufferWidth || meteor.Y + ph < 0 || meteor.Y + ph >= bufferHeight) { continue; } var y = meteor.Y + (chkBoxUp.Checked ? -ph : ph); if (y >= 0 && y < bufferHeight) { buffer[y, meteor.X] = hsv.ToColor(); } } meteor.Y += (chkBoxUp.Checked ? mspeed : -mspeed); } } // delete old meteors var meteorNum = 0; while (meteorNum < _meteors.Count) { if (_meteors[meteorNum].HasExpired(tailLength)) { _meteors.RemoveAt(meteorNum); } else { meteorNum++; } } return buffer; }