I'm using Processing to create a four-by-four grid with a specified width and height, as follows.
My ultimate goal is to be able to check when the user clicks inside a particular square. In my example, the width and height will both be set to 480 units, but this will eventually grow. So I'd like to do things in a formulaic fashion rather than manual input.
My initial thought was to obtain the vertices of every corner of every square in the grid, set it to a variable name, and then have a bunch of if conditions to check if the user clicks inside a bounded region. Here's what I have so far.
WIDTH = 480
HEIGHT = 480
rows = [WIDTH * 0.0, WIDTH * 0.25, WIDTH * 0.50, WIDTH * 0.75, WIDTH * 1.00]
columns = [HEIGHT * 0.0, HEIGHT * 0.25, HEIGHT * 0.50, HEIGHT * 0.75, HEIGHT * 1.00]
coordinates = [(i, j) for i in rows for j in columns]
# "coordinates" is a list of tuples of all the vertices:
# [(0.0, 0.0), (0.0, 120.0), (0.0, 240.0), (0.0, 360.0), (0.0, 480.0), (120.0, 0.0), (120.0, 120.0), (120.0, 240.0), (120.0, 360.0), (120.0, 480.0), ...]
So I'm able to get a list of tuples of every possible vertex, and now I'd like to assign them all to variables.
For example, for row 1, column 1 (top left square in the grid) the user would need to click in an area less than (0, 120) and (120, 0), but greater than (0,0) and (0,0). These are the vertices that ascribe the top-left square in the grid. I'd do this for each square.
I could give each of these vertices a variable name. For instance, (0, 0) could be vertex_one, (0, 120) could be vertex_two and so on. I know how to iterate through a list of tuples, but I don't know how to assign them to a changing string named vertex_n -- where n represents the vertex number -- while iterating.
But I read from this thread that it's apparently not a good idea to do this. So now I don't know if I should just input each vertex manually or if there's a more programmatic/automatic way to do this, like maybe a dictionary lookup. Because when the grid gets larger, that'll require me to manually type in an even larger number of vertices, which is undesirable.
Any ideas and suggestions on what approach I should take would be appreciated!