「毎日Unity」の技術ブログ

開発で役立つ情報を発信する

【Processing】PerlinNoiseを使ってみた

ProcessingでPerlinNoiseを扱ったのでその時のプログラムを残すことにしました。

[ プログラム ]

float v = 0.02;
int s = 12345;
int h;

void setup()
{
  size(500,500);
  
  noiseSeed(s);
  
  for(int x = 0; x <= width; x++)
  {
    for(int y = 0; y <= height; y++)
    {
      //0~100
      h = (int)(100 * noise(x * v, y * v));
      
      if(h >= 0)
      {
        //Water
        stroke(111, 141, 253);
      }
      if(h >= 30)
      {
        //Sand
        stroke(231, 224, 156);
      }
      if(h >= 40)
      {
        //Grass
        stroke(67, 100, 43);
      }
      
      point(x, y);
    }
  }
}

[ 実行結果 ]