3D数组使绘制函数起奇怪作用的问题

时间:2019-01-30 19:28:30

标签: java processing

我编写了这段代码来检查3D数组及其工作方式。我有一个简单的代码,应首先存储值,然后在绘图部分中调用它们。 与其绘制适当的点网格,不如在(110,5)处出现1个点

当我不使用数组访问颜色,而是“当场”创建它们时,我已经确保程序能够正常工作。它会按预期工作。

color [][][]array = new color[10][10][10];
int x = 0;
int y = 0;

void setup(){
  size(1100,1000);
  background(0);
  for(int i= 0; i < 10; i++){
    for(int j= 0; i < 10; i++){
      for(int k= 0; i < 10; i++){
        array[1][j][k] = color(i*25.5,j*25.5,k*25.5);
      }
    }
  }
}
void draw(){
  background(0);
  strokeWeight(0);
  stroke(0);
  for(int s= 0; s < 10; s++){
    x= 110*s;
    y= 110*s;
    for(int v= 0; v < 10; v++){
      for(int t= 0; t < 10; t++){
        fill(array[s][v][t]);
        ellipse(x+t*10+5,v*10+5,10,10);
      }
    }
  }

}

1 个答案:

答案 0 :(得分:0)

您似乎没有在设置中的三重循环中增加j / k,这是固定代码:

color [][][]array = new color[10][10][10];
int x = 0;
int y = 0;

void setup(){
  size(1100,1000);
  background(0);
  for(int i= 0; i < 10; i++){
    for(int j= 0; j < 10; j++){
      for(int k= 0; k < 10; k++){
        array[1][j][k] = color(i*25.5,j*25.5,k*25.5);
      }
    }
  }
}
void draw(){
  background(0);
  strokeWeight(0);
  stroke(0);
  for(int s= 0; s < 10; s++){
    x= 110*s;
    y= 110*s;
    for(int v= 0; v < 10; v++){
      for(int t= 0; t < 10; t++){
        fill(array[s][v][t]);
        ellipse(x+t*10+5,v*10+5,10,10);
      }
    }
  }

}