LoginSignup
1
2

More than 5 years have passed since last update.

[processing] noise()とrandom()の毎フレーム値

Last updated at Posted at 2016-08-23

スクリーンショット 2016-08-23 23.10.12.png
Coding Challenge #11: 3D Terrain Generation with Perlin Noise in Processing

こちらを写経していたのですが21分あたりからの

main.pde
void draw(){
  flying -= 0.1;

  float yoff = flying;
  for(int y = 0; y < rows; y++){
    float xoff = 0;
    for(int x = 0; x < cols; x++){
      terrain[x][y] = map(noise(xoff, yoff), 0, 1, -100, 100);
      xoff += 0.2;
    }
    yoff += 0.2;
  }
...

で毎フレームnoise動かしているのにy軸にズレていく理由がわからず。チェックしてみました。

dev.gif

結論としてはnoise()はアプリ実行時に対応する固定値が決定。

random()は毎フレーム変更。みたいです。

main.pde
void draw(){
...
  fill(255, 255);
  textSize(25);
  textAlign(CENTER);
  text("noise(10, 100) => " + noise(10, 100), 300, 60);
  text("random(10, 100) => ", 230, 90);
  text(random(10, 100), 420, 90);
...

ならば先ほどの

main.pde
      terrain[x][y] = map(noise(xoff, yoff), 0, 1, -100, 100);

でもnoiseは固定値吐き出すので問題無いですね。

コードのスナップはこちら

1
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
2