I Imagine it instead of having a line by default start with an array of 2 points then avrage the 2 and add a random value to it, random multiplied by the roughness constant
{0,0}
Becomes:
{0,3,0}
Becomes:
{0,2,3,1,0}
{0,1,2,3,1,1,0}
{0,2,1,2,2,3,3,2,1,0,1,0}
Using
http://www.gameprogrammer.com/fractal.html I get somthing like this:
public float[] createHeightMap(int finalArrayLegnth, float startingRand, float roughConstant, float minHeight){
float[] finalHeightMap = new int[arrayLegnth];
float[] startingArray = {minHeight, minHeight};
boolean isAddZero = false;
int currentIndex = 0;
float[] tempAarray;
int randAmount = startingRand;
//some kind of legnth checking would have to go here because the array ends up having to be an odd number unless you clip the last number or something
int currentLegnth = 2;
while(tempArray.legnth()<= finalArrayLegnth){
//expand the array first
for(int i=0; i<=currentLegnth+(currentlegnth-1); i++){
tempAarray = new int[currentLegnth+(currentlegnth-1)];
//this alternates adding a number from currentArray and a 0
if(isAddZero){
tempArray[i]=0;
isAddZero = false;
}else{
tempArray[i]=startingArray[currentIndex];
currentIndex++;
isAddZero = true;
}
}
//then you have to actually displace the "empty" points
for(int i=0; i<=tempArray.legnth();i++){
if(tempArray[i]==0){
tempArray[i] = ((tempArray[i-1]/tempArray[i+1])+Math.Random(randAmount));
}
}
//lastly you have to Decrease the random amount by the constant
randAmount = randAmount*randConstant;
}
//then return the Finished height map
return tempArray;
}
note the only problem to my method is that it will never have points that are 0 since the method replaces anything that is 0 with an average of the 2 numbers next to it.
the only other critizizm is that the array WILL be a odd number since after the first pass it goes 2,3,5,9,17,33 and so on, if you need it to be even clip the end until its the right legnth Ex, if you need 20 exactaly make 33 and cut the last 13 off the end.
Also, I wrote this on the fly, and I don't guarantee it will work copy and paste. but Try and understand what I did.
1)Expand the array inserting 0 in between every number in the array.
2)average the Numbers around the 0's in the Array and add a random number
3)decrease the random amount by the roughness constant.
4)repeat 1-3 until the array is the desired length(or bigger and clip it)