Login Register
Frontpage Code library Pastebin

DiamondSquare2D

Author: MetalRain
Added: 9.4.2011 23:36
Edited: 15.4.2011 22:19
Category: Algoritmi

Description

M1c:n toteuttama Diamond Square algoritmi esim. maastongenerointiin. Palauttaa muistipalan jossa korkeudet desimaalilukuna siten että siemenluvut ovat alku ja loppukorkeus. Multiplier kertoo kuinka paljon arvot voivat poiketa ja roughness käyrän tasaisuuden.

Code

Select all
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
Function DiamondSquare2D(seed1#, seed2#, _width, roughness#, multiplier#, unset# = -12345)
    width = _width
    result = MakeMEMBlock(width * 4 + 4)
    For i = 1 To width - 1
        PokeFloat result, i * 4, unset#
    Next i
    PokeFloat result, 0, seed1#
    PokeFloat result, width * 4, seed2#
    stp = width / 2
    While stp => 1
        b = stp
        While b < width
            If PeekFloat(result, b * 4) = unset# Then
                PokeFloat result, b * 4, (PeekFloat(result, (b - stp) * 4) + PeekFloat(result, (b + stp) * 4)) / 2 + Rnd(-roughness#, roughness#)
            EndIf
            b = b + stp
        Wend
        stp = stp / 2
        roughness# = roughness# * multiplier#
    Wend
    Return result
End Function

Comments

No comments. You can be first!

Leave a comment

You must be logged in to comment.