因此,我正在写一份处理草图,为我正在研究的焦土克隆人测试随机地形生成器。它看起来像预期的那样工作,但有一个小问题。在代码中,我生成了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;
}发布于 2013-06-06 06:26:30
我想这可能和每个矩形的边框都是黑色有关吧?
我相信是这样的。在绘制矩形之前,我在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]);
}
}https://stackoverflow.com/questions/16948420
复制相似问题