/** * string.java * * Title: string - NMM * Description: * @author akilian * @version */ import java.awt.*; import java.awt.event.*; import java.applet.*; import java.lang.Math.*; import java.util.Vector; import java.io.*; import java.net.*; public class squarereally extends java.applet.Applet implements Runnable{ // IMPORTANT: Source code between BEGIN/END comment pair will be regenerated // every time the form is saved. All manual changes will be overwritten. // BEGIN GENERATED CODE // member declarations // END GENERATED CODE boolean isStandalone = false; Dimension size; Image buffer; // The off-screen image for double-buffering Graphics bufferGraphics; // A Graphics object for the buffer Thread animator; // Thread that performs the animation boolean please_stop; float stepper = 0; int timer=0; int maxstepper = 10000; int grid = 4; int xdim = 200; int ydim = 200; int offset = 40; float cellsize = 400.0f/(float)xdim; int last_x=80; int last_y=80; int last_mx; int last_my; float off = cellsize/2.0f; int right,up,down,left; boolean test; int randswitch=1; Color[] particle = new Color[grid]; int colcount; int count = 0; byte[][][] lattice = new byte[ydim][xdim][grid]; byte[][][] storelattice = new byte[ydim][xdim][grid]; // lookup table collision byte[][][] table = {{{0,0,0,0},{0,0,0,0}}, {{0,0,0,1},{0,1,0,0}}, {{0,0,1,0},{1,0,0,0}}, {{0,0,1,1},{1,1,0,0}}, {{0,1,0,0},{0,0,0,1}}, {{0,1,0,1},{1,0,1,0}}, {{0,1,1,0},{1,0,0,1}}, {{0,1,1,1},{1,1,0,1}}, {{1,0,0,0},{0,0,1,0}}, {{1,0,0,1},{0,1,1,0}}, {{1,0,1,0},{0,1,0,1}}, {{1,0,1,1},{1,1,1,0}}, {{1,1,0,0},{0,0,1,1}}, {{1,1,0,1},{0,1,1,1}}, {{1,1,1,0},{1,0,1,1}}, {{1,1,1,1},{1,1,1,1}}}; public squarereally () { } // Retrieve the value of an applet parameter public String getParameter(String key, String def) { return isStandalone ? System.getProperty(key, def) : (getParameter(key) != null ? getParameter(key) : def); } // Get info on the applet parameters public String[][] getParameterInfo() { return null; } // Get applet information public String getAppletInfo() { return "Applet Information"; } // Initialize the applet public void init() { try { initComponents(); } catch (Exception e) { e.printStackTrace(); } // double buffering size = this.size(); buffer = this.createImage(size.width, size.height); bufferGraphics = buffer.getGraphics(); please_stop = false; for(int i=0;i=0.5) lattice[j][i][b]=1; else lattice[j][i][b]=0; //System.out.println(lattice[j][i][0]+" "+lattice[j][i][1]+" "+lattice[j][i][2]+" "+lattice[j][i][3]+" "+lattice[j][i][4]+" "+lattice[j][i][5]+" "+" "+table[b][0][0]+" "+table[b][0][1]+" "+table[b][0][2]+" "+table[b][0][3]+" "+table[b][0][4]+" "+table[b][0][5]+" setlattice"); }*/ if (((Math.random()*1.0)>=0.5)){ count+=1; //lattice[j][i][(int)(Math.random()*5.0)]=1; } } } //set full lattice for a square for(int j=offset;j50)&&(x<((xdim-1)*cellsize)+50)&&(y>50)&&(y<((ydim-1)*cellsize)+50)){ last_x = x-50; last_y = y-50; for(int i=0;i31) { offsetx = (size+2)*8; offsety = -(size+2)*2*32; } int centx = 470+a*(size+2)*2+offsetx; int centy = 50+t*(size+2)*2+offsety; if (table[t][a][b]==1) bufferGraphics.setColor(Color.blue); else bufferGraphics.setColor(Color.white); switch (b) { case 0: bufferGraphics.drawLine(centx,centy,centx,centy+size); case 1: bufferGraphics.drawLine(centx,centy,centx-size,centy); case 2: bufferGraphics.drawLine(centx,centy,centx,centy-size); case 3: bufferGraphics.drawLine(centx,centy,centx+size,centy); } //if (a==0) bufferGraphics.drawString(Integer.toString(t),centx-40,centy); } } } } bufferGraphics.setColor(Color.black); screen.drawImage(buffer, 0, 0, this); } // this one is for updating during runtime Graphics screeng; public void update() { if (screeng == null) screeng = this.getGraphics(); paint(screeng); } public void run() { while(!please_stop) { while (true){ animate(); update(); stepper +=0.1f; //System.out.println(stepper); } } animator = null; } public void start() { if (animator == null) { please_stop = false; animator = new Thread(this); animator.start(); } } // Standard method to stop the applet public void stop() { please_stop = true; } // Standard method to destroy the applet public void destroy() { } // Main entry point when running standalone public static void main(String[] args) { squarereally applet = new squarereally(); applet.isStandalone = true; Frame frame = new Frame(); frame.addWindowListener(new java.awt.event.WindowAdapter() { public void windowClosing(java.awt.event.WindowEvent e) { Frame f = (Frame) e.getSource(); f.setVisible(false); f.dispose(); System.exit(0); } }); frame.setTitle("string"); frame.add( applet, BorderLayout.CENTER ); applet.init(); applet.start(); frame.setSize( 600, 700 ); Dimension d = Toolkit.getDefaultToolkit().getScreenSize(); frame.setLocation( (d.width - frame.getSize().width) / 2, (d.height - frame.getSize().height) / 2); frame.setVisible( true ); } /* private void initComponents() {//GEN-BEGIN:initComponents setLayout(new java.awt.BorderLayout()); }//GEN-END:initComponents // Variables declaration - do not modify//GEN-BEGIN:variables // End of variables declaration//GEN-END:variables */ }