Adding trees to random terrains in Enu 0.2
Read the first part →
In this tutorial, I’ll add some trees to the random terrain that we’ve created last time. For the impatient, here is the complete code: https://gist.github.com/moigagoo/d40a76beee5a62d2fec7679ebc033730
As before, let’s first write down the basic ideas:
- trees grow on hills
- a tree consists of a trunk and a crow
- to draw the crown, I’ll use layers from the previous part
Tree
Here’s the command that draws a tree:
- tree(height = 5, width = 3):
let
trees use their own colors so we need to preserve the original one
defaultColor = color
a tree is roughly half trunk and half crown
trunkHeight = height div 2
crownHeight = height - trunkHeight
we'll build from the top down, so first we got up
up height - 1
height.times(stepNum):
if we're still within the crown height, draw green layers
if stepNum < crownHeight:
color = green
...