Creating an array of vectors in a line

Hello,

I have not looked at your recent post.

An exploration from the other day:

POINTS version
float angle = 0;
int steps = 10;

PVector vec;

void setup() 
  {
  size(600, 600);
  background(0);
  stroke(255, 255, 0);
  strokeWeight(2);
 
  translate(width/2, height/2);
  
  vec = new PVector(1, 1);

  for (int j = 0; j < steps; j++) 
    {
    angle = TAU/steps;
    vec.normalize();
    vec.rotate(angle);
    vec.mult(-100);  // Try 100 and -100
    
    beginShape(POINTS);     
    vertex(vec.x, vec.y);
    endShape();       
    }
  } 
LINES version
float xposLast;
float yposLast;
 
float angle = 0;
int steps = 10;

PVector vec;

void setup() 
  {
  //noSmooth();
  size(600, 600); 
  background(0);
  
  stroke(255,255, 0);
  strokeWeight(2);
 
  translate(width/2, height/2);
  
  vec = new PVector(1, 1);
  vec.normalize();
  vec.mult(100);
  xposLast = vec.x;
  yposLast = vec.y;  

  for (int j = 0; j < steps; j++) 
    {
    angle = TAU/steps;
    vec.normalize();
    vec.rotate(angle);
    vec.mult(-100);  // Try 100 and -100
    
    stroke(255, 255, 0);
    strokeWeight(2);
    
    //line(vec.x, vec.y, xposLast, yposLast);

    beginShape(LINES);      
    vertex(vec.x, vec.y);
    vertex(xposLast,yposLast);
    endShape();      
    
    xposLast = vec.x;
    yposLast = vec.y;      
    }
  }    

I broke it into two versions for POINTS and LINES.

Any examples provided are meant for insight only; explore and scrutinize them and work on your project. That is my disclaimer. :)

Pleased to see you are working at this… that is why I shared my examples.

Each step will bring you closer.

:)

1 Like