//Chloe Chao //Highlight consonantal occurrences with different //colors according to family //Color key //stops = p, b, t, d, k, g, q = red //fricatives = f, v, th, s, z, sh, h = light blue //affricate = ch, j = dark blue //nasals = m, n, ng = light green //liquids = l, r = bluish green //glides = y, w, wh = dark green import java.applet.*; import java.awt.*; import java.awt.image.*; import java.net.*; import java.util.*; import java.io.*; public class PLinguist extends Applet implements Runnable { public void init() { UNIT = 4; LEFT_MARGIN = 6; TOP_MARGIN = 30; alphabet = new Vector(); toBeCoded = new String(); noiseFactor = 0; Panel p = new Panel(); p.setLayout(new GridLayout(0,4)); //Create the URL textfield and place in view. makeUrlField(); p.add("West", urlField); //Create the Choice and place in view. makeChoice(); p.add("Center", choice); //Create the numberfield and place in view. makeNumField(); p.add("Center", numField); //Create the button and place in view. makeButton(); p.add("East", button); // Use BorderLayout. BorderLayout b = new BorderLayout(); setLayout(b); add( "North", p ); //Create the display Image and place in view. makeImageCanvas(); add( "South", imageCanvas ); displayImage = createImage(size().width,size().height); bgImage = createImage(size().width,size().height); offg = displayImage.getGraphics(); offg.setColor( Color.black ); imageCanvas.setImage(displayImage); imageCanvas.repaint(); //Read in the homemade font file. fetch("http://acg.media.mit.edu/mas962/users/cchao/ps7/colorfontcode.txt"); //fetch("file://C|/fontcode.txt"); // Start the applet thread. thread = new Thread( this ); thread.start(); } public void start() { if (thread != null) { thread.resume(); } } public void stop() { if (thread != null) { thread.suspend(); } } public void destroy() { if(thread != null) { thread.stop(); } } public void run() { try { while( true ) { coded( noiseFactor-(theta), toBeCoded.toUpperCase() ); repaint(); if( INC ) theta+=(noiseFactor*0.1); else theta-=(noiseFactor*0.1); if( theta>=noiseFactor && INC) { INC = false; theta = noiseFactor; thread.sleep(5*sleepRate); } else if( theta<=0 && !INC ) { INC = true; theta = 0.0; thread.sleep(2*sleepRate); } else thread.sleep(sleepRate); } } catch (InterruptedException e) {} } public void update(Graphics g) { paint(g); } public void paint (Graphics g) { paintComponents(g); imageCanvas.setImage(displayImage); imageCanvas.repaint(); //displayImage = bgImage; // offg = displayImage.getGraphics(); g.drawImage(displayImage, 0, 0, this); } public boolean action(Event e, Object arg) { if (e.target == button) { toBeCoded = urlField.getText(); Double tempDouble; if (numField.getText() != null) tempDouble = new Double(numField.getText()); else tempDouble = new Double(0.0); noiseFactor = tempDouble.doubleValue(); if( noiseFactor!=0 && noiseFactor!=1.0 ) noiseFactor = 1.0-tempDouble.doubleValue(); if( noiseFactor==1.0 ) noiseFactor=.05; offg = displayImage.getGraphics(); coded( noiseFactor, toBeCoded.toUpperCase() ); //This guarantees uppercase. //bgImage = duplicateImage( displayImage ); return true; } return false; } public Image duplicateImage( Image orig ) { int iw = orig.getWidth(this); int ih = orig.getHeight(this); int pixels[] = new int[iw*ih]; PixelGrabber pg = new PixelGrabber( orig, 0, 0, iw, ih, pixels, 0, iw ); try { pg.grabPixels(); } catch( InterruptedException e ){} // Duplicate the image //int sourcePixels[] = pixels; Image dup = createImage( new MemoryImageSource(iw, ih, pixels, 0, iw)); return dup; } public void coded( double noise, String codeme ) { CodeString cs = null; // crazySerifs.removeAllElements(); //System.out.println("decoding: "+noise); if (noise < 0.0) noise = 0.0; else if (noise > 1.0) noise = 1.0; //Reset drawing coordinates to upper-left and clear screen int currx, curry; currx = LEFT_MARGIN; curry = TOP_MARGIN; offg.setColor(Color.white); offg.fillRect( 0, 0, this.size().width, this.size().height); //StringBuffer sb = new StringBuffer(); for( int i=0; i(size().width-(12*UNIT)) ) { currx = LEFT_MARGIN; curry+=(12*UNIT); } }//end for each letter }// end coded() public Image blurImage(double bf, CodeString cs1, int gx, int gy) { int dim = UNIT*12; Image i2 = cs1.getImage(); Graphics g2 = i2.getGraphics(); g2.setColor( Color.white ); g2.fillRect( 0, 0, 2*dim, dim ); if( bf<=0.5 ) g2.setColor( new Color( (float)(1.0-theta), (float)(1.0-theta), (float)(1.0-theta) ) ); else g2.setColor( Color.black ); for( int i=0; i 50 ) { this.scale = 0; this.time = 0; } if( this.angle < 360 ) this.angle+=10; else this.angle = 0; double radians = angle*Math.PI/180.0; for( int k=0; k