Hi there! I am learning about loops with “for” with a useful tutorial. I have made a pattern with few lines of code (amazing!). But the pattern that I really want to do has diagonal lines of points, as you can see on the picture, and I can not Imagine the way on my head. Could you please give me a hand? Many thanks!
The problem is that your y variable is jumping in steps of 100, so is always even. (This solution is horrible but funny: y=y+100 change to +101, and point(x+100, ) should be x+50, )
I find it better to use x and y variables that count the items, eg. sqX that counts from 0 to 10, then calculate the graphical position from that, usually with two variables offsetX and scaleX; Do the same for Y. Now your sqY counts in 1s and can be used in the y%2 calculation. If you want to change the size you can alter the scale values without it affecting the logic.
As you can see, I am really beginner, so I don’t drive many of the things that you suggest me. With my knowledge I can do something like that:
void setup(){
size(1000,1000);
background (255);
stroke(0);
strokeWeight(10);
for(int x = 100; x < 1000; x=x+200) {
for(int y = 100; y < 1000; y=y+200) {
point(x,y);
}
}
for(int x = 100; x < 900; x=x+200) {
for(int y = 100; y < 800; y=y+200) {
point(x+100,y+100);
}
}
}
Maybe the code is not so smart, but it would be enough… if not for the second part. I want to make variations of colors and I want them to be diagonal, as you can see here:
So maybe my first question should be how to make a diagonal queue of points and then try to make a loop.
I can make a pattern with horizontal and vertical queues, but the colors change in those directions, so is not exactly what I want. I share here the result:
Thank you so much, x=y it is what my head was looking for (coding needs some mathematics )
Now I have made two diagonals with this code:
void setup(){
size(1000,1000);
background (255);
stroke(0);
strokeWeight(10);
for(int a = 100; a < 1000; a=a+100) {
int b = a;
point(a,b);
for(int c = 300; c < 1000; c=c+100) {
int d = c;
point(c,d-200);
}
}
}
I see in new diagonal x+200 and y-200, but I don’t know how to make a loop with that, because I want to make a lot of new diagonals. Could you please help me?
You were nesting your loops and that is not necessary for this code.
I cleaned it up.
void setup()
{
size(1000, 1000);
background (255);
stroke(0);
strokeWeight(10);
for (int a = 100; a < 1000; a=a+100)
{
int b = a;
point(a, b);
}
for (int c = 300; c < 1000; c=c+100)
{
int d = c;
point(c, d-200);
}
// Add more for() loops to start seeing a pattern
}
Add more for() loops to complete the diagonals to start seeing a pattern.
I have made this and I have seen than every line has +200 in X coordinate and -200 Y coordinate to the right of Centered diagonal, and +200 in Y coordinate and -200 in X coordinate to the left.
void setup(){
size(1000,1000);
background (255);
stroke(0);
strokeWeight(10);
for(int a = 100; a < 1000; a=a+100) {
int b = a;
point(a,b);
}
for(int c = 300; c < 1000; c=c+100) {
int d = c;
point(c,d-200);
}
for(int e = 500; e < 1000; e=e+100) {
int f = e;
point(f,e-400);
}
for(int g = 700; g < 1000; g=g+100) {
int h = g;
point(g,h-600);
}
for(int i = 900; i < 1000; i=i+100) {
int j = i;
point(i,j-800);
}
for(int l = 300; l < 1000; l=l+100) {
int k = l;
point(k-200,l);
}
for(int n = 500; n < 1000; n=n+100) {
int m = n;
point(m-400,n);
}
}
I guess last loop make that gradual increase, but I don’t know to use it on first loop. What do you mean with “each diagonal”? It isn’t possible to make the pattern with a loop?
As you can see, I am a little lost : S
void setup(){
size(1000,1000);
background (255);
int num1 = 100;
int num2 = 100;
for (int i = 0;i<5;i++){
num1 = 100 + i*200;
num2 = 100 - i*200;
}
stroke(0);
strokeWeight(10);
for(int a = 100; a < 1000; a=a+num1) {
int b = a;
point(a,b);
}
}
I am thinking in how to repeat this loop…
stroke(0);
strokeWeight(10);
for (int a = 100; a < 1000; a=a+100)
{
int b = a;
point(a, b);
}
…with an operation to make a pattern with, for example 100 diagonals, without writing a line for everyone. It will be possible?