コード例 #1
0
ファイル: PixelEffectBase.cs プロジェクト: Evilfish2000/vixen
 protected abstract void RenderEffect(int frameNum, ref PixelFrameBuffer frameBuffer);
コード例 #2
0
ファイル: PixelEffectBase.cs プロジェクト: Evilfish2000/vixen
        protected EffectIntents RenderNode(ElementNode node)
        {
            EffectIntents effectIntents = new EffectIntents();
            int nFrames = (int)(TimeSpan.TotalMilliseconds / FrameTime);
            if (nFrames <= 0) return effectIntents;
            var buffer = new PixelFrameBuffer(BufferWi, BufferHt, UseBaseColor?BaseColor:Color.Transparent);

            int bufferSize = StringPixelCounts.Sum();

            TimeSpan startTime = TimeSpan.Zero;

            // set up arrays to hold the generated colors
            var pixels = new RGBValue[bufferSize][];
            for (int eidx = 0; eidx < bufferSize; eidx++)
                pixels[eidx] = new RGBValue[nFrames];

            // generate all the pixels
            for (int frameNum = 0; frameNum < nFrames; frameNum++)
            {
                if (UseBaseColor)
                {
                    var level = BaseLevelCurve.GetValue(GetEffectTimeIntervalPosition(frameNum)*100)/100;
                    buffer.ClearBuffer(level);
                }
                else
                {
                    buffer.ClearBuffer();
                }

                RenderEffect(frameNum, ref buffer);
                // peel off this frames pixels...
                if (StringOrientation == StringOrientation.Horizontal)
                {
                    int i = 0;
                    for (int y = 0; y < BufferHt; y++)
                    {
                        for (int x = 0; x < StringPixelCounts[y]; x++)
                        {
                            pixels[i][frameNum] = new RGBValue(buffer.GetColorAt(x,y));
                            i++;
                        }
                    }
                }
                else
                {
                    int i = 0;
                    for (int x = 0; x < BufferWi; x++)
                    {
                        for (int y = 0; y < StringPixelCounts[x]; y++)
                        {
                            pixels[i][frameNum] = new RGBValue(buffer.GetColorAt(x, y));
                            i++;
                        }
                    }
                }
            };

            // create the intents
            var frameTs = new TimeSpan(0, 0, 0, 0, FrameTime);
            List<Element> elements = node.ToList();
            int numElements = node.Count();
            for (int eidx = 0; eidx < numElements; eidx++)
            {
                IIntent intent = new StaticArrayIntent<RGBValue>(frameTs, pixels[eidx], TimeSpan);
                effectIntents.AddIntentForElement(elements[eidx].Id, intent, startTime);
            }

            return effectIntents;
        }
コード例 #3
0
ファイル: Fire.cs プロジェクト: stewmc/vixen
		protected override void RenderEffect(int frame, ref PixelFrameBuffer frameBuffer)
		{
			double position = GetEffectTimeIntervalPosition(frame);
			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);
			}

			double interval = GetEffectTimeIntervalPosition(frame);

			int h = (int)Height.GetValue(interval*100);

			
			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 (HueShift > 0)
					{
						hsv.H = hsv.H + (HueShift / 100.0f);
					}

					hsv.V = hsv.V * LevelCurve.GetValue(position * 100) / 100;
					//if (color.R == 0 && color.G == 0 && color.B == 0)
					//{
					//	color = Color.Transparent;
					//}
					
					frameBuffer.SetPixel(xp, yp, hsv);
				}
			}
		}
コード例 #4
0
ファイル: Text.cs プロジェクト: naztrain/vixen
        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 xlimit = (BufferWi + _maxTextSize) * 8 + 1;
                    int ylimit = (BufferHt + maxht) * 8 + 1;
                    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))
                            {
                                frameBuffer.SetPixel(x, y, color);
                            }

                        }
                    }

                }

            }
        }
コード例 #5
0
ファイル: PixelEffectBase.cs プロジェクト: thorhs/vixen
        protected EffectIntents RenderNode(ElementNode node)
        {
            EffectIntents effectIntents = new EffectIntents();
            int           nFrames       = (int)(TimeSpan.TotalMilliseconds / FrameTime);

            if (nFrames <= 0)
            {
                return(effectIntents);
            }
            var buffer = new PixelFrameBuffer(BufferWi, BufferHt, UseBaseColor?BaseColor:Color.Transparent);

            int bufferSize = StringPixelCounts.Sum();

            TimeSpan startTime = TimeSpan.Zero;

            // set up arrays to hold the generated colors
            var pixels = new RGBValue[bufferSize][];

            for (int eidx = 0; eidx < bufferSize; eidx++)
            {
                pixels[eidx] = new RGBValue[nFrames];
            }

            // generate all the pixels
            for (int frameNum = 0; frameNum < nFrames; frameNum++)
            {
                if (UseBaseColor)
                {
                    var level = BaseLevelCurve.GetValue(GetEffectTimeIntervalPosition(frameNum) * 100) / 100;
                    buffer.ClearBuffer(level);
                }
                else
                {
                    buffer.ClearBuffer();
                }

                RenderEffect(frameNum, ref buffer);
                // peel off this frames pixels...
                if (StringOrientation == StringOrientation.Horizontal)
                {
                    int i = 0;
                    for (int y = 0; y < BufferHt; y++)
                    {
                        for (int x = 0; x < StringPixelCounts[y]; x++)
                        {
                            pixels[i][frameNum] = new RGBValue(buffer.GetColorAt(x, y));
                            i++;
                        }
                    }
                }
                else
                {
                    int i = 0;
                    for (int x = 0; x < BufferWi; x++)
                    {
                        for (int y = 0; y < StringPixelCounts[x]; y++)
                        {
                            pixels[i][frameNum] = new RGBValue(buffer.GetColorAt(x, y));
                            i++;
                        }
                    }
                }
            }
            ;

            // create the intents
            var            frameTs     = new TimeSpan(0, 0, 0, 0, FrameTime);
            List <Element> elements    = node.ToList();
            int            numElements = node.Count();

            for (int eidx = 0; eidx < numElements; eidx++)
            {
                IIntent intent = new StaticArrayIntent <RGBValue>(frameTs, pixels[eidx], TimeSpan);
                effectIntents.AddIntentForElement(elements[eidx].Id, intent, startTime);
            }

            return(effectIntents);
        }
コード例 #6
0
ファイル: Bars.cs プロジェクト: stewmc/vixen
		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;
					}
				}
			}
		}
コード例 #7
0
ファイル: PixelEffectBase.cs プロジェクト: thorhs/vixen
 protected abstract void RenderEffect(int frameNum, ref PixelFrameBuffer frameBuffer);
コード例 #8
0
ファイル: Picture.cs プロジェクト: stewmc/vixen
		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();
		}
コード例 #9
0
ファイル: Fireworks.cs プロジェクト: stewmc/vixen
		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);
				}
			}
			
				
		}
コード例 #10
0
ファイル: Butterfly.cs プロジェクト: stewmc/vixen
		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);
					}
				}
			}
		}
コード例 #11
0
ファイル: Spiral.cs プロジェクト: stewmc/vixen
		protected override void RenderEffect(int frame, ref PixelFrameBuffer frameBuffer)
		{
			int colorcnt = Colors.Count();
			int spiralCount = colorcnt * Repeat;
			int deltaStrands = BufferWi / spiralCount;
			int spiralThickness = (deltaStrands * Thickness / 100)+1;
			int spiralGap = deltaStrands - spiralThickness;
			int thicknessState = 0;
			int spiralState = 0;
			double position = (GetEffectTimeIntervalPosition(frame) * 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(GetEffectTimeIntervalPosition(frame) * 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 * Rotation / 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 (Rotation < 0)
							{
								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);
						}
					}
				}
			}
		}