11 minutes
Roadside Trees
The highway runs through bare grass. Scattering trees is easy. Getting the same trees back every time is the hard part. Next lesson your car crashes into them, and the tree it hits had better be the tree you saw.
Random you can repeat
Lesson 1.1 built the road from hash3: three whole numbers in, one number out that looks random but never changes. Give it the chunk number, and each 30 m chunk of roadside gets its own makeRng stream, the River Raid kind:
XOR mixes two whole numbers bit by bit. The code writes it ^, which here has nothing to do with powers. Our scenery seed is 7 and the road's is 1983. They mix to 1976. So chunk 4012 grows the same 72 things on every drive, and a new road seed grows a new forest as well as a new road.
Real woods come in clumps, with fields between. So each 5.2 m square of ground beside the road, a cell, gets a chance of a tree:
Continue reading
Unlock the Full Course
Every lesson, the runnable examples, and the finished build — yours to keep.