記録

勉強したことに関するのノート。見返して分かるようにしてます。

PVector理解5

int num=500;
PVector[] pos=new PVector[num];
PVector[] vel=new PVector[num];
color[] c=new color[num];
int[] r=new int[num];


void setup() {
  size(960, 540, FX2D);
  colorMode(HSB, 360, 100, 100);

  for (int i=0; i<num; i=i+1) {
    pos[i]=new PVector(random(width), random(height));
    vel[i]=new PVector(random(1, 3), random(1, 3));
    c[i]=color(random(180, 200), random(50, 100), random(50, 100));
    r[i]=int(random(2, 10));
  }
}
void draw() {
  //background(0, 0, 0);
  fill(0, 0, 0, 5);
  rect(0, 0, width, height);
  //noStroke();
  for (int i=0; i<num; i=i+1) {
    pos[i]=new PVector(random(width), random(height));
    vel[i]=new PVector(random(1, 3), random(1, 3));
    fill(c[i]);
    ellipse(pos[i].x, pos[i].y, r[i]*2, r[i]*2);
    pos[i].add(vel[i]);

    if (pos[i].x>=width-r[i]||pos[i].x<=0+r[i]) {
      vel[i].x=vel[i].x*-1;
    }
    if (pos[i].y>=height-r[i]||pos[i].y<=0+r[i]) {
      vel[i].y=vel[i].y*-1;
    }
  }
}

雨がザアザアと降っているように見えた。もはやif文は作動してない。色も似てる色に設定。