3D Terrain Generator

During a 2-week programming bootcamp at university, I developed a 3D terrain generator using Processing, a language similar to Java with out-of-the-box graphics support. This project served as an introduction to working with 3D graphics, classes, 2D arrays, and randomization.

The terrain generator constructs randomized landscapes by manipulating vertex coordinates to form 2D strips of triangles. These strips are combined to create a grid-like 3D surface. By adjusting the Z positions of the vertices, I simulated hilly and mountainous terrain. To ensure continuity between the strips, I used a 2D array to manage the vertex coordinates, facilitating the pairing of neighboring strips.

screenshot

To highlight the terrain's depth, I added a directional light to the scene which created shadows across the terrain. Using a sine wave calculation, the position of this new light source could be smoothly shifted up and down the y-axis. In this way, a day-night cycle was simulated.

screenshot

The program consists of two instances of the plane class: land and water. With land having noisier terrain and dynamic colour changes while the water instance is much flatter. This project marked my first experience creating and using class objects, which enhanced my understanding of object-oriented design.

My interest in terrain generation, which I had previously explored during my IB Maths internal assessment, provided a solid foundation for this work. The complete code for this project is available on GitHub.