3DCG屋さんの活動記録

PROFILE ★★こんな人です

映像制作会社でクリエイティブの修行中。日ごろはMaya&AEを中心にいろんなCGソフトを触りながら、TD寄りの作業が好きで、インタラクティブな体験型空間演出をやりたいと模索中。面白いこと新しいこと大好きな『素直』でいつづける

2017年2月8日水曜日

Processing OPPとクラスのお勉強3


色をランダム、フルスクリーン。
また、スクリーンサイズ丸の数だけ指定すれば、
丸の位置やサイズは自動で計算されるように改良。

見返さずにゼロから作成。。。なかなか覚えられない!
とにかく書いてテクニカルな障壁は早く解消したい。



以下スケッチ

int spotsNum  = 50;


Spot[] spots = new Spot[spotsNum];

void setup(){
  //size(600,200);
  fullScreen();
  smooth();
  noStroke();
  //配列の数だけパラメーた作成
  for (int i = 0;  i  < spots.length;  i++){
    float x = width/spots.length * i;
    float speed = random(1,5);
    color col = color(random(255),random(255),random(255));
    //インスタンス化
    spots[i] = new Spot( new PVector(x,30),width/spots.length,speed,col);
  }
}

void draw(){
  fill(0,12);
  rect(0,0,width,height);
  for(int i=0; i < spots.length; i++){
    spots[i].move();
    spots[i].display();
  }
}

class Spot{
  PVector pos;
  float  diameter;
  float speed;
  color col;
  int direction = 1; //方向
  //コンストラクタ
  Spot(PVector _pos, float _diameter, float _speed,  color _col){
  pos = _pos;
  diameter = _diameter;
  speed = _speed;
  col  = _col;
  }
  //アニメ
  void move(){
    pos.y += speed * direction;
    if(pos.y < height/spots.length || pos.y > height-height/spots.length){
     direction *= -1;
    }
  }
  //表示
  void display(){
    fill(col);
    ellipse(pos.x, pos.y, diameter, diameter);
  }
}

0 コメント:

コメントを投稿