0

そこで、作業中の焦土クローンのランダム化された地形ジェネレーターをテストするための処理スケッチを作成しています。意図したとおりに動作しているように見えますが、小さな問題が 1 つあります。コードでは、1 ピクセル幅の長方形を 800 個生成し、事前に塗りつぶしを茶色に設定しています。長方形の組み合わせは、茶色の汚れのような色 (77,0,0) の固体の塊になるはずです。

ただし、RGB 塗りつぶし値の設定に関係なく、組み合わせは黒として表示されます。各長方形の境界線が黒くなっていることと関係があるのではないでしょうか? ここで何が起こっているのか知っている人はいますか?

final int w = 800;
final int h = 480;

void setup() {
  size(w, h);
  fill(0,128,255);
  rect(0,0,w,h);
  int t[] = terrain(w,h);
  fill(77,0,0);
  for(int i=0; i < w; i++){
    rect(i, h, 1, -1*t[i]);
  }
}

void draw() {

}

int[] terrain(int w, int h){

    width = w;
    height = h;

    //min and max bracket the freq's of the sin/cos series
    //The higher the max the hillier the environment
    int min = 1, max = 6;

    //allocating horizon for screen width
    int[] horizon = new int[width];
    double[] skyline =  new double[width];

    //ratio of amplitude of screen height to landscape variation
    double r = (int) 2.0/5.0;

    //number of terms to be used in sine/cosine series
    int n = 4;

    int[] f = new int[n*2];


    //calculating omegas for sine series
    for(int i = 0; i < n*2 ; i ++){
      f[i] = (int) random(max - min + 1) + min;
    }

    //amp is the amplitude of the series
    int amp =  (int) (r*height);

    for(int i = 0 ; i < width; i ++){
      skyline[i] = 0;

      for(int j = 0; j < n; j++){
        skyline[i] += ( sin( (f[j]*PI*i/height) ) +  cos(f[j+n]*PI*i/height) );
      }

      skyline[i] *= amp/(n*2);
      skyline[i] += (height/2);
      skyline[i] = (int)skyline[i];
      horizon[i] =  (int)skyline[i];
    }
    return horizon;
}
4

1 に答える 1

3

各長方形の境界線が黒くなっていることと関係があるのではないでしょうか?

私はこれが事実だと信じています。あなたの関数では、長方形を描く前に関数setup()を追加しました。noStroke()これにより、長方形の黒い輪郭が削除されます。各四角形は幅が 1 ピクセルしかないため、この黒のストローク (デフォルトでオン) を使用すると、前にどの色を選択しようとしても、各四角形の色が黒になります。

これが更新されたsetup()関数です。赤褐色の地形が表示されます。

void setup() {
  size(w, h);
  fill(0, 128, 255);
  rect(0, 0, w, h);
  int t[] = terrain(w, h);
  fill(77, 0, 0);
  noStroke(); // here
  for (int i=0; i < w; i++) {
    rect(i, h, 1, -1*t[i]);
  }
}
于 2013-06-05T22:26:29.720 に答える