processingによる可視化
移転しました。
simulation
http://www7b.biglobe.ne.jp/meganii/java/simulation/index.html
今度の授業は、
この前のjavaのモデリングをprocessingというプログラミング言語によって可視化するというもの。
一つ一つの円は、要素の数を表し、円の大きさは、要素の数によって変動する。
中盤から緑の勢力が強いですね(^_^;)
んー、衝突して変化させるにはどうすればいいんだろう?
//global variable int MAX = 200; int [] v ={70,40,30,50,100}; int [][] Rule ={ {-1,1,1,-1,0},{1,-1,-1,1,0},{0,1,1,-1,-1},{1,0,-1,1,-1} }; int [][] x = new int[4][MAX]; int [][] y = new int[4][MAX]; int [][] r = new int[4][MAX]; int[][] xspeed = new int[4][MAX]; int[][] yspeed = new int[4][MAX]; float k1 = 0.3; float k2 = 0.8; float k3 = 0.9; float k4 = 0.9; float Pr; float rlt; void setup(){ size(600,600); colorMode(HSB,100); frameRate(30); noStroke(); smooth(); //setup position for(int i=0;i<4;i++){ for(int j=0;j<MAX;j++){ x[i][j] = int(random(width)); y[i][j] = int(random(height)); r[i][j] = int(random(10,40)); } } } void draw(){ background(0); float r1 = v[0]*v[3]; //docomo*price float r2 = v[1]*v[2]; //softbank*trust float r3 = v[4]*v[3]; //user*price float r4 = v[4]*v[2]; //user*trust //calculation of possibility float Pr1 = (r1/(r1+r2+r3+r4))*k1; float Pr2 = (r2/(r1+r2+r3+r4))*k2; float Pr3 = (r3/(r1+r2+r3+r4))*k3; float Pr4 = (r4/(r1+r2+r3+r4))*k4; //make roulette float rlt = random(0,1); //adopt rules if(rlt<=Pr1){ for(int i=0;i<4;i++){ v[i] += Rule[0][i]; } }else if(rlt<=Pr1+Pr2){ for(int i=0;i<=4;i++){ v[i] += Rule[1][i]; } }else if(rlt<=Pr1+Pr2+Pr3){ for(int i=0;i<=4;i++){ v[i] += Rule[2][i]; } } //draw bubbles & setup of speeds for(int i=0;i<4;i++){ for(int j=0;j<=v[i];j++){ xspeed[i][j] = int(random(-4,4)); yspeed[i][j] = int(random(-4,4)); fill(30+30*i,70,100,60); ellipse(x[i][j],y[i][j],r[i][j]*0.015*v[i],r[i][j]*0.015*v[i]); //rect(x[1][j],y[1][j],r[1][j]*0.015*v[i],r[i][j]*0.015*v[i]); x[i][j] = x[i][j] + xspeed[i][j]; y[i][j] = y[i][j] + yspeed[i][j]; if ((x[i][j] > width) || (x[i][j] < 0)) { xspeed[i][j] = xspeed[i][j] * -1; } if ((y[i][j] > height) || (y[i][j] < 0)) { yspeed[i][j] = yspeed[i][j] * -1; } } } }