We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpSyntax Questions › How to make a grid of squares(new to programming)
Page Index Toggle Pages: 1
How to make a grid of squares?(new to programming) (Read 1501 times)
How to make a grid of squares?(new to programming)
Nov 11th, 2007, 1:04am
 
Hi, Can someone lead me in the right direction here? All I want is to have a grid of say 100x100 black squares on a white background. I would also like to be able to control the order in which each one pops onscreen (could be random, filling in the grid eventually).

Thanks for any help!
Re: How to make a grid of squares?(new to programm
Reply #1 - Nov 11th, 2007, 9:13am
 
use arrays:

boolean[][] rects; // twodimensional array, think rows and columns

void setup ()
{
size(300,300);
rects = new boolean[100][100];
fill(0);
noStroke();
}

void draw ()
{
background(255); // clear background with white
for (int r=0; r<100; r++ ) // rows
{
for ( int c = 0; c < 100; c++ ) // columns per row
{
if ( rects[r][c] == true ) // is it on?
{
rect( r*3, c*3, 3, 3 ); // draw it!
}
}
}
}

F
Re: How to make a grid of squares?(new to programm
Reply #2 - Nov 11th, 2007, 2:31pm
 
Hey thanks for replying!

Hmm, when I run this code I just get a blank white screen. Am I missing something?
Re: How to make a grid of squares?(new to programm
Reply #3 - Nov 12th, 2007, 10:12pm
 
for(int i=0; i<width; i+=widthSpace){
   line(i,0,i,height);
 }
 for(int w=0; w<height; w+=heightSpace){
   line(0,w,width,w);
 }

replace widthSpace and heightSpace with any number you want for the grid
Page Index Toggle Pages: 1