Lakes
Overview
A sea covers everything below one height, but lakes, ponds and puddles sit at their own heights, in the hollows of the land. Quorum Studio has two tools for them. Fill water pours water into a hollow and lets it rise the way real water does, until it would spill over the edge. Paint water lays a thin layer of water exactly where you brush it, for puddles, marshes and shallow streams. In this tutorial, you will make lakes with both tools, change a lake's level, and learn the step-by-step rule, an algorithm, that Quorum Studio follows to fill a hollow. At the end, a short program checks whether a player is standing in the water.
Goals
By the end of this lesson, you can
- Fill a hollow with the Fill water tool, and change the lake's level
- Paint and erase shallow water with the Paint water tool
- Describe the algorithm that fills a hollow, and test it with cases where it should and shouldn't make a lake
- Write a program that asks a terrain whether a point is under water, and how deep the water is there
Warm up
Pour a glass of water onto a bumpy table in your mind. Where does it go first? When does it stop spreading? What happens if one side of a dip is lower than the others? Try to write the rules down in three or four short steps that anyone could follow.
Vocabulary
You will be learning about the following vocabulary words:
| Term | Definition |
|---|---|
| Lake | Water standing at its own level in a hollow of the ground. A terrain can have many. |
| Hollow | A low place in the ground with higher ground all around it, which can hold water. |
| Rim | The lowest point on the edge of a hollow. Water rising above it spills over and runs away downhill. |
| Water level | The height of a lake's flat surface. |
| Water depth | How far above the ground under the brush the water tools put the water. It is set in the Brush section. |
| Cell | One small square of the ground, as wide as the space between the terrain's height samples. A filled lake is made of cells that hold water or not. |
| Algorithm | A set of steps, in order, that solves a problem, such as filling a hollow with water. |
| Priority queue | A waiting list where the most important item always comes out first, such as the lowest cell when filling a lake. |
| Test case | An input chosen to check a program, with the result you expect from it. |
New Code to Learn
You will be using the following new pieces of code:
| Quorum Code | Code Example | Explanation |
|---|---|---|
| TerrainItem:GetWater() | TerrainWater water = ground:GetWater() | Returns the terrain's water: its sea, its lakes and their look. |
| TerrainItem:IsUnderWater(number x, number y, number z) | ground:IsUnderWater(x, y, z) | Returns true if the point is below the water there, and above the ground. |
| TerrainWater:GetWaterDepthAt(number x, number z) | water:GetWaterDepthAt(x, z) | Returns how deep the water is over the ground at a place, or 0 where there is no water. |
| TerrainWater:GetWaterLevelAt(number x, number z) | water:GetWaterLevelAt(x, z) | Returns the height of the water's surface at a place: the highest of the sea and any lakes there. |
| TerrainData:GetSurfaceHeight(number x, number z) | data:GetSurfaceHeight(x, z) | Returns the height of the ground at a place, as it is drawn. |
| TerrainData:HasHeight(number x, number z) | data:HasHeight(x, z) | Returns true if there is ground at a place. |
CSTA Standards
For teachers · 2026 CSTA K–12 Computer Science Standards
High School · Algorithms & Design
Design an algorithm using appropriate data structures to solve a problem or express an idea.
Also in 2 other lessons
High School · Algorithms & Design
Evaluate algorithms for efficiency, correctness, and clarity, using metrics or test cases.
Also in 4 other lessons
Explore
This tutorial needs a terrain with hollows: a few dips made with the Lower tool in Shaping Terrain, or a generated landscape from Generating Terrain. It also helps to make one long slope with no dip in it, for testing. The water's colors and ripples are the same as the sea's, set in the Water section's Look part, as The Sea explains.
The water tools
| Action | Windows | Mac |
|---|---|---|
| Choose the Fill water tool | Shift+Alt+5 | Shift+Option+5 |
| Choose the Paint water tool | Shift+Alt+6 | Shift+Option+6 |
| Move the brush | Arrow keys | Arrow keys |
| Fill water: pour at the brush | Space | Space |
| Paint water: paint (hold) | Space | Space |
| Paint water: erase (hold) | Ctrl+Space | Control+Space |
| Larger or smaller brush (Paint water) | Alt+= or Alt+- | Option+= or Option+- |
| Cancel a Paint water stroke, then leave the tool | Escape | Escape |
Both tools are also in the Brush section's Tool group, and in the Scenes menu (Alt+C, or Option+C on Mac) under Terrain and then Tools. With either tool chosen, the Brush section shows a Water card with one field, Water depth:. It is how far above the ground under the brush the water's surface goes. It starts at 2.
With the mouse, a gray ring follows the pointer. A click outside the brush's ring moves the brush there, and a click inside it uses the tool. Holding the button down for a moment uses the tool wherever the pointer is.
Filling a hollow
- Choose Fill water: press Shift+Alt+5 (Shift+Option+5 on Mac).
- Set the Water depth: in the Brush section's Water card. A bigger number lets the water rise higher.
- Move the brush into a hollow, and press Space or click inside the ring.
The water's highest allowed level is the ground's height under the brush plus the water depth. Quorum Studio then fills the hollow and says what happened, such as "Filled the hollow: water at 4.3, 812 cells, about 30.0 by 24.0." The new lake is named "Lake 1", then "Lake 2", and so on. Each fill can be undone.
Fill water ignores the brush's size: the water goes wherever it would really flow, however big the brush is. Pouring again inside a lake that was filled before fills that lake again from the new spot, and the lake keeps its name.
How Fill water decides where water goes
Fill water follows an algorithm that copies what real water does. The ground is treated as a grid of small square cells, each as wide as the space between the terrain's height samples. Each cell has one height.
- Run downhill. Starting at the brush, the water looks at the four cells around it, and moves to the lowest one, if it is lower. It repeats this until no neighbor is lower. Now it is at the bottom of the hollow. It only runs so far (64 cells), so water poured on a long slope doesn't end up in a valley far away.
- Rise, lowest first. The water keeps a waiting list of the cells touching its edge, sorted so the lowest cell always comes out first. A list like this is called a priority queue. Each time, the water covers the lowest waiting cell, and adds that cell's dry neighbors to the list. Because it always takes the lowest one, it fills the bottom of the hollow first and spreads upward evenly, as real water does.
- Stop at the first of three limits:
- The level. The next lowest cell is at or above the highest level allowed (the ground under the brush plus the water depth).
- The rim. The next lowest cell is lower than ground the water has already covered. That means the water has gone over the edge of the hollow and would run away downhill. The water stops at the rim's height.
- The edge of the terrain. The water reached a cell with no ground, so it would run off the world. It stops there too.
- Wet the low cells. Every cell the water reached whose ground is below the final level gets water. The rest stay dry.
When the rim or the edge stopped the water, the report says so, such as "Filled the hollow: water at 3.1, the hollow's rim, 640 cells, about 26.0 by 20.0." On a slope with no hollow, the water runs down, then spills over right away, so no cell is low enough to hold it. Then nothing fills, and Quorum Studio says "There is no hollow here to hold water: the ground slopes away, so the water would run off." Past the edge of the ground, it says "There is no ground there to pour water on."
A lake can never float in the air or flood a valley by accident, because the water only ever stands where ground surrounds it.
Changing a lake in the Water section
The Water section's Lakes part lists each lake as a part of its own, which opens with its chevron. Its title says the lake's name, its water level and about how big it is, such as "Lake 1, level 4.3, about 30 by 24". Opened, it has two fields and a button:
- Name: gives the lake a better name, such as
Mill pond
. - Water level: changes the lake's height. A filled lake is filled again from its lowest point, so it grows or shrinks to fit the hollow, and it still stops at the rim. Quorum Studio says, for example, "Mill pond: water at height 4.8, filling its hollow, about 32.0 by 25.0." If the new level is higher than the rim, it says "Mill pond: the hollow spills over its rim at height 5.2, so the water stops there, about 34.0 by 27.0."
- Remove lake takes the lake away. Quorum Studio says "Removed Mill pond."
Each change can be undone, and saving the scene saves the lakes in the
terrain's water.json file.
Painting water
Sometimes you want water that isn't flat: a puddle on a path, a marsh, or a shallow stream running down a hill. Paint water puts water exactly where you brush it, standing the water depth above the ground, so it follows the ground up and down and thins out at its edges.
- Choose Paint water: press Shift+Alt+6 (Shift+Option+6 on Mac).
- Set the brush's Size with Alt+= and Alt+- (Option on Mac), and a small Water depth:, such as 0.3, for a puddle or a stream.
- Hold Space, or hold the mouse button, and move the brush. Let go to finish the stroke.
If the stroke starts in a lake, it adds water to that lake. Otherwise, it starts a new lake. When you let go, Quorum Studio says, for example, "Painted water into Lake 2: 120 cells, water at 6.2." Painting into a filled lake only adds water where the ground is below that lake's level, so the water never floats.
Erasing: hold Ctrl as the stroke starts (on a Mac, the Control key, then Space) to erase water from the lake under the brush. Quorum Studio says "Erased water from Lake 2: 40 cells left." A lake erased to nothing is removed: "Erased all of Lake 2, so it was removed." If there's no water under the brush, it says "There is no water under the brush to erase." Pressing Escape while still holding cancels the stroke and puts the water back, and Quorum Studio says "Stroke canceled".
Water in a game
A game that loads the scene gets its lakes and sea with no extra code. It
can also ask about the water. This program puts a red ball on the ground,
lets the arrow keys roll it around, and once a second writes to Quorum
Studio's output window whether the ball is on dry ground, wading or
swimming. Put it in your project's Main.quorum, and change the scene's
path and the terrain's name if yours are different.
use Libraries.Game.Game
use Libraries.Game.InputMonitor
use Libraries.Game.Graphics.Model
use Libraries.Game.Graphics.Color
use Libraries.Game.Graphics.Worlds.TerrainItem
use Libraries.Game.Graphics.Worlds.TerrainWater
use Libraries.Game.Graphics.Worlds.TerrainData
use Libraries.Interface.Item3D
use Libraries.Interface.Events.KeyboardEvent
use Libraries.Compute.Math
class Main is Game
TerrainItem ground = undefined
Model ball
InputMonitor monitor
KeyboardEvent keys
Math math
number speed = 5
number sinceReport = 0
action Main
UseVulkan(true)
StartGame()
end
action CreateGame
LoadScene("Scenes/Scene.qs")
Item3D found = FindItem3DByName("Terrain")
if found is TerrainItem
ground = cast(TerrainItem, found)
else
output "This scene has no terrain named Terrain."
end
Color colors
ball:LoadSphere(1, 1, 1, colors:Red())
ball:SetPosition(0, 0, 0)
Add(ball)
GetCamera3D():Follow(ball, 12, 5)
end
action Update(number seconds)
if ground = undefined
return now
end
number x = ball:GetX()
number z = ball:GetZ()
if monitor:IsKeyPressed(keys:UP)
z = z + speed * seconds
end
if monitor:IsKeyPressed(keys:DOWN)
z = z - speed * seconds
end
if monitor:IsKeyPressed(keys:LEFT)
x = x - speed * seconds
end
if monitor:IsKeyPressed(keys:RIGHT)
x = x + speed * seconds
end
// Keep the ball on the ground: its middle is half a unit above it.
TerrainData data = ground:GetWorldTerrain():GetData()
if data:HasHeight(x, z)
ball:SetPosition(x, data:GetSurfaceHeight(x, z) + 0.5, z)
end
sinceReport = sinceReport + seconds
if sinceReport >= 1
sinceReport = 0
Report()
end
end
action Report
TerrainWater water = ground:GetWater()
number depth = water:GetWaterDepthAt(ball:GetX(), ball:GetZ())
if ground:IsUnderWater(ball:GetX(), ball:GetY(), ball:GetZ())
output "Swimming: the water is " + math:Round(depth, 1) + " deep here."
elseif depth > 0
output "Wading: the water is " + math:Round(depth, 1) + " deep here."
else
output "On dry ground."
end
end
end
How it works:
FindItem3DByName("Terrain")finds the scene's terrain. It returns anItem3D, so the program checks that it really is aTerrainItembefore using it as one.- In
Update, the arrow keys change the ball's x and z, and the ball's height is set from the ground's height there, so it rolls over hills and down into the lakes. GetWaterDepthAtsays how deep the water is above the ground at the ball's place. It counts the sea and every lake, and is 0 on dry ground.IsUnderWaterchecks one point: here, the middle of the ball, half a unit above the ground. In water deeper than that, the middle is under the surface, so the ball is swimming. In shallower water, the ball is only wading.
Engage
The goal of this activity is to design a fill algorithm yourselves, and
then to test Quorum Studio's with cases where you know the right answer.
Work with a partner. First, unplugged: draw a grid of 6 by 6 squares on
paper, and write a height from 0 to 9 in each square, so that there is a
hollow in the middle with one low notch in its edge. Choose a square to
pour water on. Together, write the steps you would follow to decide which
squares get water, and at what level it stops. Decide how you will keep
track of the squares at the water's edge that are waiting to be covered,
and which one you take next. Then follow your steps by hand, shading the
wet squares. Compare your steps with the four steps in How Fill water
decides where water goes
. Did you use a list sorted lowest first? Did your
water stop at the notch?
Next, test the real tool. On a terrain, make four test cases, and before pouring, write down what you expect Quorum Studio to say for each:
- a round hollow, poured with a small water depth, so the level stops it;
- the same hollow with a large water depth, so the rim stops it;
- a long slope with no dip at all;
- a hollow that reaches the edge of the terrain.
Pour water in each, and record what Quorum Studio actually said or did and how the lake looks, either visually or using the math behind the lake. Mark each test as passed or failed, and for any that failed, write what you think went wrong. Finally, try the lake's Water level field: raise it past the rim and check the result against what you expected.
Wrap up
Fill water turns a simple idea, water runs downhill and fills the lowest
place first
, into steps a computer can follow, with a priority queue to
choose the next cell. Paint water trades that realism for control, for
small water the algorithm wouldn't make. Where else might always take the
lowest one next
be a useful rule? In the next tutorial, Rivers, you will draw water that
flows along a path from the hills down to a lake or the sea.