Hello my friends,
I tried to create a grid with a scaleable size.
So I wanted to use this few lines to create the rectangles.
for (field2 = 0; field2 < x; field2 = field2 + 1){
Box[] box = { new Box(10+ size/2 *field2,10+ size/2 *size,size)};
box[bs].Drawbox();
bs = bs + 1;
}
}
I figured out, that this would everytime create the rectangle 0.
What can i do, that this would create the Rectangle 0, 1, 2, 3, …
the complete Code isn’t ready yet, but I cant work on the other things, if this is wrong.
Downthere is my complete code.
The line grid is only for orientation.
Thank you
float fieldx, fieldy;
float tx, ptx, pty, ty;
float field1, field2;
float x = 30;
float y = 30;
float size = 50;
int bs;
ArrayList<PVector> grid;
int BoxSize = 10;
Draw2DArray[] array = {
new Draw2DArray(x, y, size)
};
Draw2DArray c = new Draw2DArray(0, 0, 0);
void setup(){
size(3000,2000);
x = 1;
tx = 0;
ty = 0;
}
void draw(){
if (keyPressed){
if ( key == 'b'){
x = x + 0.008;
}
else if (key == 'n') {
x = x - 0.008;
}
}
if ((mousePressed) && (mouseButton == LEFT)){
tx = ptx +mouseX *2 - 2000;
ty = pty +mouseY *2 - 2000;
}
else {
mouseReleased();
}
background(200);
scale(x);
translate(tx, ty);
for (Draw2DArray c : array) {
c.Draw();
}
for (field1 = 0; field1 < y; field1 = field1 + 1){
for (field2 = 0; field2 < x; field2 = field2 + 1){
Box[] box = { new Box(10+ size/2 *field2,10+ size/2 *size,size)};
box[bs].Drawbox();
bs = bs + 1;
}
}
}
class Draw2DArray{
float Numx;
float Numy;
float lines;
float Size;
float SizeX;
float SizeY;
float field;
float posx, posy, Posx;
Draw2DArray(float NumX,float NumY, float SI){
Numx = NumX;
Numy = NumY;
Size = SI;
SizeX = Numy * Size;
SizeY = Numx * Size;
}
float i = 10;
void Draw() {
lines = 0;
i = 0;
for (lines = 0; lines < Numx; lines = lines + 1){
line(10, i, SizeX, i);
i = i + Size;
}
lines = 0;
i = 0;
for (lines = 0; lines < Numy; lines = lines + 1){
line(i, 10, i, SizeY);
i = i + Size;
}
}
}
void mouseReleased(){
ptx = tx;
pty = ty;
}
class Box{
float Bx, By, Size;
Box (float BX, float BY, float BS){
Bx = BX;
By = BY;
Size = BS;
}
void Drawbox(){
rect(Bx, By, Size, Size);
}
}