We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hi There,
I made a horizontal (columns) grid and vertical (rows) grid of different rectangles (10 x 10) Now I want to declare the coördinates of an other individual rectangle on that grid by using an array. ( coördinate[x][y] ) For example, the rectangle can have a x-coördinate on the second of the columns and a y-coördinate on the third of the rows.
Can someone help me with this question
Thanks!
Answers
Show your code
Its still just simple
void setup() { size(500, 500); }
void draw() { for (int i = 0; i < width; i = i+width/10-10) { for (int j = 0; j < height; j = j+height/10-10) { rectMode(CENTER); rect(i, j, 20, 20); } } }
before
setup()
Make the for loops from
0
to<10
in setup() define all cells with a double for loop and
and in draw say in a double for loop:
Also make a class
Cell
Also read the tutorial about objects
https://www.processing.org/tutorials/objects/
@jaspervanblokland -- Here are different approaches:
rect()
display()
method, as per @Chrisirscale(x,y)
to scale your drawing space directly, then use rect() as normal.wStep
,hStep
) and use them as multipliers when drawing your grid points or mapping things to that grid.Your title suggests the first approach; here is an example of the last approach based on what you did in your short example sketch:
my objects based approach from above:
Thank you all!