【Processing】背景処理をしない

f:id:osushi_94:20180217023653p:plain

 

パーティクルを使って、こういうことをしてみた。

部分的に背景処理をあえてやめてみたらどうなるか、、、と思ったけど結果が微妙だったので、いろんなこと試して、設定をブン曲げてこういう投稿に。

 

int NUM = 300;
PVector[] p = new PVector[NUM];   //点p
PVector[] force = new PVector[NUM];     //かかる力
PVector[] acceleration = new PVector[NUM]; //加速度
PVector[] velocity = new PVector[NUM]; //速度
PVector[] gravity = new PVector[NUM]; //重力
PVector[] min = new PVector[NUM];   //最小値
PVector[] max = new PVector[NUM];   //最大値
float[] mass = new float[NUM];    //質量
float friction; //摩擦


void setup() {
  size(200,800); //ウィンドウサイズは500x500
  background(255);
  smooth();      //描画を滑らかに
  
  for(int i = 0 ; i < NUM;i++){
   p[i] = new PVector(width/2,100);     //点Pの初期値
   velocity[i] = new PVector(random(-5,5),random(-10));      //速度初期値
   force[i] = new PVector(random(-1,1),random(-5,5));     //かかる力
   min[i] = new PVector(0.0,0.0);       //左の壁の設定
   max[i] = new PVector(width,height);  //右の壁の設定
   gravity[i] = new PVector(0.0,random(1,1.5));   //重力の設定
   mass[i] = random(0.8);                       //質量の設定
   friction = 0.01;                  //摩擦の設定
   acceleration[i] = force[i].mult(mass[i]*5);  //かかる力と質量からを加速度を算出
  }
}


void draw() {
              
 noStroke();
  for(int i = 0 ; i < NUM;i++){
 acceleration[i].add(gravity[i]);       //加速度に重力を加えて算出
 velocity[i].add(acceleration[i]);      //速度に加速度を加える
 velocity[i].mult(1.0-friction);     //摩擦をかける
 p[i].add(velocity[i]);                 //点Pに速度を加える
 acceleration[i].set(0,0);           //加速度をリセットする

 fill(30,30);                         //点Pの色
 ellipse(p[i].x,p[i].y,mass[i]*10,mass[i]*10);//点Pをかく
 
 //横の跳ね返りの処理ーーーーーーーーーー
 if( p[i].x < min[i].x){
   p[i].x = min[i].x + p[i].x; //一旦最小にして反対方向へ
   velocity[i].x *= -1;
 }
  if(p[i].x > max[i].x){
   p[i].x = max[i].x;//一旦最大にして反対方向へ
   velocity[i].x *= -1;
 }
 
 //縦の跳ね返りの処理ーーーーーーーーーー
  if( p[i].y < min[i].y){
   p[i].y = min[i].y + p[i].y; //一旦最小にして反対方向へ
   velocity[i].y *= -1;
 }
   if(p[i].y > max[i].y){
   p[i].y = max[i].y; //一旦最小にして反対方向へ
   velocity[i].y *= -1;
 }
 
  }
}