We are about to switch to a new forum software. Until then we have removed the registration on this forum.
hi everybody, I recently incurred in an unexpected behavior using rect to draw a grid of squares. i have a Cell calss that draws every rect to form a grid. The grid is initially drawn during setup without issues, but after being drawn for a few draw cycles the grid deforms. I tried replacing rect with ellipse and the a.m. misbehavior doesn't show up. This is my code
Processing version 3.3 running on Linux Mint-PC 4.4.0-53-generic #74 x86_64 GNU/Linux
Can anyone recreate and or explain the erratic behavior described?
Cell[][] grid;
int rows;
int columns;
int gridSize=20;
boolean updateGrid = false;
void setup() {
size (800, 300);
background(200);
rectMode(CORNER);
columns = width/gridSize;
rows = height/gridSize;
grid = new Cell[columns][rows];
//grid displays well in setup
for (int i=0; i<columns; i++) {
for (int j=0; j<rows; j++) {
grid[i][j] = new Cell(i*gridSize, j*gridSize, gridSize);
grid[i][j].displayCell();
}
}
}
void draw() {
//if (updateGrid) {
//issues appear here after about 20 draw cycles
for (int i=0; i<columns; i++) {
for (int j=0; j<rows; j++) {
grid[i][j].displayCell();
}
}
//updateGrid=false;
//}
}
//void mousePressed() {
//int x = floor(mouseX/gridSize);
//int y = floor(mouseY/gridSize);
//grid[x][y].activateCell();
//updateGrid= true;
//}
class Cell {
float cellPsnX;
float cellPsnY;
float cellSize;
boolean activeCell;
Cell(float _x, float _y, float _size) {
cellPsnX = _x;
cellPsnY = _y;
cellSize = _size;
activeCell=false;
}
void activateCell() {
activeCell = !activeCell;
}
void displayCell() {
stroke(10);
if (activeCell) {
fill(100, 50, 255);
} else {
fill(255);
}
rect(cellPsnX, cellPsnY, cellSize, cellSize);
//ellipse(cellPsnX, cellPsnY, cellSize, cellSize);
}
}
Answers
Please edit your post, select your code and hit ctrl+o to format your code. Make sure there is an empty line above and below your code.
I run your code in Linux OS and no issues. The grid seems fine. You can use save() to save a frame of your program showing the issue and post it here in the forum.
Kf
Thx for the feedback, I'm struggling with formatting. I'll try to post an image.
Post updated including frame drawn correctly at setup and frame of wrong behavior experienced during draw
What video card do you have? Do you experience the same with other renderers?
size (800, 300,P2D/JAVA2D/FX2D);
Very odd... What happen if you remove rectMode? If you change the width as declared in size?
Kf
Same issue with all other renders.
I purposely added rectMode in an attempt to solve the issue
system details follow:
Integrated graphics card on a netbook intel Atom Processor Z36xxx/Z37xxx Series Graphics & Display on an hp netbook.
I thought it was a system issue and tried to draw the grid only on mouse click //commented sections in the code.
the result is that everything runs fine for about only 40 click/drawing of the grid: after that same issue. Filling the rect on click showed that the shape doesn't have issues, only the stroke around it.
Changing the rect with ellipse and the issue disappears.
My system is lousy but I manage to get more complicate stuff running without issues.
I'm considering overlaying an independent grid over the rect drawn with noStroke().
Thank you for taking time to dig into this issue.
[SOLVED] restarted Processing, tried again with the various renders Issue disappeared only using FX2D. @kfrajer Thank you, your answer did actually solve the problem.
So do you still have issues using the standard JAVA2D renderer? What about P2D or OPENGL?
Glad it is working now and thank you for posting your solution. Restarting is a good trick at the end >-)
Kf
@kfrajer the issue remains with JAVA2D, P2D, OPENGL. FX2D is the only stable renderer.
@seamiki -- This sounds like it might have been a specific driver or hardware issue -- such as a problem like bad ram in your graphics card etc.
I cannot reproduce your issue using your code with any renderer w/Processing 3.3 on a MacBook running 10.12.3-- the grid draws fine in default, JAVA2D, P2D, P3D, OPENGL, FX2D. My guess is that if you switch to any other computer you won't be able to reproduce this either...?
@jeremydouglas you might be right. I just wondered, cause I've done much more intensive drawing without issues on the same computer. Thanx for taking your time into this.