xxxxxxxxxx
int n=20;
float h = 20.0;
int [][] c = new int[n][n];
float [][] p = new float[n][n];
float [][] pn = new float[n][n];
float [][] pd = new float[n][n];
void setup(){
size(800,800,WEBGL);
colorMode(HSB,360,100,100);
//noFill();
frameRate(40);
for(int i=0; i<n; i++){
for(int j=0; j<n; j++){
c[i][j]=int(random(360));
p[i][j]=int(random(1,n+1));
do{
pn[i][j]=int(random(1,n+1));
} while(pn[i][j]==p[i][j]);
pd[i][j] = -0.1;
if(pn[i][j]>p[i][j]) pd[i][j]=0.1;
}
}
}
void draw(){
background(20);
translate(width/2,height/2);
//float x = map(mouseX,0,width,0,TWO_PI);
//float y = map(mouseY,0,height,0,TWO_PI);
rotateX(PI/4);
rotateZ(PI/200*frameCount);
rotateY(PI/6*sin(PI/250*frameCount));
strokeWeight(1);
stroke(220);
noFill();
box(h*n);
for(int i=0; i<n; i++){
for(int j=0; j<n; j++){
pushMatrix();
translate(h/2-h/2*n+i*h,h/2-h/2*n+j*h,-h/2*n);
//color cl = color(c[i][j],100,100);
quader(p[i][j]*h,h,c[i][j]);
popMatrix();
p[i][j]+=pd[i][j];
if(abs(p[i][j]-pn[i][j])<0.01){
do{
pn[i][j]=int(random(1,n+1));
}while(abs(pn[i][j]-p[i][j])<0.01);
pd[i][j] = -0.1;
if(pn[i][j]>p[i][j]) pd[i][j]=0.1;
}
}
}
}
void quader(float l, float b,color cc){
pushMatrix();
translate(-b/2,-b/2,l);
fill(cc,100,100);
rect(0,0,b,b);
popMatrix();
strokeWeight(1);
stroke(cc,60,30);
noFill();
//fill(cc,30,30,30);
rotateX(PI/2);
for(int i=0; i<4; i++){
pushMatrix();
rotateY(PI/2*i);
//rotateX(PI/2);
translate(-b/2,0,-b/2);
rect(0,0,b,l);
popMatrix();
}
}