A bouncing ball
Make a ball fall, bounce, squash and cast a shadow with SVG animation. Learn how easing makes motion feel real, using only markup you can edit.
Ages 9 to 12, about 35 minutes. You will practice: How to animate a shape with animate and values, How easing makes falling and rising look natural, How squash and stretch adds weight, How to move several animated parts together.
Goal: animate a ball that falls, squashes on the floor and bounces back up, with a shadow that grows and shrinks.
A real ball speeds up as it falls and slows down as it rises. If you animate it at a steady speed, it looks like a machine. In this project you will fix that, step by step. If animation is new, try Animate a fish first. Every animation here is slow and smooth, with no flashing.
Step 1: A ball and a floor
Start with a still picture. The floor is a rectangle whose top edge is at y="176". The ball has a radius of 20 and its center is at cy="156", so the bottom of the ball, at 156 plus 20, touches the floor exactly.
Try this: change the ball’s cx to 80, then change its color. Keep cy at 156 so it still rests on the floor.
Step 2: Make it fall
<animate> changes one number over time. This one changes cy, the ball’s height, from 30 near the top to 156 on the floor. It takes 2 seconds, then starts over. The fall is a steady speed, so it looks stiff.
Try this: change dur from 2s to 4s. A slow fall feels like a heavy ball on the Moon. Then put it back.
Step 3: Easing, so it speeds up and slows down
Now the ball goes down and up. values="30;156;30" lists the heights it should pass through. keyTimes="0;0.5;1" says when. The ball reaches the floor halfway through the time, then goes back up.
calcMode="spline" and keySplines set the easing. Each of the two parts has four numbers that describe a curve. 0.5 0 1 1 starts slowly and ends fast, which is how a falling ball moves. 0 0 0.5 1 starts fast and ends slowly, which is how a rising ball moves.
Try this: swap the two keySplines so they read 0 0 0.5 1;0.5 0 1 1. The ball now seems to float down and slam up. Why does that look wrong?
Step 4: Squash on landing
Cartoon animators squash a ball when it hits the floor, because that makes it feel soft and heavy. To squash, we need an ellipse, not a circle. At the moment of impact, ry shrinks from 20 to 14, rx grows from 20 to 27 and the center sinks to 162, so the bottom stays on the floor at 176. Most of the time the ellipse is a perfect circle, because both radii are 20.
The extra keyTimes give the squash a short, quick moment at half time.
Try this: make the squash bigger by changing 14 to 10, 27 to 32 and 162 to 166. The last change keeps the bottom of the ball on the floor. Then try a hard ball with almost no squash.
Step 5: A shadow on the floor
A shadow tells us how high the ball is. When the ball is high, the shadow is small and faint. When the ball is low, the shadow is wide and dark. The shadow uses the same keyTimes and dur as the ball, so they stay in step.
Try this: change the shadow’s fill-opacity values to make it darker. What happens to the picture if the shadow stays the same size the whole time?
Step 6: Bounce across the floor
Now put the ball and the shadow in one group, <g>. An animateTransform slides the whole group left and then right. The whole trip, there and back, takes 9.6 seconds. That is exactly four bounces of 2.4 seconds each.
Try this: change the group’s values to -60 0;60 0;-60 0 to make a smaller trip. What dur on the group would give you two bounces for the whole trip? Hint: each bounce takes 2.4 seconds.
For teachers and families
Ask: “What makes a bounce look heavy or light? Which numbers did you change to find out?” As a classroom extension, link this to science. A ball speeds up as it falls because of gravity, and it slows as it rises. Children can compare a basketball, a tennis ball and a balloon, then change the numbers to match each one. A balloon would use a longer dur, a smaller squash and a gentler keySplines curve. Next, try Draw a water cycle diagram.
Next project: Draw a water cycle diagram