Mountain Range¶
By the end of this lab you'll be able to:
- Write a
mountain(x, peak_y, width, color)function usinggoto()waypoints - Layer function calls from back to front to create a sense of depth
- Use color value (dark vs light) to signal distance — a key technique in art
Three layered mountain ranges recede into a sky gradient — the far peaks are pale and cool, the near peaks are deep blue, creating depth with nothing but color.
Welcome to the Mountain Range!
Artists have known for centuries that distant objects look lighter and cooler.
In this lab you'll use the same trick in code to create a landscape with depth!
Let's code it together!
How the Depth Works¶
We draw three mountain layers in order: background first, foreground last. Each layer uses a progressively darker, more saturated blue. Since fills are opaque, each front layer partially covers the layers behind it, naturally creating the illusion of distance.
Sample Code¶
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 | |
What Do You Think Will Happen?
The mountains are drawn back-to-front. Which color will appear in the very foreground?
Scan the function calls and make your guess — then click Run to find out!
Try It Now¶
The navy foreground mountain is drawn last and appears closest. Were you right?
How It Works¶
mountain() draws a filled triangle using three goto() calls: left base → peak → right base.
The base y-coordinate is always -190 (bottom of canvas) so all mountains share a common ground line.
The sky rectangle is drawn before the mountains so it serves as the background layer — any later fill will appear on top of it.
Explanation Table¶
| Line | What it does |
|---|---|
monty.goto(x - width//2, -190) |
Left base of the mountain triangle |
monty.goto(x, peak_y) |
The peak — highest point of the triangle |
monty.goto(x + width//2, -190) |
Right base — closes the triangle |
| Draw order: back → front | Later draws appear on top (closer to viewer) |
| Lighter color = more distant | Atmospheric perspective trick |
Learning Check¶
Your Turn — Add a Snow Cap
Add a small white triangle on top of the navy foreground mountain to simulate snow.
Call mountain() one more time with a smaller width, higher peak_y, and 'white' color.
Add mountain(-30, 70, 80, 'white') — a narrow white triangle overlapping the top of the navy peak.
Experiments¶
-
Add a sunset sky. Change the sky color from
'lightsteelblue'to'darkorange'. You'll know it worked when the scene looks like dusk. -
Add a tree line. Before the foreground mountain, add a row of small dark-green triangles across the base. You'll know it worked when a forest silhouette appears at the mountain's foot.
-
Make taller mountains. Change
peak_y = 170for the background range to220. You'll know it worked when the back mountains tower above the canvas top. -
Add a lake. Draw a filled blue ellipse at the bottom center after all mountains. You'll know it worked when a body of water appears in the foreground.
Beautiful Work!
You used layered drawing, color value, and function calls to create a landscape
with real visual depth — an artist's technique implemented in pure Python!
Up next: Archimedean Spiral — how a growing step length creates a perfect spiral.