By combining multiple key frames and easings, VectSharp makes it possible to create rather complex animations. For example, let us say we want to animate a “bouncing ball”. This is what the end result should look like:
Animating transforms
We can start by creating the start and end point of each “bounce”:
Expand source code
The ball is bouncing, but its movement does not look very natural. Recall from high-school physics, that when an object falls towards the ground and bounces (neglecting air friction), its trajectory looks like a parabola; instead, in our animation the ball moves in straight-line segments.
Using easings to approximate motion
To address this, we can use easings. We can decompose the motion of the bouncing bool in two motions: one along the X axis, which happens at a constant speed (linear easing), and one along the Y axis, which happens at a constant acceleration (which we can simulate using spline easings).
To do this in VectSharp, instead of drawing the ball at coordinates x and y, we can draw the ball at (0, 0), and apply two translation transforms to move it. Then, we do not apply any easing to the horizontal translation, and instead apply a spline easing to the vertical translation.
Unfortunately, to do this in an animated SVG, we need to save the animation using the SaveAsAnimatedSVGWithFrames method, as animated transforms are not properly supported in SVG files otherwise. This is shown in the following example:
Expand source code
Adding depth with a gradient
The bouncing of the ball looks much more natural now! We can also add “depth” to the ball and make it look more like a sphere, by adding a shading to it. This can be achieved by using a RadialGradientBrush:
Expand source code
Adding a shadow
We can further improve the impression of depth by adding a shadow to the ball. To make it look more natural, we can use a skew transform to warp the shape of the shadow:
Expand source code
Blurring the shadow
Finally, for the shadow to feel more natural, it should be crisper when it is closer to the object, and more blurred when it is further away. We can achieve this effect by using and animating a Gaussian blur filter: