Square grid not displaying....?
in
Programming Questions
•
1 year ago
Hey guys!
For some reason the square grid isn't showing up even though I checked (via println) that the rect(x, y, size, size) function is getting the correct values...I don't understand why when I type rect(115, 115, 20, 20) I get the square come up but when I feed it those numbers with variables I get no square. Am I missing something really simple?
For some reason the square grid isn't showing up even though I checked (via println) that the rect(x, y, size, size) function is getting the correct values...I don't understand why when I type rect(115, 115, 20, 20) I get the square come up but when I feed it those numbers with variables I get no square. Am I missing something really simple?
- ElectrodeSq[][] s;
- int numCols = 2;
- int numRows = 3;
- float gapX, gapY;
- float electSize = 20;
- float x, y;
- float chunkX;
- float chunkY;
- color background0 = color(95,95,91);
- color background1 = color(178, 172, 172);
- color electColor = color(232, 210, 12);
- void setup() {
- size(600,400);
- gapX = electSize/2 + 5;
- gapY = electSize/2 + 5;
- s = new ElectrodeSq[numCols][numRows];
- for(int i=0;i<numCols; i++) {
- for(int j=0; j<numRows; j++) {
- s[i][j] = new ElectrodeSq(i, j);
- }
- }
- noLoop();
- }
- void draw() {
- for(int i=0; i<numCols; i++) {
- for(int j=0; j<numRows; j++) {
- x = 100 + gapX;
- y = 100 + gapY;
- s[i][j].display();
- gapY+=electSize + 5;
- }
- gapX+= electSize + 5;
- }
- }
- ElectrodeSq[][] s;
- int numCols = 2;
- int numRows = 3;
- float gapX, gapY;
- float electSize = 20;
- float x, y;
- float chunkX;
- float chunkY;
- color background0 = color(95,95,91);
- color background1 = color(178, 172, 172);
- color electColor = color(232, 210, 12);
- void setup() {
- size(600,400);
- gapX = electSize/2 + 5;
- gapY = electSize/2 + 5;
- s = new ElectrodeSq[numCols][numRows];
- for(int i=0;i<numCols; i++) {
- for(int j=0; j<numRows; j++) {
- s[i][j] = new ElectrodeSq(i, j);
- }
- }
- noLoop();
- }
- void draw() {
- for(int i=0; i<numCols; i++) {
- for(int j=0; j<numRows; j++) {
- x = 100 + gapX;
- y = 100 + gapY;
- s[i][j].display();
- gapY+=electSize + 5;
- }
- gapX+= electSize + 5;
- }
- }
- class ElectrodeSq {
- float electSize;
- float posX, posY;
- ElectrodeSq(float posX, float posY){
- this.electSize = electSize;
- this.posX = posX;
- this.posY = posY;
- }
- void display() {
- fill(background0);
- rectMode(CENTER);
- rect(width/2, height/2, width-60, height-40);
- fill(background1);
- rectMode(CENTER);
- rect(width/2, height/2, width-70, height-50);
- fill(electColor);
- rectMode(CENTER);
- rect(x, y, electSize, electSize); //not working for some reason
- println(x+" "+y); //using println I see that I am getting the right x and y values
- rect(115, 115, 20, 20); //manually typing the values into rect() I get a rectangle show up
- }
- }
Thank you!
McK
McK
1