import java.applet.*; import java.awt.*; import java.awt.image.*; import java.awt.event.*; import java.io.*; import java.net.*; import java.text.*; import java.util.*; import java.util.zip.*; public class sur3 extends BApplet {//                         //                              //                                                        //                                                //                                                        //                                                                //                           float p0x[]= {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};float p0y[]= {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};float p1x[]= {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};float p1y[]= {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};float p2x[]= {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};float p2y[]= {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};float p3x[]= {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};float p3y[]= {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};//                               float rotation[]= {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};float fixed[] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};int light[] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};int hits[] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};float mobility[] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};//                            float grid_x[] = {0, 20, 40, 60, 80};float grid_y[] = {0, 20, 40, 60, 80}; float area[] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};//                int random;int elapsed_time;int trans = 32;int average_hits = 0;//                                  //                                             //                                                                //                                                //                                                       //                      int day_scale = 10;void lightGrid() {   push();  translate(40, 200, 0);  //                                                  for (int i=0; i<16; i++) {    int column = i%4  ;   //                                   int row = 3-(i/4);    //                                   noStroke();    fill(140+light[i]*20);    //                                                   rect(grid_x[column], grid_y[row], grid_x[column+1]-grid_x[column],grid_y[row+1]-grid_y[row]);    area[i] = (grid_x[column+1]-grid_x[column]) * (grid_y[row+1]-grid_y[row]);	//                                                    	if ((hour<7) || (hour>19)) day_scale = 11;	else day_scale = 7;	fixed[i] = light[i]*day_scale;  }  pop();}//                                                             void setMobility() {	for (int i=0; i<16; i++) {		average_hits += hits[i];	}	average_hits /= 16;	for (int j=0; j<16; j++) {		mobility[j] = hits[j]/(average_hits+0.001f);		}}float hour = 0;int scaled_time = 0;void barClock() {	scaled_time = elapsed_time/20;	hour = scaled_time%24;	push();	translate(40, 300, 0);	fill(80);	rect(0,0,80,10);	fill(180, 150, 30);	rect(0,0,(hour*80/24), 10);	pop();}	void setRotation() {	for (int i=0; i<16; i++) {		//                                  		rotation[i] += (area[i]-400)/60;		//                                              		//                           				if (rotation[i]<fixed[i]) {			rotation[i] += (fixed[i]-rotation[i])/(20-mobility[i]);		}		else rotation[i] -= (rotation[i]-fixed[i])/(20-mobility[i]);		if (rotation[i]>70) rotation[i] = 70;		else if (rotation[i]<-70) rotation[i] = -70;			}}//                                                   void handleHit(int x, int y) {  for (int i=0; i<4; i++) {    if ((x<grid_x[i+1]) && (x>grid_x[i])) {        int column = i;        for (int j=0; j<4; j++) {          int row = 3-j;          int next = 4-j;          if ( (y>grid_y[row]) && (y<grid_y[next]) ) {            int val = (j*4)+i;            //                                                                light[val] += 1;		    hits[val] += 1;            transformGrid(i,j);            if (light[val] > 5) light[val] = -5;          }        }     }  }	setMobility();}void transformGrid(int c, int r) {  int selection = (r*4)+c;  //                                  int delta = light[selection];  grid_x[c] -= delta;  if (grid_x[c]<0) grid_x[c] = 0;  grid_x[c+1] += delta;  if (grid_x[c+1]>80) grid_x[c+1] = 80;  grid_y[c] -= delta;  if (grid_y[c]<0) grid_y[c] = 0;  grid_y[c+1] += delta;  if (grid_y[c+1]>80) grid_y[c+1] = 80;}//                     void decayGrid() {  for (int i=0; i<5; i++) {    float deltaX = grid_x[i] - i*20;    float moveX = (deltaX+1)/15;    grid_x[i] -= moveX;  }  for (int j=0; j<5; j++) {    float deltaY = grid_y[j] - j*20;    float moveY = (deltaY+1)/15;    grid_y[j] -= moveY;  }}  //                                                         void setup() {  	size(440, 360);	elapsed_time = 1;	makePanels();}void loop() {	background(90, 85, 95);    lightGrid();	barClock();	push();	if (mousePressed) {		handleHit(mouseX-40, mouseY-200);	}    else decayGrid();	elevation2();	setRotation();	drawPanels();	pop();	elapsed_time++;}//            void elevation2() {        translate(320-(mouseX/10), 160, -140);	rotateX( (280-mouseY)/3000.0f+  (PI/2));	rotateZ(PI/2.8f-(390/600.0f));	rotateY(-0.5f + 95/400.0f);  }//                void makePanels() {	for (int i=0; i<16; i++) {		float random1 = random(6);		float random2 = random(8);		float random3 = random(10);		float random4 = random(3.5f);			p0x[i] = 0+random1 -trans;		p0y[i] = 88+random2;		p1x[i] = 15+random3 -trans;		p1y[i] = 0+random1;		p2x[i] = 40+random2 -trans;		p2y[i] = 68+random3;		p3x[i] = 48+random1 -trans;		p3y[i] = 0+random3;		//                                     delay(7);	}}void drawRoom() {	push();	noStroke();	fill(96);	translate(0, 0, 24);	rect(10,0,150,360);	pop();	push();	translate(0, 0, -90);	rect(10,0,150,390);	pop();}void updatePanelPosition() {}void drawPanels() {	push();	drawRoom();	stroke(100);	fill(10, 40, 30);	for (int i=0; i<16; i++) {		push();		int row = i/4;		int column = i%4;				translate(42*column, 94*row, 0);		//                     		rotateY(rotation[i]*PI/180);				beginShape(TRIANGLE_STRIP);			vertex(p0x[i], p0y[i], 0);		vertex(p1x[i], p1y[i], 0);		vertex(p2x[i], p2y[i], 0);		vertex(p3x[i], p3y[i], 0);		endShape();		pop();	}	pop();}}