Loop with increasing inclination

Hi there! I want to make a loop with diagonal lines whose inclination grows little by little. My loop draws lines 10 by 10, but I want to incline them 1 by 1 and I don’t know how. If I use variable ‘i’ I think increase start from 20, but if I create another variable that grows 1 by 1 does not work. Could you please help me?

size(1000,1000);
strokeWeight(3);

for (int i =-100; i<=1100; i+=20) {
      for (int j =0; j<=1000; j++) {
      stroke(255,0,0);
     line(i+i,0,i,1000);
      }
}

Not really understand what you are trying to achieve? Something like that ?

void draw() {
  background(0);
  strokeWeight(1);
  stroke(255,0,0);
  for (int i = 0; i < 90; i++) {
    pushMatrix();
    translate(0,height);
    rotate(radians(i));
    line(0,0,0,-height);
    popMatrix();
  }
}

dummy

1 Like

You only need ONE for loop with i

You don’t need pushMatrix or translate etc.

The line command could be

line(i, 100, i2, 60);

i2=i2+3;

sorry, I think that I did not explain this correctly. This is want I am trying to do
procs

And?

Does my version work?

You can just do it like this … (first two lines parallel and afterwards increase w counter for increase spacing)

void draw() {
  background(0);
  strokeWeight(3);
  stroke(255,0,0);

  for (int w=0,i=10;i+w<width;i+=10) {
    line(i,height,i+w,0);
    if (i>10)
      w++;
  }
}

dummy3

Cheers
— mnse

3 Likes

I think that your version changes both axis of the lines

thank you so much, I would never been able to imagine this solution

Nice solution, i always forget you can declare multiple variables in a for loop, there’s so much to remember and some things slip the memory bank lol

2 Likes

I have used your smart idea to make this growing loop and now I would like to make a decreasing one, as you can see on the picture, but I don’t find the way. Could you please help me?

size(1000,1000);
background(0);
strokeWeight(3);

stroke(0,0,255);
for(int w=0, i=0; i<300; i+=10+w) {
  line(i,0, i,1000);
  w++;
}

for(int w=0, i=300; i<600; i+=10-w) {
  line(i,0, i,1000);
  w++;
}

Hi

Idea without loop

int c = 1;
int move=0; 
void setup() { 
  size(600, 600);
} 
void draw() { 
  //background(255); 
  move= move + c; 
  line(move, width, move, 0); 
 
    c= c +1;
  }


Really interesting, but I still don’t know how to make a decreasing loop with that

Hi

It’s same @mnse code

void draw() {
  background(0);
  strokeWeight(3);
  stroke(255,0,0);

 // for (int w=0,i=10;i+w<width;i++) {
  for (int w=0,i=10;i+w<width;i++) {
  int d =i+w;
    line(d,height,d,0);
   // if (i>10)
      w=w+15;
  }
}

I could make an increasing loop with that idea, but not a decreasing one like the one you can see on the picture

size(1000,1000);
background(0);
strokeWeight(3);

stroke(0,0,255);
for(int w=0, i=0; i<300; i+=10+w) {
  line(i,0, i,1000);
  w++;
}

for(int w=0, i=300; i<600; i+=10-w) {
  line(i,0, i,1000);
  w++;
}

Why not !?

void draw() {
  background(0);
  strokeWeight(1);
  stroke(255,0,0);
  
  for(int i=0,w=0; i<width; i+=10+w) {
    line(i,0, i,height);
    if (i < width/2)
      w++;
    else 
      w--;
  }  
}

or if you want it even more unreadable and compact :slight_smile:

void draw() {
  background(0);
  strokeWeight(1);
  stroke(255,0,0);
  
  for(int i=0,w=0; i<width;w+=((i < width/2) ? 1 : -1), i+=10+w) {
    line(i,0, i,height);
  }
}

Cheers
— mnse

dummy6

1 Like

amazing! now I am trying something more complex, make the space between lines larger and also the thickness of the lines, as you can see on the picture. I have created a new variable on the loop but I think it is not working

sintitulo1

size(1000,1000);
background(255,255,255);

   

   stroke(255,0,0);
    for(int i=0,w=0,u=0; i<1000; i+=16+w) {
    strokeWeight(8+u); 
    line(i,0, i,1000);
    if (i < 300)
     w++;
    else if(i <300)
     u+=8;
    else if (i < 600)
      w--;
    else 
      w = 0;
  } 
  

This doesn’t work as if i < 300 it only goes into first branch where you increasing w the second branch is never reached…

— mnse

thanks! And could you just tell me why these two loops do not grow tangentially?

size (1000,1000);
  background(0);
  strokeWeight(10);
  
  
  for(int i=0,w=0; i<width; i+=20+w) {
    stroke(0,0,255);
    line(i+50,0, i,height);
    if (i < 500)
      w=w+1;
   
  }
   for(int k=10,v=0; k<width; k+=20+v) {
    stroke(0,255,0);
    line(k+50,0, k,height);
    if (k < 500)
      v=v+1;
    
  }

I really don’t know why these lines are not together if they have same thickness and they grow with same distances between them, do you know what I should improve?

Hello @humano,

Consider this:

line(k+50+10, 0, k+10, height); // Also k = 0 initially

:)

1 Like