I have homework where i was supposed to make recreate a drawing from a famous painter. The assignment now is to make the window resizable. I came up with this solution:
void setup() {
background(255, 255, 255);
size(600, 600, P2D);
surface.setResizable(true);
}
void draw() {
stroke(0, 0, 0);
strokeWeight(3);
u = min(height/600.0, width/600.0);
for (int i=0; i<5; i=i+1) {
for (int j=0; j<1; j+=1) {
x = int(random(0, 300*u));
y = int(random(0, 300*u));
w = int(random(2.0*u, 5.0*u));
h = int(random(2.0*u, 5.0*u));
}
pushMatrix();
translate(x, y);
scale(w, h);
fill(random(100, 255), 0, 0);
rect(0, 0, 100, 100);
popMatrix();
for (int j=0; j<1; j+=1) {
x = int(random(0, 300*u));
y = int(random(0, 300*u));
w = int(random(2.0*u, 5.0*u));
h = int(random(2.0*u, 5.0*u));
}
pushMatrix();
translate(x, y);
scale(w, h);
fill(0, 0, random(100, 255));
rect(0, 0, 100, 100);
popMatrix();
}
noLoop();
}
Problem, when i resize the window, the whole window turns black. Do i just not see the problem right now?
This is because you only drew the background once in setup(). Since the draw() function is being executed multiple times per second, you need to draw your background at each iteration in order to clear the screen.
Outside of the initial region, it’s black by default… unless the background is drawn again
After removing the noLoop(); it works, but i only want the first for loop to be run once, i dont want to be contantly bombarded with new shapes, only the 10 that get created in the inital “run”(idk if thats the right way to call it xd).
Looks just fine on a Mac. What operating system are you using? Was that an exported app that you posted with the black border? Are you trying to make resizable rectangles?