array_PVector_ellipse04

int num = 1000;

PVector[] pos;
PVector[] vel;
color[] c;

void setup() {
  size(500, 500);
  colorMode(HSB, 360, 100, 100, 100);
  background(0, 0, 100);
  noStroke();

  pos = new PVector[num];
  vel = new PVector[num];
  c = new color[num];

  for (int i =0; i < num; i ++) {
    pos[i] = new PVector( random(width), random(height));
    vel[i] = new PVector( random(-10, 10), random(-10, 10));
    c[i] = color(80, 100, i%100, i%100);
  }
}

void  draw() {
  fill(0, 0, 100, 10);
  rect(-50, -50, width+50, height+50);
  
  for (int i=0; i < num; i++) {
    pos[i].add(vel[i]);
    fill(c[i]);
    ellipse(pos[i].x, pos[i].y, i%100, i%100);

    if (pos[i].x < 0 || pos[i].x > height) {
    vel[i].x= - vel[i].x;
    }
  }
}

前回,pointでつくったものをellipseにして色をつけてみた.マウスでクリックするともとに戻るようにしたかったけど,夜遅いので次の宿題.