PVector_vertex01

PVector pos;
PVector vel;
float r;

void setup() {
  size(500, 500);
  colorMode(HSB, 360, 100, 100, 100);
  pos = new PVector (0, 0);
  vel = new PVector(1, 1);
  background(0, 0, 100);
}

void draw() {
  fill(0, 0, 100, 5);
  rect(0, 0, width, height);

  pos.add(vel);

  r = atan2(mouseX, mouseY);

  pushMatrix();
  translate(pos.x, pos.y);
  rotate(r);

  beginShape();
  vertex(pos.x*2, pos.y*2);
  vertex(pos.y*-2, pos.x*-2);
  endShape();

  beginShape();
  vertex(pos.x*2, pos.y*-2);
  vertex(pos.y*-2, pos.x*2);
  endShape();

  popMatrix();

  if (pos.x < 0 || pos.x > width) {

    vel.x = - vel.x;
    vel.y =- vel.y;
  }
}

PVectorの練習.なんとなく動かすことはできてきた.PVectorのどこがそれ以外のやり方に対して便利なのかは,いまいちわからないけれど, pos.add(vel)というだけで,x yの値が決まっていくのが便利なのだろう.きっとそうなのだろう.そのためのPVectorなのだろう.