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
This commit is contained in:
RKrom 2012-12-08 00:02:53 +00:00
commit bf8fd174ce
2 changed files with 170 additions and 49 deletions

View file

@ -42,7 +42,15 @@ namespace Greenshot {
private Bitmap gBitmap = new Bitmap(90, 90, PixelFormat.Format32bppRgb); private Bitmap gBitmap = new Bitmap(90, 90, PixelFormat.Format32bppRgb);
private ColorAnimator backgroundColor; private ColorAnimator backgroundColor;
private List<RectangleAnimator> pixels = new List<RectangleAnimator>(); private List<RectangleAnimator> pixels = new List<RectangleAnimator>();
private List<Color> colorFlow = new List<Color>();
private List<Color> pixelColors = new List<Color>();
private IntAnimator angleAnimator; 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 w = 13;
private const int p1 = 7; private const int p1 = 7;
@ -55,40 +63,52 @@ namespace Greenshot {
private List<Point> gSpots = new List<Point>() { private List<Point> gSpots = new List<Point>() {
// Top row // Top row
new Point(p2, p1), new Point(p2, p1), // 0
new Point(p3, p1), new Point(p3, p1), // 1
new Point(p4, p1), new Point(p4, p1), // 2
new Point(p5, p1), new Point(p5, p1), // 3
new Point(p6, p1), new Point(p6, p1), // 4
// Second row // Second row
new Point(p1, p2), new Point(p1, p2), // 5
new Point(p2, p2), new Point(p2, p2), // 6
// Third row // Third row
new Point(p1, p3), new Point(p1, p3), // 7
new Point(p2, p3), new Point(p2, p3), // 8
// Fourth row // Fourth row
new Point(p1, p4), new Point(p1, p4), // 9
new Point(p2, p4), new Point(p2, p4), // 10
new Point(p5, p4), new Point(p5, p4), // 11
new Point(p6, p4), new Point(p6, p4), // 12
new Point(p7, p4), new Point(p7, p4), // 13
// Fifth row // Fifth row
new Point(p1, p5), new Point(p1, p5), // 14
new Point(p2, p5), new Point(p2, p5), // 15
new Point(p6, p5), new Point(p6, p5), // 16
new Point(p7, p5), new Point(p7, p5), // 17
// Sixth row // Sixth row
new Point(p1, p6), new Point(p1, p6), // 18
new Point(p2, p6), new Point(p2, p6), // 19
new Point(p3, p6), new Point(p3, p6), // 20
new Point(p4, p6), new Point(p4, p6), // 21
new Point(p5, p6), new Point(p5, p6), // 22
new Point(p6, p6) 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<int> flowOrder = new List<int>() {
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() { public AboutForm() {
@ -113,15 +133,25 @@ namespace Greenshot {
// Number of frames the "fade-in" takes // Number of frames the "fade-in" takes
int frames = CalculateFrames(3000); int frames = CalculateFrames(3000);
waitFrames = CalculateFrames(5000);
// Create pixels // Create pixels
foreach (Point gSpot in gSpots) { 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); 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); 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 // 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 // Angle animation
angleAnimator = new IntAnimator(-30, 20, frames, EasingType.Sine, EasingMode.EaseIn); angleAnimator = new IntAnimator(-30, 20, frames, EasingType.Sine, EasingMode.EaseIn);
} }
@ -144,6 +174,28 @@ namespace Greenshot {
} }
protected override void Animate() { protected override void Animate() {
// 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;
}
// Draw the "G"
using (Graphics graphics = Graphics.FromImage(gBitmap)) { using (Graphics graphics = Graphics.FromImage(gBitmap)) {
graphics.SmoothingMode = SmoothingMode.HighQuality; graphics.SmoothingMode = SmoothingMode.HighQuality;
graphics.InterpolationMode = InterpolationMode.HighQualityBilinear; graphics.InterpolationMode = InterpolationMode.HighQualityBilinear;
@ -155,8 +207,11 @@ namespace Greenshot {
graphics.TranslateTransform(2, -2); graphics.TranslateTransform(2, -2);
graphics.RotateTransform(angleAnimator.Next()); graphics.RotateTransform(angleAnimator.Next());
using (SolidBrush brush = new SolidBrush(Color.FromArgb(138, 255, 0))) { using (SolidBrush brush = new SolidBrush(pixelColor)) {
int index = 0;
// Pixels of the G
foreach (RectangleAnimator pixel in pixels) { foreach (RectangleAnimator pixel in pixels) {
brush.Color = pixelColors[index++];
graphics.FillEllipse(brush, pixel.Current); graphics.FillEllipse(brush, pixel.Current);
pixel.Next(); pixel.Next();
} }

View file

@ -50,6 +50,31 @@ namespace GreenshotPlugin.Core {
} }
} }
/// <summary>
/// This class is used to store a animation leg
/// </summary>
internal class AnimationLeg<T> {
public T Destination {
get;
set;
}
public int Frames {
get;
set;
}
public EasingType EasingType {
get;
set;
}
public EasingMode EasingMode {
get;
set;
}
}
/// <summary> /// <summary>
/// Base class for the animation logic, this only implements Properties and a constructor /// Base class for the animation logic, this only implements Properties and a constructor
/// </summary> /// </summary>
@ -58,7 +83,7 @@ namespace GreenshotPlugin.Core {
protected T first; protected T first;
protected T last; protected T last;
protected T current; protected T current;
protected Queue<T> queue = new Queue<T>(); private Queue<AnimationLeg<T>> queue = new Queue<AnimationLeg<T>>();
protected int frames; protected int frames;
protected int currentFrameNr = 0; protected int currentFrameNr = 0;
@ -115,7 +140,7 @@ namespace GreenshotPlugin.Core {
if (queue.Count == 0) { if (queue.Count == 0) {
return last; return last;
} }
return queue.ToArray()[queue.Count - 1]; return queue.ToArray()[queue.Count - 1].Destination;
} }
} }
@ -141,11 +166,47 @@ namespace GreenshotPlugin.Core {
} }
/// <summary> /// <summary>
/// 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
/// </summary> /// </summary>
/// <param name="queuedDestination"></param> /// <param name="queuedDestination"></param>
public void QueueDestinationLeg(T queuedDestination) { public void QueueDestinationLeg(T queuedDestination) {
queue.Enqueue(queuedDestination); QueueDestinationLeg(queuedDestination, Frames, EasingType, EasingMode);
}
/// <summary>
/// Queue the destination, it will be used to continue at the last frame
/// </summary>
/// <param name="queuedDestination"></param>
/// <param name="frames"></param>
public void QueueDestinationLeg(T queuedDestination, int frames) {
QueueDestinationLeg(queuedDestination, frames, EasingType, EasingMode);
}
/// <summary>
/// Queue the destination, it will be used to continue at the last frame
/// </summary>
/// <param name="queuedDestination"></param>
/// <param name="frames"></param>
/// <param name="easingType">EasingType</param>
public void QueueDestinationLeg(T queuedDestination, int frames, EasingType easingType) {
QueueDestinationLeg(queuedDestination, frames, easingType, EasingMode);
}
/// <summary>
/// Queue the destination, it will be used to continue at the last frame
/// </summary>
/// <param name="queuedDestination"></param>
/// <param name="frames"></param>
/// <param name="easingType"></param>
/// <param name="easingMode"></param>
public void QueueDestinationLeg(T queuedDestination, int frames, EasingType easingType, EasingMode easingMode) {
AnimationLeg<T> leg = new AnimationLeg<T>();
leg.Destination = queuedDestination;
leg.Frames = frames;
leg.EasingType = easingType;
leg.EasingMode = easingMode;
queue.Enqueue(leg);
} }
/// <summary> /// <summary>
@ -191,7 +252,7 @@ namespace GreenshotPlugin.Core {
} }
/// <summary> /// <summary>
/// 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.
/// </summary> /// </summary>
public virtual bool NextFrame { public virtual bool NextFrame {
get { get {
@ -201,8 +262,12 @@ namespace GreenshotPlugin.Core {
} }
if (queue.Count > 0) { if (queue.Count > 0) {
this.first = current; this.first = current;
this.last = queue.Dequeue();
this.currentFrameNr = 0; this.currentFrameNr = 0;
AnimationLeg<T> nextLeg = queue.Dequeue();
this.last = nextLeg.Destination;
this.frames = nextLeg.Frames;
this.EasingType = nextLeg.EasingType;
this.EasingMode = nextLeg.EasingMode;
return true; return true;
} }
return false; return false;
@ -495,8 +560,9 @@ namespace GreenshotPlugin.Core {
} }
public static double EaseInOut(double s, int power) { public static double EaseInOut(double s, int power) {
s *= 2; s *= 2;
if (s < 1) if (s < 1) {
return EaseIn(s, power) / 2; return EaseIn(s, power) / 2;
}
var sign = power % 2 == 0 ? -1 : 1; var sign = power % 2 == 0 ? -1 : 1;
return (sign / 2.0 * (Math.Pow(s - 2, power) + sign * 2)); return (sign / 2.0 * (Math.Pow(s - 2, power) + sign * 2));
} }