[英]How to draw an N*N grid on the screen that completely fills the window by using “Processing”
How to draw an N*N grid on the screen that completely fills the window. 如何在完全填满窗口的屏幕上绘制N * N网格。 Suppose n=8.
假设n = 8。
My code is like that: 我的代码是这样的:
boolean[][] rects;
void setup ()
{
size(300,300);
rects = new boolean[100][100];
fill(0);
}
void draw (){
background(255);
for (int r=0; r<100; r++ ){
for ( int c = 0; c < 100; c++ ){
if ( rects[r][c] == true ){
rect( r*3, c*3, 3, 3 );
}
}
}
}
when I run this code I just get a blank white screen. 当我运行此代码时,我只得到一个空白的白色屏幕。 Am I missing something?
我错过了什么吗?
Check out this line: 看看这一行:
rects = new boolean[100][100];
This creates a 100x100 2d array of boolean
values, but they all have the default value of false
because you haven't set them to anything. 这会创建一个100x100的2d
boolean
值数组,但它们都具有默认值false
因为您没有将它们设置为任何值。
Then check out this line: 然后看看这一行:
if ( rects[r][c] == true ){
rect( r*3, c*3, 3, 3 );
}
Here you're checking whether a particular index is true
, but you haven't set them to anything other than the default of false
. 在这里,你正在检查一个特定的指数是否是
true
,但你有没有将它们设置为比默认以外的任何false
。 In other words, this if
statement never evaluates to true
, so your rect()
function is never called. 换句话说,这个
if
语句永远不会计算为true
,因此永远不会调用你的rect()
函数。
You need to set some of the boolean
values to true
for this code to do anything. 您需要将一些
boolean
值设置为true
,以使此代码执行任何操作。
rects = new boolean[100][100];
rects[50][50] = true;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.