煙のプログラム
煙のようなものを表示させるプログラムをProce55ingで作ってみた。
//constants int WIDTH = 200; int HEIGHT = 200; int SMOKE_X = WIDTH/2; int SMOKE_Y = HEIGHT-100; int SMOKE_NUM = 2; //Object Smoke[] smoke; ///////////SETUP//////////// void setup(){ size(WIDTH,HEIGHT); background(0); colorMode(HSB); smooth(); smoke = new Smoke[SMOKE_NUM]; for(int i=0;i<SMOKE_NUM;i++){ smoke[i] = new Smoke(); } } ///////////DRAW//////////// void draw(){ background(0); for(int i=0;i<SMOKE_NUM;i++){ smoke[i].smokeDraw(); } filter(BLUR,3); } //////////SMOKE//////////// class Smoke{ SmokeParticle[] sParticle; float initialPhase; float dPhase; float c; Smoke(){ initialPhase=random(0,PI); dPhase = TWO_PI-random(0.001,0.2); c = random(10,50); sParticle = new SmokeParticle[SMOKE_Y+1]; for(int i=0;i<SMOKE_Y+1;i++){ sParticle[i] = new SmokeParticle(i,initialPhase,c,dPhase); } } public void smokeDraw(){ for(int i=0;i<SMOKE_Y+1;i++){ if(random(-1,1)>0){ c++; }else{ c--; } sParticle[i].drawParticle(); } } } //////////SMOKE PARTICLE/////////// class SmokeParticle{ float x; int y; float c; float phase; float initialPhase; float dPhase; SmokeParticle(int _y, float _initialPhase,float _c, float _dPhase){ initialPhase = _initialPhase; dPhase = _dPhase; c = _c; y = _y; phase = SMOKE_Y-0.1*y+initialPhase; x = SMOKE_X+c*(1-exp(-0.01*(y)))*sin(phase); } public void drawParticle(){ phase += dPhase; x = SMOKE_X+c*(1-exp(-0.001*(SMOKE_Y-y)))*sin(phase); fill(64); stroke(64); ellipse(x,y,1,1); } }
ほんとはもっと大きくしたいんだけど、大きくするとかなり重い。
>||filter(BLUR,3);|