We are about to switch to a new forum software. Until then we have removed the registration on this forum.
So I have a small piece of code that I eventually would like to turn into something more advanced but for now I need to figure out how to make the computer understand that each of the squares shown is a specific grid reference (aka coordinate) on the screen.
This I do now know how to do, was wondering if I gave the code I have now if someone could help adapt it to what I need would be super awesome. Thanks
Code bellow:
`size(500,500); int cols = width; int rows = height;
// Declare 2D array int[][] myArray = new int[cols][rows]; // Initialize 2D array values for (int i = 0; i < cols; i+=50) { for (int j = 0; j < rows; j+=50) { myArray[i][j] = int(random(255)); } }
// Draw points for (int i = 0; i < cols; i+=50) { for (int j = 0; j < rows; j+=50) { stroke(myArray[i][j]); fill(myArray[i][j]); rect(i,j,50,50); } }`
Answers
Please format your code: https://forum.processing.org/two/discussion/15473/readme-how-to-format-code-and-text
What exactly is your question? What does your code do? What do you want it to do? What exactly do you mean when you say you want to make the computer understand?
Simple answer here is to make OOP grid. Have a class for a Cell and a class for a Grid. You can then create a system that will return you a reference for particular cell and you will be able to manipulate it. I recommend "Nature of code" by Shiffman, particulary, there's a chapter explaining grids in detail: http://natureofcode.com/book/chapter-7-cellular-automata/ If this would seem too hard, start the book from the beginning.