alright I made this code to try and get a grid of cells across the screen to try and make a cellular automata as I am quite new to programming but when I run this all of my cells are in one place near the bottom center on my screen (I know this because I set them to always display as white to check where they where as it wasn’t working. you may notice a logic function that generally isn’t being called but I just wanted to see if there was something I was missing that is obvious.
import java.util.ArrayList;
boolean paused = false;
int x = -10;
int y = -10;
final static ArrayList<cell> cells = new ArrayList();
class cell
{
boolean state;
float xpos, ypos;
float age;
int identify;
cell (float x, float y, int ident) {
xpos = x;
ypos = y;
identify = ident;
}
void colour()
{
if (state == true)
{
fill(255);
} else
{
fill(0);
}
}
void DrawAndPress()
{
if (mouseX > x && mouseX < x+10 && mouseY > y && mouseY < y+10 && mousePressed)
{
state = !state;
}
rect(x, y, 10, 10);
}
void Logic()
{
}
}
void setup()
{
fullScreen();
background(0);
noStroke();
for (int i = 0; i < (width*height)/10000; i = i+1)
{
x = x+10;
if (x > width)
{
y = y+10;
x = 0;
}
cells.add( new cell(x, y, i));
}
}
void draw()
{
for (cell c : cells) c.colour();
for (cell c : cells) c.DrawAndPress();
if (!paused)
{
for (cell c : cells) c.Logic();
}
}