Vector_ellipse01

PVector pos;
PVector vel;
PVector gra;

void setup() {
  size(500, 500);
  colorMode(HSB, 360, 100, 100);
  frameRate(24);
  fill(150, 80, 100);

  pos = new PVector(width/2, height/2);
  vel = new PVector(random(-5, 5), random(-5, 5));
}


void draw() {
  background(0, 0, 100);
  gra = new PVector(random(-5, 5), random(-0.05, 0.05));

  pos.add(vel);
  vel.add(gra);

  noStroke();
  fill(random(360), 80, 100);
  ellipse(pos.x, pos.y, 100, 100);
  fill(random(360), 80, 100);
  ellipse(pos.x, pos.y, 50, 50);
  
  checkEdge();
}

void mousePressed() {
  gra.x = -5;
  gra.y = 0.05;
}

void checkEdge() {
  if (pos.x > width || pos.x < 0) {
    vel.x = vel.x * -1;
  }
  if (pos.y > height || pos.y < 0) {

    vel.y = vel.y * -1;
  }
}

高尾さんに教わったPVectorを復習.pos vel までは写経.写経してなんとなく感じを掴んで,gra は自分で追加.といっても,高尾さんのサンプルにもあったやつだけど… サンプルは見ないで追加してみた.「どっちいこうかな?」という感じをだしたかった.すこしPVectorがわかった気がする.