Skip to content

Instantly share code, notes, and snippets.

@JonRurka
Last active January 23, 2016 07:12
Show Gist options
  • Save JonRurka/8531bc088b37512b2f32 to your computer and use it in GitHub Desktop.
Save JonRurka/8531bc088b37512b2f32 to your computer and use it in GitHub Desktop.
/* Procedural Terrain Generation
* Peter Taylor (EmersonT1)
* Created: 29th November 2015
* A C# implementation of http://www.stuffwithstuff.com/robot-frog/3d/hills/index.html
*/
using System;
namespace Test1
{
class TerrainGen
{
ushort[,] Points;
Random R;
ushort MaxRadius;
public TerrainGen()
{
Points = new ushort[1024,1024];
R = new Random();
MaxRadius = 50;//Can gu up to
//Initialise Array; all at 0 height
for(ushort i = 0; i < 1024; i++)
for (ushort j = 0; j < 1024; j++)
Points[i, j] = 0;
//Generate the Terrain
for(ushort iterations = 0; iterations < 200; iterations++)
{
Tuple<ushort, ushort> Centre = new Tuple<ushort, ushort>((ushort)R.Next(0, 1024), (ushort)R.Next(0, 1024));
ushort Radius = (ushort)R.Next(0, MaxRadius);
for (ushort x = 0; x < 1024; x++)
for (ushort y = 0; y < 1024; y++)//TODO: Condense Loop
{
int H = (int)(Math.Pow((double)Radius, 2) - (Math.Pow(x - Centre.Item1, 2)+ Math.Pow(y - Centre.Item2, 2)));
if (H <= 0)
Points[x, y] =(ushort)(H + Points[x,y]);
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment