import java.util.*; import java.awt.*; import java.applet.Applet; public class PottsGibbs extends Applet implements Runnable { int frameNumber = -1; int delay; Thread animatorThread; boolean frozen = false; Color[] color; Random rng = new Random(); int squareWidth = 1; int m; int n; int[][] graph; double beta; public String getAppletInfo() { String info = "PottsGibbs, Version 0.0\n" + "Author: Charles Geyer (charlie@stat.umn.edu)\n" + " some code derived from the Java Tutorial and\n" + " Copyright 1995, 1996 by Sun Microsystems\n" + " other code derived from Java in a Nutshell and\n" + " Copyright 1996 by O'Reilly & Associates\n" + " the rest is public domain"; return info; } public String[][] getParameterInfo() { String[][] info = { // Parameter Name Type or Range Description {"fps", "integer", "frames per second"}, {"ncolor", "integer", "number of colors"}, {"color1", "hexadecimal integer", "1st color"}, {"colorn", "hexadecimal integer", "n-th color"}, {"squareWidth", "integer", "number of browser pixels per side of Potts model pixel"} }; return info; } protected Color getColorParameter(String name) { String value = getParameter(name); int intvalue = -1; try { intvalue = Integer.parseInt(value, 16); } catch (NumberFormatException e) {} if (intvalue == -1) { return new Color(rng.nextFloat(), rng.nextFloat(), rng.nextFloat()); } else { return new Color(intvalue); } } public void init() { String str; int fps = 10; int ncolor = 0; //How many milliseconds between frames? str = getParameter("fps"); try { if (str != null) { fps = Integer.parseInt(str); } } catch (NumberFormatException e) {} delay = (fps > 0) ? (1000 / fps) : 100; //Number of colors? str = getParameter("ncolor"); try { if (str != null) { ncolor = Integer.parseInt(str); } } catch (NumberFormatException e) {} //Number of pixels per pixel? str = getParameter("squareWidth"); try { if (str != null) { squareWidth = Integer.parseInt(str); } } catch (NumberFormatException e) {} //Default: two colors, black and white. if (ncolor <= 0) { ncolor = 2; color = new Color[2]; color[0] = Color.black; color[1] = Color.white; } else { color = new Color[ncolor]; for (int i=0; i= 0) neighborColor[graph[i-1][j]]++; if (i + 1 < m) neighborColor[graph[i+1][j]]++; if (j - 1 >= 0) neighborColor[graph[i][j-1]]++; if (j + 1 < n) neighborColor[graph[i][j+1]]++; double[] probs; probs = new double[color.length]; double sumprobs = 0.0; for (int k=0; k= 0) System.out.println("-/ neighbor color : " + graph[i-1][j]); if (i + 1 < m) System.out.println("+/ neighbor color : " + graph[i+1][j]); if (j - 1 >= 0) System.out.println(" /- neighbor color : " + graph[i][j-1]); if (j + 1 < n) System.out.println(" /+ neighbor color : " + graph[i][j+1]); for (int l=0; l