From bf8fd174ce8c7c40bc0371626c614cbd86f8a48b Mon Sep 17 00:00:00 2001 From: RKrom Date: Sat, 8 Dec 2012 00:02:53 +0000 Subject: [PATCH] Finished color flow (shine), the animation might still need some changes... git-svn-id: http://svn.code.sf.net/p/greenshot/code/trunk@2369 7dccd23d-a4a3-4e1f-8c07-b4c1b4018ab4 --- Greenshot/Forms/AboutForm.cs | 139 ++++++++++++++++------- GreenshotPlugin/Core/AnimationHelpers.cs | 80 +++++++++++-- 2 files changed, 170 insertions(+), 49 deletions(-) diff --git a/Greenshot/Forms/AboutForm.cs b/Greenshot/Forms/AboutForm.cs index 0f16dabb6..3ca2303d8 100644 --- a/Greenshot/Forms/AboutForm.cs +++ b/Greenshot/Forms/AboutForm.cs @@ -42,7 +42,15 @@ namespace Greenshot { private Bitmap gBitmap = new Bitmap(90, 90, PixelFormat.Format32bppRgb); private ColorAnimator backgroundColor; private List pixels = new List(); + private List colorFlow = new List(); + private List pixelColors = new List(); private IntAnimator angleAnimator; + private Random rand = new Random(); + private Color backColor = Color.FromArgb(61, 61, 61); + private Color pixelColor = Color.FromArgb(138, 255, 0); + private int waitFrames = 0; + private int colorIndex = 0; + private int scrollCount = 0; private const int w = 13; private const int p1 = 7; @@ -55,40 +63,52 @@ namespace Greenshot { private List gSpots = new List() { // Top row - new Point(p2, p1), - new Point(p3, p1), - new Point(p4, p1), - new Point(p5, p1), - new Point(p6, p1), + new Point(p2, p1), // 0 + new Point(p3, p1), // 1 + new Point(p4, p1), // 2 + new Point(p5, p1), // 3 + new Point(p6, p1), // 4 // Second row - new Point(p1, p2), - new Point(p2, p2), + new Point(p1, p2), // 5 + new Point(p2, p2), // 6 // Third row - new Point(p1, p3), - new Point(p2, p3), + new Point(p1, p3), // 7 + new Point(p2, p3), // 8 // Fourth row - new Point(p1, p4), - new Point(p2, p4), - new Point(p5, p4), - new Point(p6, p4), - new Point(p7, p4), + new Point(p1, p4), // 9 + new Point(p2, p4), // 10 + new Point(p5, p4), // 11 + new Point(p6, p4), // 12 + new Point(p7, p4), // 13 // Fifth row - new Point(p1, p5), - new Point(p2, p5), - new Point(p6, p5), - new Point(p7, p5), + new Point(p1, p5), // 14 + new Point(p2, p5), // 15 + new Point(p6, p5), // 16 + new Point(p7, p5), // 17 // Sixth row - new Point(p1, p6), - new Point(p2, p6), - new Point(p3, p6), - new Point(p4, p6), - new Point(p5, p6), - new Point(p6, p6) + new Point(p1, p6), // 18 + new Point(p2, p6), // 19 + new Point(p3, p6), // 20 + new Point(p4, p6), // 21 + new Point(p5, p6), // 22 + new Point(p6, p6) // 23 + }; + + // 0 1 2 3 4 + // 5 6 + // 7 8 + // 9 10 11 12 13 + // 14 15 16 17 + // 18 19 20 21 22 23 + + + List flowOrder = new List() { + 4, 3, 2, 1, 0, 5, 6, 7, 8, 9, 10, 14, 15, 18, 19, 20, 21, 22, 23, 16, 17, 13, 12, 11 }; public AboutForm() { @@ -113,15 +133,25 @@ namespace Greenshot { // Number of frames the "fade-in" takes int frames = CalculateFrames(3000); + waitFrames = CalculateFrames(5000); // Create pixels foreach (Point gSpot in gSpots) { RectangleAnimator pixelAnimation = new RectangleAnimator(new Rectangle(p4, p3, 0, 0), new Rectangle(gSpot.X, gSpot.Y, w-2, w-2), frames, EasingType.Sine, EasingMode.EaseIn); pixels.Add(pixelAnimation); + pixelColors.Add(pixelColor); } + // Pixel Color animation + ColorAnimator pixelColorAnimator = new ColorAnimator(pixelColor, Color.FromArgb(255, 255, 255), 6, EasingType.Quadratic, EasingMode.EaseIn); + pixelColorAnimator.QueueDestinationLeg(pixelColor, 6, EasingType.Quadratic, EasingMode.EaseOut); + do { + colorFlow.Add(pixelColorAnimator.Current); + pixelColorAnimator.Next(); + } while (pixelColorAnimator.hasNext); + // color animation - backgroundColor = new ColorAnimator(this.BackColor, Color.FromArgb(61, 61, 61), frames, EasingType.Linear, EasingMode.EaseIn); + backgroundColor = new ColorAnimator(this.BackColor, backColor, frames, EasingType.Linear, EasingMode.EaseIn); // Angle animation angleAnimator = new IntAnimator(-30, 20, frames, EasingType.Sine, EasingMode.EaseIn); } @@ -144,25 +174,50 @@ namespace Greenshot { } protected override void Animate() { - using (Graphics graphics = Graphics.FromImage(gBitmap)) { - graphics.SmoothingMode = SmoothingMode.HighQuality; - graphics.InterpolationMode = InterpolationMode.HighQualityBilinear; - graphics.CompositingQuality = CompositingQuality.HighQuality; - graphics.PixelOffsetMode = PixelOffsetMode.HighQuality; + + // Color cycle + if (waitFrames != 0) { + waitFrames--; + } else if (scrollCount < (pixelColors.Count + colorFlow.Count)) { + // Scroll colors, the scrollCount is the amount of pixels + the amount of colors to cycle. + for (int index = pixelColors.Count - 1; index > 0; index--) { + pixelColors[flowOrder[index]] = pixelColors[flowOrder[index-1]]; + } + // Keep adding from the colors to cycle until there is nothing left + if (colorIndex < colorFlow.Count) { + pixelColors[flowOrder[0]] = colorFlow[colorIndex++]; + } + scrollCount++; + } else { + // Reset values, wait X time for the next one + waitFrames = CalculateFrames(rand.Next(40000)); + colorIndex = 0; + scrollCount = 0; + } - graphics.Clear(backgroundColor.Next()); - - graphics.TranslateTransform(2, -2); - graphics.RotateTransform(angleAnimator.Next()); + // Draw the "G" + using (Graphics graphics = Graphics.FromImage(gBitmap)) { + graphics.SmoothingMode = SmoothingMode.HighQuality; + graphics.InterpolationMode = InterpolationMode.HighQualityBilinear; + graphics.CompositingQuality = CompositingQuality.HighQuality; + graphics.PixelOffsetMode = PixelOffsetMode.HighQuality; - using (SolidBrush brush = new SolidBrush(Color.FromArgb(138, 255, 0))) { - foreach (RectangleAnimator pixel in pixels) { - graphics.FillEllipse(brush, pixel.Current); - pixel.Next(); - } - } - } - pictureBox1.Invalidate(); + graphics.Clear(backgroundColor.Next()); + + graphics.TranslateTransform(2, -2); + graphics.RotateTransform(angleAnimator.Next()); + + using (SolidBrush brush = new SolidBrush(pixelColor)) { + int index = 0; + // Pixels of the G + foreach (RectangleAnimator pixel in pixels) { + brush.Color = pixelColors[index++]; + graphics.FillEllipse(brush, pixel.Current); + pixel.Next(); + } + } + } + pictureBox1.Invalidate(); } /// diff --git a/GreenshotPlugin/Core/AnimationHelpers.cs b/GreenshotPlugin/Core/AnimationHelpers.cs index 4f49efa6c..96c0b144d 100644 --- a/GreenshotPlugin/Core/AnimationHelpers.cs +++ b/GreenshotPlugin/Core/AnimationHelpers.cs @@ -49,6 +49,31 @@ namespace GreenshotPlugin.Core { get; } } + + /// + /// This class is used to store a animation leg + /// + internal class AnimationLeg { + public T Destination { + get; + set; + } + + public int Frames { + get; + set; + } + + public EasingType EasingType { + get; + set; + } + + public EasingMode EasingMode { + get; + set; + } + } /// /// Base class for the animation logic, this only implements Properties and a constructor @@ -58,7 +83,7 @@ namespace GreenshotPlugin.Core { protected T first; protected T last; protected T current; - protected Queue queue = new Queue(); + private Queue> queue = new Queue>(); protected int frames; protected int currentFrameNr = 0; @@ -115,7 +140,7 @@ namespace GreenshotPlugin.Core { if (queue.Count == 0) { return last; } - return queue.ToArray()[queue.Count - 1]; + return queue.ToArray()[queue.Count - 1].Destination; } } @@ -141,11 +166,47 @@ namespace GreenshotPlugin.Core { } /// - /// Queue the destination, it will be used after the current animation is finished + /// Queue the destination, it will be used to continue at the last frame + /// All values will stay the same /// /// public void QueueDestinationLeg(T queuedDestination) { - queue.Enqueue(queuedDestination); + QueueDestinationLeg(queuedDestination, Frames, EasingType, EasingMode); + } + + /// + /// Queue the destination, it will be used to continue at the last frame + /// + /// + /// + public void QueueDestinationLeg(T queuedDestination, int frames) { + QueueDestinationLeg(queuedDestination, frames, EasingType, EasingMode); + } + + /// + /// Queue the destination, it will be used to continue at the last frame + /// + /// + /// + /// EasingType + public void QueueDestinationLeg(T queuedDestination, int frames, EasingType easingType) { + QueueDestinationLeg(queuedDestination, frames, easingType, EasingMode); + } + + /// + /// Queue the destination, it will be used to continue at the last frame + /// + /// + /// + /// + /// + public void QueueDestinationLeg(T queuedDestination, int frames, EasingType easingType, EasingMode easingMode) { + AnimationLeg leg = new AnimationLeg(); + leg.Destination = queuedDestination; + leg.Frames = frames; + leg.EasingType = easingType; + leg.EasingMode = easingMode; + queue.Enqueue(leg); } /// @@ -191,7 +252,7 @@ namespace GreenshotPlugin.Core { } /// - /// Returns if there are any frame left, and if this is the case than the frame is increaded. + /// Returns if there are any frame left, and if this is the case than the frame is increased. /// public virtual bool NextFrame { get { @@ -201,8 +262,12 @@ namespace GreenshotPlugin.Core { } if (queue.Count > 0) { this.first = current; - this.last = queue.Dequeue(); this.currentFrameNr = 0; + AnimationLeg nextLeg = queue.Dequeue(); + this.last = nextLeg.Destination; + this.frames = nextLeg.Frames; + this.EasingType = nextLeg.EasingType; + this.EasingMode = nextLeg.EasingMode; return true; } return false; @@ -495,8 +560,9 @@ namespace GreenshotPlugin.Core { } public static double EaseInOut(double s, int power) { s *= 2; - if (s < 1) + if (s < 1) { return EaseIn(s, power) / 2; + } var sign = power % 2 == 0 ? -1 : 1; return (sign / 2.0 * (Math.Pow(s - 2, power) + sign * 2)); }