Declaring a global var once and having void draw() call its methods isn't working
in
Programming Questions
•
2 years ago
I am trying to code some cellular automata and I have a container class named LifeMatrix. I want the draw thread to repeatedly call LifeMatrix's drawMatrix and updateMatrix methods. I thought that I needed to declare variable LifeMatrix Life as a global var and then initialize it during void setup() and then make the draw and update calls in void draw(), however this only draws the matrix once and then freezes. Putting the initialization of Life inside void draw() and then having drawMatrix and updateMatrix inside a for loop works perfectly though, it is not ideal. Sorry if this is confusing, see below for the code
LifeMatrix Life;
void setup() {
size(800,800);
Life = new LifeMatrix(100);
}
void draw() {
Life.drawMatrix();
Life.updateMatrix();
}
1