Thank you!
I changed it up a little since I don’t want to use class. But it works now!
Sometimes if I run the program there are two red blocks on the same position so I only see 9 blocks…
It doesn’t happen often but if I increase the number of red blocks to 30 it does happen a lot.
I tried to fix that with an ‘if-statement’ but I can’t get it to work…
int widthGrid = 60;
int heightGrid = 40;
int block[][] = new int[widthGrid][heightGrid];
int blockX[] = {
0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60
};
int blockY[] = {
0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40
};
int widthBlock = 10;
int heightBlock = 10;
int positionBlockY;
int positionBlockX;
void setup() {
size(600, 400);
}
void draw() {
for (int i = 0; i < widthGrid; i++) {
for (int j = 0; j < heightGrid; j++) {
int xPositionBlock = i * widthBlock;
int yPositionBlock = j * heightBlock;
fill(#0ff09d);
rect(xPositionBlock, yPositionBlock, widthBlock, heightBlock);
}
}
noLoop();
for (int p = 0; p < 10; p++) {
positionBlockX = blockX[(int)random(60)] * 10;
positionBlockY = blockY[(int)random(40)] * 10;
println(positionBlockX, positionBlockY);
fill(#ff0000);
rect(positionBlockX, positionBlockY, widthBlock, heightBlock);
}
}