import java.awt.*; import java.lang.Math; import java.util.Random; public class phasor extends java.applet.Applet implements Runnable { int Nmax = 100; int numcolors = 128; Color colortab[] = new Color[numcolors]; int colorindex[] = new int[Nmax*Nmax]; int sleeptime = 25; // Milliseconds double speed = .1; double scale = 1.; double noise = 0.; double eps = .1; // .01 .001 int elemSize = 5; int width, height; int canvas_width; int canvas_height; int N = 51; int NN=N*N; double phi[] = new double[Nmax*Nmax]; double rhs[] = new double[Nmax*Nmax]; Thread runner; Image offscreenImg; Graphics offscreen; Canvas canvas = new Canvas(); Button initB = new Button("init"); Label Nlabel = new Label( "N", Label.RIGHT ), esizelabel = new Label( "size", Label.RIGHT ), speedlabel = new Label("omega", Label.RIGHT), scalelabel = new Label("scale", Label.RIGHT), noiselabel = new Label("noise", Label.RIGHT), epslabel = new Label("coupling", Label.RIGHT); TextField Ntf = new TextField( Integer.toString( N ) ), esizetf = new TextField( Integer.toString( elemSize ) ), speedtf = new TextField( Double.toString( speed )), scaletf = new TextField( Double.toString( scale )), noisetf = new TextField( Double.toString( noise )), epstf = new TextField( Double.toString( eps ) ); FlowLayout lm = new FlowLayout(FlowLayout.LEFT); // GridLayout lm = new GridLayout(10, 1); public void init() { int i; Random r = new Random(); double v; setLayout(lm ); for (i=0; i= 2*Math.PI) phi[i] -= 2*Math.PI; while (phi[i] < 0) phi[i] += 2*Math.PI; } // compute new colors for (i=0; i=3. && newValue < Nmax) N = (int)newValue; NN = N*N; } numberFormatError = false; try { dval = Double.valueOf(esizetf.getText()); } catch (NumberFormatException e) { numberFormatError = true; } if ( numberFormatError == false) { newValue = dval.doubleValue(); if (newValue >=1. && newValue <= 100.) elemSize = (int)newValue; } numberFormatError = false; try { dval = Double.valueOf(speedtf.getText()); } catch (NumberFormatException e) { numberFormatError = true; } if ( numberFormatError == false) { newValue = dval.doubleValue(); if (newValue >=0 && newValue <= 100) speed = newValue; } numberFormatError = false; try { dval = Double.valueOf(scaletf.getText()); } catch (NumberFormatException e) { numberFormatError = true; } if ( numberFormatError == false) { newValue = dval.doubleValue(); if (newValue >=0 && newValue < (N-1)) scale = newValue; } numberFormatError = false; try { dval = Double.valueOf(noisetf.getText()); } catch (NumberFormatException e) { numberFormatError = true; } if ( numberFormatError == false) { newValue = dval.doubleValue(); if (newValue >=0 && newValue <= 100) noise = newValue; } numberFormatError = false; try { dval = Double.valueOf(epstf.getText()); } catch (NumberFormatException e) { numberFormatError = true; } if ( numberFormatError == false) { newValue = dval.doubleValue(); if (newValue >=0 && newValue <= 100) eps = newValue; } return true; } else if (evt.target instanceof Button) { int i; Random r = new Random(); double v; // initial to random positions and directions for (i=0; i