Hello there,
I createt a scaleable grid, that have no funktion at the Moment.
But it is Scaleable and you can move it.
Now my problem.
I want to generate a Grid with 1000*1000 rectangles (or more), but 1 000 000 rectangles are very much.
If i want to scale or transform the grid, I have only about five FPS
Is there a way to make that I reach 30 FPS?
Down there is the Code.
Thank you very much.
// Szize of one rectangle
int size = 50,t;
float s,tr, tx, ty, tix, tiy;
//Grid size
int x = 1000, y = 1000;
class Gitter{
float numx, numy, size, col,mode,px,py,i;
//I need them later, but at the moment hey have no function
int n1, n2, n3, n4, n5, n6, n7, n8, i2;
Gitter(float id, float NUMX, float NUMY, float SIZE){
numx = NUMX;
numy = NUMY;
size = SIZE;
i = id;
}
void Draw(){
rectMode(CENTER);
noStroke();fill(255);rect (numx * size +10,numy * size + 10, size-1 , size-1 );
}
}
Gitter[] gitter = new Gitter[x*y];
void setup(){
size(1600,800);
int I = 0;
int ix,iy;
s = 1;
for (iy = 0;iy < y; iy = iy+1){
for(ix = 0;ix < x; ix = ix+1){
gitter[I] = new Gitter(I++,ix, iy, size);
}
}
tr = 0;
}
void draw(){
//scaling andtranslations
if (keyPressed){
if (keyCode == UP ){
s=s+0.05;
}
else if (keyCode == DOWN ){
s=s-0.05;
}
}
if ((mousePressed) && (mouseButton == LEFT)) {
if (tr == 0){
tr = 2;
tix = tx;
tiy = ty;
tix = tix - mouseX*(1/s);
tiy = tiy - mouseY*(1/s);
}
else{
tx = (1/s)*mouseX + tix;
ty = (1/s)*mouseY + tiy;
tr = 3;
}
}
if (tr > 0){
tr = tr - 1;
}
scale(s);
translate(tx,ty);
background(0);
int ix,iy;int I=0;
//draw grid
for (iy = 0;iy < y; iy = iy+1){
for(ix = 0;ix < x; ix = ix+1){
gitter[I++].Draw();
}
}
}