こんにちは!たやち(tayati_369)です。
輝る虫たちの群れを作った!淡い青の光が好み。。。
import gifAnimation.*; GifMaker gifExport; int r,g,b; int PARTICLE_NUM = 50; float PARTICLE_RADIOUS =2.5; float PARTICLE_MAX_SPEED = 10.0; float PARTICLE_MAX_ACCELERATION = 0.6; float PARTICLE_IMPACT_SPEED = 300; float PARTICLE_SPEED_VARIANT = 0.1; String filename= nf(year(), 2) + nf(month(), 2) + nf(day(), 2) +"-"+ nf(hour(), 2) + nf(minute(), 2) + nf(second(), 2); Particle[] particles; void setup(){ size(600,600); blendMode(ADD); imageMode(CENTER); frameRate(50); gifExport = new GifMaker(this, filename+=".gif"); gifExport.setRepeat(0); // エンドレス再生 gifExport.setQuality(10); gifExport.setDelay(20); particles = new Particle[PARTICLE_NUM]; for(int i =0; i particles[i] = new Particle(); } } void draw(){ background(0); for(Particle particle: particles){ particle.display(); particle.update(); } if(frameCount <= 50*3){ gifExport.addFrame(); // フレームを追加 } else { gifExport.finish(); // 終了してファイル保存 } } class Particle{ PVector position; PVector velocity; Particle(){ //初期発生地のランダムな場所を設定 position = new PVector(random(width), random(height)); setRandomVelocity(); } void setRandomVelocity(){ //速度の定義(ランダム)を設定 velocity = new PVector(random(10)-1.0,random(10)-1.0); velocity.normalize(); velocity.mult(random(PARTICLE_MAX_SPEED*2)-PARTICLE_MAX_SPEED); } void impact(){ velocity = PVector.random2D(); velocity.normalize(); velocity.mult(PARTICLE_IMPACT_SPEED); } void display(){ float dist = sq(random(20)); dist /= 25.0; r = constrain(int(80/dist), 0, 255); g = constrain(int(80/dist), 0, 255); b = constrain(int(200/dist), 0, 255); fill(r, g, b); stroke(r, g, b); ellipse(position.x,position.y,PARTICLE_RADIOUS*2, PARTICLE_RADIOUS*2); } void update(){ //中心に集める PVector mouse = new PVector(width/2, height/2); //subメソッドでベクトルの引き算 PVector direction = PVector.sub(mouse, position); //方向ベクトルの正規化 direction.normalize(); //正規化した方向ベクトルに加速度をスカラー倍しておく。 PVector acceleration = PVector.mult(direction, PARTICLE_MAX_ACCELERATION); //速度に加速度を加算する velocity.add(acceleration); //速度変更 PVector velocityVariant = new PVector(random(10)-1.0, random(10)-1.0); //正規化 velocityVariant.normalize(); velocityVariant.mult(PARTICLE_SPEED_VARIANT); //速度に加算して、速度を変える velocity.add(velocityVariant); velocity.limit(PARTICLE_MAX_SPEED); position.add(velocity); } }
最後に
これ使っていろいろためしてみたいな。
自分のイマジネーション力がなくて笑う。ww
ではでは、さようなら〜〜〜。
コメント