記録

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

窓の景色

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

void setup() {
  size(960, 540);
  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), 0);
    c[i]=color(pos[i].y%360, random(50, 100), random(50, 100), random(50, 100));
  }
}

void draw() {
  fill(0, 0, 0, 10);
  rect(0, 0, width, height);
  noStroke();
  for (int i=0; i<num; i=i+1) {
    fill(c[i]);
    ellipse(pos[i].x, pos[i].y, r*2, r*2);
    pos[i].add(vel[i]);

    if (pos[i].x>width+r) {
      pos[i].x=0;
    }
  }

  fill(0, 0, 0);
  rect(0, 0, 150, height);
  rect(width-150, 0, width, height);
  rect(0, 0, width, 100);
  rect(0, height-100, width, height);
  noStroke();
  stroke(0, 0, 0);
  strokeWeight(20);
  line(width/2, 0, width/2, height);
  line(0, height/2, width, height/2);
  PFont f;
  f=createFont("MS-PGothic", 50, true);
  textFont(f, 30);
  fill(0, 0, 50);
  textAlign(CENTER);
  text("From My Window", width/2, height-50);
}

PVector理解するときに作ったスケッチを改造した。窓枠付けるのちょっと面白い。新幹線乗ってるときにこんなのいいなぁと思ってたので嬉しい。これであとはクリックしたところから流れるようにできると完成。どうしよう。
PVectorの使い方ちゃんとまとめてなかったから今度ちゃんとまとめよう。

年賀状まだかけてません(´・ω・`)