0
所以我正在編寫一個處理草圖來測試我正在處理的焦土克隆的隨機地形生成器。它似乎按預期工作,但有一個小問題。在代碼中,我生成800 1像素寬的矩形,並預先將填充設置爲棕色。矩形的組合應該是具有褐色污垢狀顏色的固體塊(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;
}
對於一個像素,你也可以使用點(X,Y),這些用筆畫來設置顏色。 –