/*	grid1.java  adaptive gridworks*/import java.awt.*;import java.applet.Applet;import java.util.Date;import java.awt.event.*;import java.awt.geom.*;import java.lang.Math.*;import java.lang.StringBuffer;import dataSpace;import Randomizer;public class grid1 extends Applet 			implements MouseListener, MouseMotionListener, Runnable { public static grid1 instance;	//for mouse dragging:boolean moving = false;int mousedown;int mouseup;	//for double buffering:Dimension size;Image buffer;Graphics bufferGraphics;Thread animator;boolean please_stop;	//randomizer with time-based seed:Date time = new Date();long seed = time.getTime();Randomizer r = new Randomizer(seed);	//global colors:int co = 0;Color c3 = new Color(235, 240, 230);Color c4 = new Color(168, 168, 139);		Color grey = new Color(196, 196, 196);Color white = new Color(255, 255, 255);Color lime = new Color(209, 245, 99);	Color red = new Color(80, 10, 10);Color block = new Color(117, 117, 95);Color band = new Color(246, 246, 204);Color bound = new Color(101, 101, 75);Color black = new Color(10, 10, 10);Color light = new Color(240, 240, 240);	//kram style text display:String global;String upper;int reveal_index = 0;boolean do_kram = true;char[] display_chars;char[] temp_char = new char[1];char[] char_sequence = {'#', '%', '$', '@'};boolean letter_sequence = false;int char_index = 0;	//pause for runtime:int pause_factor = 15;int special_clock = 0;	//the dataSpace grid:dataSpace grid;	//file reading - as a stream?		public void init() {		instance = this;		size = this.size();		buffer = this.createImage(size.width, size.height);		bufferGraphics = buffer.getGraphics();						addMouseListener(this);		addMouseMotionListener(this);					letter_sequence = false;				global = new String("adaptive applet 003: modeling input behavior for reactive surface");		upper = new String(global.toUpperCase());		int global_size = global.length();		display_chars = new char[global_size];		display_chars = upper.toCharArray();				grid = new dataSpace();			}				public void paint(Graphics g)  {				//draw background		this.setBackground(c4);		bufferGraphics.setColor(this.getBackground());		bufferGraphics.fillRect(0, 0, size.width, size.height);				//draw grid		bufferGraphics.setColor(band);		bufferGraphics.fillRect(0, 0, 180, 200);				//checkerboard based on dataspace:		bufferGraphics.setColor(red);		int width = grid.grid_width;		int height = grid.grid_height;		for (int i=0; i<width-1; i++) {			for(int j=0; j<height-1; j++) {				//see if box should be drawn, and then draw it:				if (grid.drawBox(i, j)) {					int x = grid.grid_x[i];					int y = grid.grid_y[j];					int delta_x = grid.grid_x[i+1] - x;					int delta_y = grid.grid_y[j+1] - y;					bufferGraphics.fillRect(x, y, delta_x+1, delta_y+1);				}			}		}				//draw the iteration number:		String tally = new String("// " +String.valueOf(reveal_index) );		int tally_size = tally.length();		bufferGraphics.setColor(black);		bufferGraphics.fillRect(180, 176, tally_size*6+4, 14);		bufferGraphics.setColor(white);		bufferGraphics.drawString(tally, 182, 188);				//draw the large rectangle:			int rect_width = (int)(reveal_index*5.8);		bufferGraphics.setColor(black);		bufferGraphics.fillRect(180, 40, rect_width, 14);		//draw the existing text:			bufferGraphics.setColor(white);		String vis = new String(display_chars, 0, reveal_index);		bufferGraphics.drawString(vis, 182, 52);				//draw the individual next rectangle:		if(letter_sequence){			bufferGraphics.setColor(black);			bufferGraphics.fillRect(180+rect_width, 40, 9, 14);			bufferGraphics.setColor(white);			bufferGraphics.drawChars(char_sequence, char_index, 1, 180+rect_width, 52);		}		else{			bufferGraphics.setColor(black);			bufferGraphics.fillRect(180+rect_width, 40, 9, 14);			bufferGraphics.setColor(white);			bufferGraphics.drawChars(temp_char, 0, 1, 180+rect_width, 52);		}											g.drawImage(buffer, 0, 0, this);	}		//rectangle increases in size	//text is written over the rectangle	//for each new letter, there is a series of chars before the final letter	//boundaries of the rectangle to determine size limits	//maybe load a background image		public void KramText() {		if (do_kram) {			reveal_index = 0;			int global_size = global.length();						String upper = new String(global.toUpperCase());			for (int i=1; i<global_size; i++) {				//allow grid manipulation				if (expanding) grid.handle_hit(x_hit, y_hit);							upper.getChars(i, i+1, temp_char, 0);								letter_sequence = true;				char_index++;				if(char_index>3) char_index = 0;				repaint();				try { Thread.sleep(40); } catch (InterruptedException e) { ; }								letter_sequence = false;				repaint();				try { Thread.sleep(30); } catch (InterruptedException e) { ; }				reveal_index++;								}			do_kram = false;	 		}	}		public void update(Graphics g) { paint(g); }			//method for runnable:	public void run()  {		while(!please_stop) {			KramText();							if (expanding) { 				grid.handle_hit(x_hit, y_hit);			}			else {				grid.decayGrid();				repaint();				try { Thread.sleep(30); } catch (InterruptedException e) { ; }			}						try { Thread.sleep(20); } catch (InterruptedException e) { ; }			repaint();		}		animator = null;	}			public void start()  {		if (animator == null)  {			please_stop = false;			animator = new Thread(this);			animator.start();		}	}		public void stop() { please_stop = true; }  		// will he notice this - yes		public void keyDown(Event event) {		if (event.key == event.ENTER) grid.transform_model = 1;		System.out.println("transformation model: " + grid.transform_model);	}					boolean expanding = false;	int x_hit;	int y_hit;		public void mousePressed(MouseEvent event) {		x_hit = event.getX();		y_hit = event.getY();		expanding = true;	}		public void mouseReleased(MouseEvent event) {		expanding = false;	}			public void mouseClicked(MouseEvent event) {}	public void mouseEntered(MouseEvent event) {}	public void mouseExited(MouseEvent event) {}	public void mouseMoved(MouseEvent event) {}	public void mouseDragged(MouseEvent event) {}			}