そこで、作業中の焦土クローンのランダム化された地形ジェネレーターをテストするための処理スケッチを作成しています。意図したとおりに動作しているように見えますが、小さな問題が 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;
}