I have made a loop with rectangles and I am trying to Increase gradually the Stroke , so have made another loop for that, but It does not work. Could you please help me? Thanks!
size(1000,1000);
background(255,255,255);
fill(0,255,255);
rectMode(CENTER);
for (int w = 0; w < 10; w++){
strokeWeight(w);
}
for (int i = 0; i < 20; i++){
int s = 1000 -i * 50;
rect(width/2,height/2,s,s);
}
Thank you so much? I have tried this but It does not work, do you know why?
size(1000,1000);
background(255,255,255);
fill(0,255,255);
rectMode(CENTER);
for (int i = 0; i < 20; i++){
int s = 1000 -i * 50;
for (int w = 0; w < 10; w++){
strokeWeight(w);
rect(width/2,height/2,s,s);
}
}
I wasn’t talking about just putting the for loop inside the second one.
When you have a program, try to check on paper or in your head what it’s going to do step by step:
i = 0
w = 0
w = 1
w = 2
...
w = 9
i = 1
w = 0
w = 1
w = 2
...
w = 9
So basically you are doing 20 x 10 iterations in total because the two for loops are nested so you are drawing 200 rectangle instead of 20 and because each time you change the strokeWeight but draw the rectangle at the same position (width/2,height/2,s,s) the largest stroke (9) is hiding the smallest stroke weights.
Try to figure out how to change the stroke weight for each one of the rectangles with a single for loop
Thank you so much for your answer. Now I think that I undestand the problem , but I don’t know how to solve It because StrokeWeight It something that is not inside of rect(width/2,height/2,s,s); so could you give a clue, please? Thanks!
Thank you so much for your answer. This is a draft of what I am looking for. I can make a loop for squares, but with strokes I only can think in creating a variable as If tried, It is the way to Go on?
In this example you are doing it manually but what you want is to use a for loop as you did before. Try to identify how the square size change over the iterations and do the same for the stroke weight.
What is the link between iteration 0 and iteration 1? You go from 900 to 600 for the rect size and 15 to 10 for the stroke weight…
Then depending on the loop iteration number you can compute both properties.
Also instead of using rect(x, y, w, w) you can directly draw a square with square(x, y, w)
Thanks Joseph. I can do It manually with different values but I can not do It in a loop, I try it is not right and I don’t know how to advance
size(1000,1000);
background(255,255,255);
noFill();
rectMode(CENTER);
for (int i = 0; i < 20; i = i + 1){
int s = 1000 -i * 50;
for (int w = 0; w < 20; w = w + 1){
strokeWeight(10-w);
rect(width/2,height/2,s,s);
}
}
I know what I Want to do, that is clear. The loop for quads is working, but the loop for StrokeWeight is not and I really don’t know if it’s possible to do a loop for that or if should do It by hand
You are right, before reading this I have achieved something using only int I
size(1000,1000);
background(255,255,255);
noFill();
rectMode(CENTER);
for (int i = 0; i < 20; i = i + 1){
int s = 1000 -i * 50;
strokeWeight(i);
rect(width/2,height/2,s,s);
}