Ty for the support, I managed to "kind of" fix it and it is indeed very satisfying. But I'm still having a problem... I'm not sure whether it's a side effect of the diamond square algorithm or a problem in my code, but I'm getting this artifacts, odd bumps appearing in a pattern across my map. It's using minecraft-style blocks, and while the general terrain shape is there, something is a bit off.
Are these just a result of going from doubles to integers? Or a natural side effect of the algorithm? Or is my code off
Rem Project: terraingen
Rem Created: Sunday, January 30, 2011
Rem ***** Main Source File *****
Rem ***** Included Source File *****
Rem initialize
randomize timer()
set display mode 1650,768,32
Rem some variables
`Arrays
dim land(17,17)
`Single
scounter=1 :`number of squares in the grid so far
lcounter = 1 :`square root of scounter
Roughness# = 0.20 :`How rough the terrain should be
rlimit = 30 :`The min/max height value(max/min would be rlimit/2)
slen = 16 :`How many "squares" in a grid, this is one less than the array values 33-32
`Genrate a seed vaulue in the middle
`land(9,9) = (rnd(rlimit)-(rlimit/2))
`rlimit = rlimit*Roughness
for n = 1 to 4
Rem -------do a diamond pass
for x = 1 to lcounter
for y = 1 to lcounter
` land(slen/lcounter*x-(slen/lcounter/2),slen/lcounter*y-(slen/lcounter/2)) = (land(slen/lcounter*x-(slen/lcounter),slen/lcounter*y-(slen/lcounter/2))+land(slen/lcounter*x-(slen/lcounter),slen/lcounter*y)+land(slen/scounter*x,slen/lcounter*y-(slen/scounter))+land(slen/lcounter*x,slen/lcounter*y))
land(((slen/lcounter)*x)-(slen/lcounter/2)+1,(slen/lcounter*y)-(slen/lcounter/2)+1) = (land(((slen/lcounter)*x)-(slen/lcounter)+1,(slen/lcounter*y)-(slen/lcounter)+1)+land(((slen/lcounter)*x)+1,(slen/lcounter*y)+1)+land(((slen/lcounter)*x)-(slen/lcounter)+1,(slen/lcounter*y)+1)+land(((slen/lcounter)*x)+1,(slen/lcounter*y)-(slen/lcounter)+1))/4 + (rnd(rlimit)-(rlimit/2))
next y
next x
Rem -------do a square pass
`Do the vertical squares first
for x = 1 to lcounter
for y = 1 to lcounter+1
if y = 1
` land(slen/lcounter*x-(slen/lcounter/2),slen/lcounter*y-(slen/lcounter)) = (land(slen/lcounter*x-(slen/lcounter/2),slen/lcounter*y-(slen/lcounter/2))+land(slen/lcounter*x-(slen/lcounter),slen/lcounter*y-(slen/lcounter))+land(slen/lcounter*x,slen/lcounter*y-(slen/lcounter))+land(slen/lcounter*x-(slen/lcounter/2),slen-(slen/lcounter/2)))/slen + (rnd(rlimit)-(rlimit/2))
land(((slen/lcounter)*x)-(slen/lcounter/2)+1,(slen/lcounter*y)-(slen/lcounter)+1) = (land(((slen/lcounter)*x)-(slen/lcounter/2)+1,slen-(slen/lcounter/2)+1)+land(((slen/lcounter)*x)-(slen/lcounter/2)+1,(slen/lcounter*y)-(slen/lcounter/2)+1)+land(((slen/lcounter)*x)-(slen/lcounter)+1,(slen/lcounter*y)-(slen/lcounter)+1)+land(((slen/lcounter)*x)+1,(slen/lcounter*y)-(slen/lcounter)+1))/4 + (rnd(rlimit)-(rlimit/2))
endif
if y = (lcounter+1) :`check if the point is on the far edge
` land(slen/lcounter*x-(slen/lcounter/2),slen/lcounter*y-(slen/lcounter)) = (land(slen/lcounter*x-(slen/lcounter/2),(slen/lcounter/2))+land(slen/lcounter*x-(slen/lcounter),slen/lcounter*y-(slen/lcounter))+land(slen/lcounter*x,slen/lcounter*y-(slen/lcounter))+land(slen/lcounter*x-(slen/lcounter/2),slen/lcounter*y-((slen/lcounter)+(slen/lcounter/2))))/slen + (rnd(rlimit)-(rlimit/2))
land(((slen/lcounter)*x)-(slen/lcounter/2)+1,(slen/lcounter*y)-(slen/lcounter)+1) = (land(((slen/lcounter)*x)-(slen/lcounter/2)+1,(slen/lcounter*y)-((slen/lcounter)+(slen/lcounter/2))+1)+land(((slen/lcounter)*x)-(slen/lcounter/2)+1,(slen/lcounter/2)+1)+land(((slen/lcounter)*x)-(slen/lcounter)+1,(slen/lcounter*y)-(slen/lcounter)+1)+land(((slen/lcounter)*x)+1,(slen/lcounter*y)-(slen/lcounter)+1))/4 + (rnd(rlimit)-(rlimit/2))
endif
if y>1 and y<lcounter+1 :`if point is on the close edge
` land(slen/lcounter*x-(slen/lcounter/2),slen/lcounter*y-(slen/lcounter)) = (land(slen/lcounter*x-(slen/lcounter/2),slen/lcounter*y-(slen/lcounter/2))+land(slen/lcounter*x-(slen/lcounter),slen/lcounter*y-(slen/lcounter))+land(slen/lcounter*x,slen/lcounter*y-(slen/lcounter))+land(slen/lcounter*x-(slen/lcounter/2),slen/lcounter*y-((slen/lcounter)+(slen/lcounter/2))))/slen + (rnd(rlimit)-(rlimit/2))
land(((slen/lcounter)*x)-(slen/lcounter/2)+1,(slen/lcounter*y)-(slen/lcounter)+1) = (land(((slen/lcounter)*x)-(slen/lcounter/2)+1,(slen/lcounter*y)-((slen/lcounter)+(slen/lcounter/2))+1)+land(((slen/lcounter)*x)-(slen/lcounter/2)+1,(slen/lcounter*y)-(slen/lcounter/2)+1)+land(((slen/lcounter)*x)-(slen/lcounter)+1,(slen/lcounter*y)-(slen/lcounter)+1)+land(((slen/lcounter)*x)+1,(slen/lcounter*y)-(slen/lcounter)+1))/4 + (rnd(rlimit)-(rlimit/2))
endif
next y
next x
`horizontal ones
for x = 1 to lcounter+1
for y = 1 to lcounter
if x=1
` land(slen/lcounter*x-(slen/lcounter),slen/lcounter*y-(slen/lcounter/2)) = (land(slen/lcounter*x-(slen/lcounter),slen/lcounter*y-(slen/lcounter))+land(slen/lcounter*x-(slen/lcounter),slen/lcounter*y)+land(slen/lcounter*x-(slen/lcounter/2),slen/lcounter*y-(slen/lcounter/2))+land(slen-(slen/lcounter/2) ,slen/lcounter*y-(slen/lcounter/2)))/slen + (rnd(rlimit)-(rlimit/2))
land(((slen/lcounter)*x)-(slen/lcounter)+1,(slen/lcounter*y)-(slen/lcounter/2)+1) = (land(((slen/lcounter)*x)-(slen/lcounter)+1,(slen/lcounter*y)-(slen/lcounter)+1)+land(((slen/lcounter)*x)-(slen/lcounter)+1,(slen/lcounter*y)+1)+land(((slen/lcounter)*x)-(slen/lcounter/2)+1,(slen/lcounter*y)-(slen/lcounter/2)+1)+land(lcounter-(slen/lcounter/2)+1,(slen/lcounter*y)-(slen/lcounter/2)+1))/4 + (rnd(rlimit)-(rlimit/2))
endif
if x = lcounter+1
` land(slen/lcounter*x-(slen/lcounter),slen/lcounter*y-(slen/lcounter/2)) = (land(slen/lcounter*x-(slen/lcounter),slen/lcounter*y-(slen/lcounter))+land(slen/lcounter*x-(slen/lcounter),slen/lcounter*y)+land((slen/lcounter/2),slen/lcounter*y-(slen/lcounter/2))+land(slen/lcounter*x-((slen/lcounter) + (slen/lcounter/2)) ,slen/lcounter*y-(slen/lcounter/2)))/slen + (rnd(rlimit)-(rlimit/2))
land(((slen/lcounter)*x)-(slen/lcounter)+1,(slen/lcounter*y)-(slen/lcounter/2)+1) = (land(((slen/lcounter)*x)-(slen/lcounter)+1,(slen/lcounter*y)-(slen/lcounter)+1)+land(((slen/lcounter)*x)-(slen/lcounter)+1,(slen/lcounter*y)+1)+land((slen/lcounter/2)+1,(slen/lcounter*y)-(slen/lcounter/2)+1)+land(((slen/lcounter)*x)-((slen/lcounter)+(slen/lcounter/2))+1,(slen/lcounter*y)-(slen/lcounter/2)+1))/4 + (rnd(rlimit)-(rlimit/2))
endif
if x>1 and x<lcounter+1
` land(slen/lcounter*x-(slen/lcounter),slen/lcounter*y-(slen/lcounter/2)) = (land(slen/lcounter*x-(slen/lcounter),slen/lcounter*y-(slen/lcounter))+land(slen/lcounter*x-(slen/lcounter),slen/lcounter*y)+land(slen/lcounter*x-(slen/lcounter/2),slen/lcounter*y-(slen/lcounter/2))+land(slen/lcounter*x-((slen/lcounter) + (slen/lcounter/2)) ,slen/lcounter*y-(slen/lcounter/2)))/slen + (rnd(rlimit)-(rlimit/2))
` land((slen/lcounter*x)-(slen/lcounter/2),(slen/lcounter*y)) = 2
land(((slen/lcounter)*x)-(slen/lcounter)+1,(slen/lcounter*y)-(slen/lcounter/2)+1) = (land(((slen/lcounter)*x)-(slen/lcounter)+1,(slen/lcounter*y)-(slen/lcounter)+1)+land(((slen/lcounter)*x)-(slen/lcounter)+1,(slen/lcounter*y)+1)+land(((slen/lcounter)*x)-(slen/lcounter/2)+1,(slen/lcounter*y)-(slen/lcounter/2)+1)+land(((slen/lcounter)*x)-((slen/lcounter)+(slen/lcounter/2))+1,(slen/lcounter*y)-(slen/lcounter/2)+1))/4 + (rnd(rlimit)-(rlimit/2))
endif
next y
next x
` land(((slen/lcounter)*x)-(slen/lcounter)+1,(slen/lcounter*y)-(slen/lcounter)+1) Above
` land(((slen/lcounter)*x)-(slen/lcounter)+1,(slen/lcounter*y)+1) Below
` land(((slen/lcounter)*x)-(slen/lcounter/2)+1,(slen/lcounter*y)-(slen/lcounter/2)+1) Right
` land(((slen/lcounter)*x)-((slen/lcounter)+(slen/lcounter/2))+1,(slen/lcounter*y)-(slen/lcounter/2)+1) Left
` land(((slen/lcounter)*x)-(slen/lcounter)+1,(slen/lcounter*y)-(slen/lcounter)+1) Above
` land(((slen/lcounter)*x)-(slen/lcounter)+1,(slen/lcounter*y)+1) Below
` land((slen/lcounter/2)+1,(slen/lcounter*y)-(slen/lcounter/2)+1) Right
` land(lcounter-(slen/lcounter/2)+1,(slen/lcounter*y)-(slen/lcounter/2)+1) Left
scounter = 2^(n*2) :`Number of squares can be derived from the number of passes
lcounter = sqrt(scounter) :`length of sides can be derived from the square root of the number of squares
rlimit = rlimit*Roughness# : `reduce the limit based on the roughness value
next n
Rem --------Print the results
cls
for y = 1 to 17
for x = 1 to 17
set cursor x*60,y*15
print left$(str$(land(x,y)),5)
next y
next x
`set cursor 0,500
`print scounter
sync
suspend for key
This is just the terrain gen code with print out. I'll post the visualizer code if it makes it easier.