2016-08-24 93 views
0

我想用OpenSimplexNoise生成隨機地形。開始我只想得到一個結果並將其繪製到窗口中。繪製並獲取OpenSimplexNoise結果

我現在的問題是:如何獲得OpenSimplexNoise的正確輸出(因爲有很多方法,我只是不知道哪個是正確的)以及如何繪製這個結果。

它應該是這樣的: enter image description here

public double[][] generateMap(long seed, int width, int height) { 
     double[][] map = new double[width][height]; 

     // start generating things here, just how? 
     OpenSimplexNoise simplex = new OpenSimplexNoise(seed); 

     return map; 
    } 

    public void drawMap(double[][] map, Graphics g) { 
     for(int x = 0; x < map.length; x++) { 
      for(int y = 0; y < map[0].length; y++) { 
       Color color = new Color(); // how to get the color here? 
      } 
     } 
    } 

這是當前的代碼,我已經得到了。

這裏是OpenSimplexNoise的人誰需要它的鏈接: https://gist.github.com/KdotJPG/b1270127455a94ac5d19

回答

1

其實這裏只有3公有方法 - 每個爲2D,3D & 4D噪音。 既然你填寫你的地圖的二維數組,使用二維噪聲eval方法, 是這樣的:

for(int x=0; x<width; x++){ 
    for(int y=0<y<height; y++){ 
     map[x][y] = simplex.eval(x, y); 
    } 
} 

之後,你可以生成從地圖值的顏色如下:

Color color = new Color(map[x][y], ma[x][y], map[x][y]); 

作者還提供了示例使用代碼OpenSimplexNoiseTest;他正在使用3D eval方法,但始終將z座標保持爲零。我的猜測是示例代碼是在他添加2D 4D實現之前編寫的。無論如何,它仍然有效,但它可能比直接使用2D稍慢。