I’m trying to get a 2D grid to display properly with 1 subclass object before adding additional subclasses.
The code for this 2D array grid is pulled from one of my previous projects, and it worked fine.
However, the difference is: with this sketch I am breaking the class down into subclasses. I am thinking this may be the issue? However, not able to find any specific threads on-line to pursue.
I also tried implementing pushMatrix() and popMatrix() in the subclass, to no avail…
Or, some basic oversight…
Any guidance most welcome!
// MAIN
HalfmoonRect [][] myHMrect;
int num = 4;
int cols = num, rows = cols;
void setup(){
size (800, 800);
frameRate (1);
float x = 0, y = x, sz = width/num;
myHMrect = new HalfmoonRect [cols][rows];
for (int i = 0; i < cols; i++){
for (int j = 0; j < rows; j++){
myHMrect[i][j] = new HalfmoonRect (x+(i*width/cols), y+(j*height/rows), sz);
}
}
}
void draw(){
for (int i = 0; i < cols; i++){
for (int j = 0; j < rows; j++){
myHMrect[i][j].display();
}
}
}
// SUPER
class Halfmoon {
color c1 = #FFFFFF,
c2 = #BEBEBE,
c3 = #7F7F7F,
c4 = #3F3F3F,
c5 = #000000;
color[] grays = {c1, c2, c3, c4, c5};
float deg, rad;
float x, y, sz;
Halfmoon(float tempX, float tempY, float tempSz) {
x = tempX;
y = tempY;
sz = tempSz;
//deg = radians(90);
}
void rectPlusColor (color rectColor) {
fill (rectColor);
rectMode (CENTER);
rect (x, y, sz, sz);
}
}
// SUBCLASS
class HalfmoonRect extends Halfmoon {
HalfmoonRect(float x, float y, float sz) {
super(x, y, sz);
}
void display() {
noStroke();
translate (100, 100);
rectPlusColor(grays[int(random(grays.length))]);
}
}