Creating an array of vectors in a line

And it will… keep it simple and work through PShapes and PVectors and then merge the two.

You just have to invest time in this.

This is just an example of creating a shape using vertices where the vertices are PVectors:

Example < Open here!
float rot = 0.0;
PVector v1, v2, v3, v4, v5;

void setup() 
  {
  size(500, 500);
  noSmooth();
  }
  
void draw()
  { 
  background(0);  
  translate(width/2, height/2);
  strokeWeight(5);
  strokeCap(ROUND);
  stroke(255, 255, 0);  
  v1 = new PVector(0, 0);  
  v2 = new PVector(0, 150);
  v3 = new PVector(150, 150);  
  v4 = new PVector(150, 0); 

  rot = map(mouseX, 0, width, -PI, +0);
  v1.rotate(rot);
  v2.rotate(rot);
  v3.rotate(rot);
  v4.rotate(rot); 

  //debugging
  println(v4);
  String s = str(v4.x) + "  " + str(v4.y);
  text(s, v3.x, v3.y);
  
  noFill();
  beginShape();
  vertex(v1.x, v1.y);
  vertex(v2.x, v2.y);
  vertex(v3.x, v3.y);
  vertex(v4.x, v4.y);
  endShape(CLOSE);
  
  line(v2.x, v2.y, -width/2, -height/2);
  }

Use println() statements to help you see what the variables are:
println() / Reference / Processing.org to show on console
or
text() / Reference / Processing.org to display on canvas

Keep in mind that there is always more than one way of doing things; you will learn that as you progress.

:)

1 Like