15th April 2024

Random Terrain Generator Solution Guide

Even though you can create a lot of fancy and complex models in Grasshopper using generative algorithms, there's a lot you can accomplish with the humble Random Numbers component. In this guide, I'll walk you through creating "terrains" randomly using on this component as the driving factor.

External Plugins

Before we start, this script uses several external plugins but it works without them. Throughout the guide, I'll note when to substitute the plugins for native components.

Here's a list of plugins that the script uses:

  • Heteroptera (for easy randomness)

Creating the surface

Let's start by creating the surface. I will use the rectangle component to create a square.

To generate the different heights for the terrain, we need more control points on the surface. To do that, I'll use the divide surface component

Using this grid of points, I will then set random elevations to create the "terrain".

Let's pause here and look at the first external plugin that I am using.

Using the Heteroptera plugin (Random Seed Component)

Grasshopper’s Random Number component isn’t truly random, it relies on a “seed” which is just a number telling Grasshopper how to create the "random" number. Changing the seed number will create a new set of numbers. This means to create “random” numbers, you need to keep changing the seed.

You can see this in action by plugging a slider into the random number component.

I find this annoying because I have to keep changing the number to get a new terrain. That's why I use Heteroptera's random seed component. It generates a new seed every time I re-solve the canvas. That means I don't need a slider, I just need to refresh the canvas when I want a new terrain.

Now that I can generate a set of points in random elevations, I will rebuild the surface to make the top of the terrain.

Just a note, I added a "+1" here to the U Count because the Surface Grid component wants the number of points, not the number of sections,

Creating the Topological Curves

With the surface created, I will work on creating topological curves on the surface. To do that, I will project some curves to the surface from before.

Firstly, I will put the entire surface in a bounding box and get the top and bottom edges.

Then, I create intermediate lines using the tween curve component.

These lines will control the density of the curves on the surface. Once I project them to the surface, I will have the curves.

Colouring the curves

To colour the curves based on their elevation, I will first need to split them because the each curve can span multiple elevations.

By using the midpoint of each curve segment, I will create a colour gradient using the colour gradient component. Once I do that, I will visualise the curves using the preview custom lineweight component. I using this component to add some thickness to the curves.

"Filling" in the rest of the model

If you are happy with the model now, you can stop here. But I wanted to add some depth to the surface.

To do that, I will extrude the surface downwards and cut it by a plane.

Once, I cut the Brep, I will select the top piece.

Final Thoughts

And with that, we have a script that randomly generates the terrain based on a random number.

I hope you have enjoyed making this model as I have. I think it's nice to play with some randomness in modelling and design. Even though this was a relatively simple script to make, I think it shows you how powerful Grasshopper can be if you make full use of its components.

Here is where you can find the script: Random Terrain Generator.gh