Paint a vector landscape
Layer a sky, mountains, curved hills, trees and drifting clouds into a calm countryside scene. Learn paths, curves and reusing shapes with use.
Ages 9 to 12, about 35 minutes. You will practice: How to build a scene in layers, back to front, How to draw curved hills with a path and the Q command, How to define a shape once and reuse it with use, How to add a slow, gentle animation.
Goal: paint a countryside scene with mountains, hills, trees and slowly drifting clouds.
A landscape is a good way to practice layers. Things far away go in first. Things up close go in last. You should already know basic shapes and fills from Draw with shapes. Each example below is live, so edit the code freely.
Step 1: Sky and ground
Start with two big rectangles. The canvas here is 300 wide and 200 tall, so it is wider than it is tall, like a real view. The sky fills the whole canvas. The ground sits on top of the lower part.
Try this: make it a sunset by changing the sky to #ffd2a8. Then make the ground darker.
Step 2: Mountains and a sun
The sun is a circle, and the mountain is a triangle. Because the sun and mountain are far away, they come before the ground in the code. The snowy tip is a small extra polygon in white.
Try this: add a second, smaller mountain by copying the gray triangle. Try points="110,140 170,85 230,140" and a slightly different gray.
Step 3: Curved hills with a path
A <path> can draw curves. Its d is a list of drawing commands. M means move to a point. Q means draw a curve: it takes one pulling point and one end point. The curve bends toward the pulling point, like a string pulled by a finger. V200 draws down to the bottom edge, H0 goes along to the left edge, and Z closes the shape.
The paler hill is farther away, so it comes first.
Try this: change the first number after the first Q from 80 to 40. The pulling point moves and the hill changes shape. Then try changing 70 to 30.
Step 4: Reuse a tree
You can draw a tree once and place it many times. Put it inside a <g id="tree">, which is a group, and tuck the group inside <defs>. Things in <defs> are not drawn until you ask for them. Then <use href="#tree"> draws a copy. Use transform="translate(x y)" to move it, and scale(0.8) to shrink it.
The tree is drawn around its own origin, 0,0, which sits at the top of the trunk. That makes it easy to place.
Try this: plant a fourth tree with transform="translate(120 172) scale(1.2)". Trees that are lower and bigger look closer to you.
Step 5: Clouds
A cloud is a few overlapping circles in white. Define it once, then use it twice at different sizes. The clouds come right after the sky and sun, so they sit behind the mountain and hills.
Try this: add a third cloud near the right with translate(190 70) scale(0.6). Smaller clouds look farther away.
Step 6: Let the clouds drift
SMIL is the part of SVG that can animate things on its own, with no code to run. Here an animateTransform slides the second cloud 30 units to the right and back. It takes 30 seconds for the full trip, so the move is slow and calm.
Try this: make the drift even slower by changing 30s to 60s. Then wrap the first cloud in its own animated group, too. Slower is almost always better for scenery.
For teachers and families
Ask: “How did layering help you show what is near and what is far away?” As a classroom extension, ask children to sketch a scene on paper in three labeled layers (far, middle, near) before they code it. They can then compare the sketch to the finished SVG. A good side conversation is how artists use size, height on the page and paler colors to show distance. If a child finds movement distracting, they can remove the animation lines and keep the still picture.
Next project: Animate a fish