PVector_curveVertex01

PVector pos;
PVector vel;

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

  pos = new PVector(width/2, 0);
  vel = new PVector(0, 5);
}


void draw() {
 fill(0, 0, 100, 10);
 rect(0, 0, width, height);
  pos.add(vel);

  fill(random(360), 100, 100);

  beginShape();
  curveVertex(pos.x, pos.y);
  curveVertex(random(width), random(height));
  curveVertex(random(width), random(height));
  curveVertex(random(width), random(height));
  curveVertex(random(width), random(height));
  curveVertex(random(width), random(height));
  curveVertex(random(width), random(height));
  curveVertex(pos.x, pos.y);
  endShape();

  bound();
}

void bound() {
  if (pos.y < 0 || pos.y > height) {
    vel.y = - vel.y;
  }
}

想像してものができた.中心のライン移動する点を起点にして図形を描き続ける.curveVertexをはじめて使った.あとは,mousePressed();から得た感覚でbound();というのもをつくってみた.いつもと少しちがうことをした.そして,動いたのでよし.それも,15分程度でできたので,さらによし.

array_PVector_ellipse05

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();
  mousePressed();
}

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

  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 > width) {
      vel[i].x= - vel[i].x;
    }
    if (pos[i].y <0 || pos[i].y >height) {
      vel[i].y= - vel[i].y;
    }
  }
}

void mousePressed() {
  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(random(80, 100), i%100, i%100, i%100);
  }
}

メディア芸術祭の内覧会に出席するため東京に出張.実家での作業.移動で疲れたこともあって,昨日のコードの色を変え,Y軸でも跳ね返りをつけて,mousePressedでリセットを設定.ちょっとした修正だけど,修正しただけ,動きに反映されるので面白い.

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にして色をつけてみた.マウスでクリックするともとに戻るようにしたかったけど,夜遅いので次の宿題.

array_PVector_vertex01

int num = 100;

PVector[] pos;
color[] c; 

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

void draw() {
  for (int i = 3; i < num; i ++) {
    fill(c[i]);
    beginShape();
    vertex(pos[i].x, pos[i].y);
    vertex(pos[i-1].x, pos[i-1].y);
    vertex(pos[i-2].x, pos[i-2].y);
    vertex(pos[i].x, pos[i].y);
    endShape();
  }
}

void mousePressed() {
  pos = new PVector[num];
  c = new color[num];
  for (int i = 0; i < num; i ++) {
    pos[i] = new PVector(random(width), random(height));
    c[i] = color(random(360), 80, 80, 30);
  }
  fill(0, 0, 100);
  rect(0, 0, width, height);
}

今日も教科書に戻らず,何も見ないで配列で何か書くをしてみた.ラファエル・ローゼンダールの作品のようなものが20分程度で書けたことに自分の成長を見た気がした.雰囲気で書けて,チャレンジができるようにはなってきた.配列の意味もわかってきたのだと思う.次こそ教科書に戻るといいつつ,時間がないと雰囲気で書くことを選んでしまう.でも,それだとできることしかできないので,あたらしいことが覚えられないのでいけないと思いつつ,雰囲気でちょっと書けるようになってきたり,修正のコツがわかってくるのは教科書では味わえない感じなので,それはそれでいい.

array_PVector_points01

int num = 10000;

PVector[] pos;
PVector[] vel;

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

  pos = new PVector[num];
  vel = new PVector[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));
  }
}

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]);
    point(pos[i].x, pos[i].y);

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

配列で初心に変えるつもりでpointのスケッチを書いてみた.はじめて,何も参考せずに配列のスケッチを書けた.次の目標を決めるために,明日から教科書に戻ろう.と,同じことを昨日も書いた気がする.

array_PVector_elipse03

int num = 100;

PVector[] pos;
PVector[] vel;
color[] c;
void setup() {
  size(500, 500);
  colorMode(HSB, 360, 100, 100, 100);
  smooth();
  //noStroke();
  background(0, 0, 100);

  pos = new PVector[num];
  vel = new  PVector[num];
  c = new color[num];
  
  for (int i = 0; i < num; i ++) {
    pos[i] = new PVector(width/2, 10*i);
    vel[i] = new PVector(1, 0);
    c[i] = color(random(360), 100, 100);
  }
}

void draw() {

  int d = 1;

  for (int i = 0; i < num; i ++) {
    pos[i].add(vel[i]);

    if (i%2 == 0) {
      vel[i].x = d;
    } else {
      vel[i].x = -d;
    }
    stroke(c[i]);
    ellipse(pos[i].x, pos[i].y, width/num, height/num);
    
    pos[i].y += 0.001;

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

最初に狙っていた違い近いに逆方向に円を移動させるところまではできた.だけど,両端で跳ね返ってくるところができなかった.もうそろそろ教科書に戻ろう.

PVector_ellipse05

int num = 500;

PVector[]  pos;
PVector[] vel;

color[]  c;

int d = 50;

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

  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));
    c[i] = color(random(360), 80, 80, 50);
  }
}

void draw() {

  noStroke();
  fill(0, 0, 100, 10);
  rect(0, 0, width, height);

  for (int i =0; i <num; i ++) {  
    float r;
    r = radians(frameCount);
    vel[i] = new PVector(cos(r), sin(r));

    pos[i].add(vel[i]);

    stroke(c[i]);
    ellipse(pos[i].x, pos[i] .y, d, d);

    r += r +1;
  }
}

授業準備をはじめるつもりが,なぜかProcessingをしてしまった.配列の復習.何も見ないで書いたけど,やはり忘れていたので,最後には前回書いたものをみた.まだまだです.