/* * Coupled Map Lattices 4-Neighbor * Por Rogerio Neves * LSI- USP */ import java.awt.*; import java.awt.Graphics; import java.awt.Color; import java.applet.Applet; import java.util.Random; public class cml extends Applet implements Runnable { Random rnd = new Random(); Thread tread; int i, j, cont=1, Xsize=100, Ysize=100, step=8, delay=10, gap=1, phase=1; double[][] M,N; double E=.3, mu=3.5; char map='h'; boolean flag = true; public void init() { String par; // Get Parameters par = getParameter("xsize"); if (par!=null) Xsize = Integer.parseInt(par); par = getParameter("ysize"); if (par!=null) Ysize = Integer.parseInt(par); par = getParameter("coupling"); if (par!=null) E = Double.valueOf(par).doubleValue(); par = getParameter("mu"); if (par!=null) mu = Double.valueOf(par).doubleValue(); par = getParameter("step"); if (par!=null) step = Integer.parseInt(par); par = getParameter("phase"); if (par!=null) cont = Integer.parseInt(par); par = getParameter("delay"); if (par!=null) delay = Integer.parseInt(par); par = getParameter("palette"); if (par!=null) map = par.toLowerCase().charAt(0); par = getParameter("gap"); if (par!=null) gap = Integer.parseInt(par); M = new double [Xsize+2][Ysize+2]; N = new double [Xsize+2][Ysize+2]; for(i=0;istep) { cont=1; flag=true; repaint(); while (flag) { try { me.sleep(delay); } catch (InterruptedException e) { } } } } } public void paint(Graphics g) { if (flag) { setBackground(Color.black); int w = (getSize().width)/Xsize; int h = (getSize().height)/Ysize; for(i=0;i<=Xsize+1;i++) for(j=0;j<=Ysize+1;j++) { if (map=='g') g.setColor(Color.getHSBColor((float)1,(float)0,(float)M[i][j])); else if (map=='h') g.setColor(Color.getHSBColor((float)(.65+.59*M[i][j]),(float)1,(float)(.5+.5*M[i][j]))); else if (map=='c') g.setColor(Color.getHSBColor((float)(M[i][j]),(float)1,(float)1)); else if (map=='b') { float c=0; if (M[i][j]>.5) c=1; g.setColor(Color.getHSBColor((float)1,(float)0,c)); } g.fillRect(gap+i*w,gap+j*h,w-gap,h-gap); } flag = false; } } public void update(Graphics g) { paint(g); } public String getAppletInfo() { return "Logistic Map for\nTime-series\nBy Rogério Neves."; } public String[][] getParameterInfo() { String[][] info = { {"xsize", "integer number", "The cell matrix x size in pixels."}, {"ysize", "integer number", "The cell matrix y size in pixels."}, {"coupling", "double between 0 and 1", "The 4-neighbour coupling constant."}, {"mu", "double between 0 and 1", "The cell time-series parameter."}, {"step", "integer greater than 0", "The Nth. interaction to show, 1=show every frame"}, {"delay", "integer greater than 0", "The frame sleep time in microseconds"}, {"palette", "string", "The color oscheme to use (binary, gray, color, hot)."}, {"gap", "string", "The gap between cells."} }; return info; } }