I'm trying to do a fairly crude (to start with) heightmap generator but unfortunately I'm not getting expected results
What I've tried to do is calculate a starting height for the first pixel and then the surrounding 8 pixels are set to a random height obtained by the average of the current pixel and the other pixel with a random number applied.
This way the heightmap blends together without too extreme differences. I'd have expected the final result to be a bit like the photoshop cloud effect.
But I've found that in the first few columns the value plotted onto a picture object can start at a height of 9000 and finish up around 2000.
Then from around the 10th column the rest of the map is just slight random variations of the start height.
Below is the code, can anyone see the problem, or suggest a better approach? I'm hoping to reach a fairly realistic final heightmap but it doesn't have to be too accurate.
Many thanks in advance.
Code:Dim MyNHeight As Long Dim MyHeight As Long, intCnt1 As Integer, intCnt2 As Integer, intCnt3 As Integer, intCnt4 As Integer Randomize Timer For intCnt1 = 1 To Picture1.Height - 1 For intCnt2 = 1 To Picture1.Width - 1 If intCnt1 = 1 And intCnt2 = 1 Then MyHeight = Int(Rnd() * 2000) + 9000 Picture1.BackColor = MyHeight Picture1.PSet (1, 1), MyHeight Else For intCnt3 = -1 To 1 For intCnt4 = -1 To 1 If intCnt3 <> 1 And intCnt4 <> 1 Then MyNHeight = Picture1.Point(intCnt2 + intCnt3, intCnt1 + intCnt4) MyNHeight = ((MyHeight + MyNHeight) / 2) + Int(Rnd() * 250 - 125) If MyNHeight < 0 Then MyNHeight = 0 If MyNHeight > 20000 Then MyNHeight = 20000 Picture1.PSet (intCnt2 + intCnt3, intCnt1 + intCnt4), MyNHeight End If Next Next MyHeight = Picture1.Point(intCnt2, intCnt1) End If Next intCnt2 Next intCnt1





Reply With Quote