/** * 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 fluid 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 = 6; int xdim = 100; int ydim = 100; int offset = 40; int last_x=80; int last_y=80; int last_mx; int last_my; int off = -2; int right,up,down,left; boolean test; int randswitch=1; Color[] particle = new Color[6]; int colcount; int count = 0; byte[][][] lattice = new byte[ydim][xdim][6]; byte[][][] storelattice = new byte[ydim][xdim][6]; // scatter cases byte[][][] scatter = {{{0,0,1,0,0,1}, {1,0,0,1,0,0}, {0,1,0,0,1,0}}, {{1,0,0,1,0,0}, {0,0,1,0,0,1}, {0,1,0,0,1,0}}, {{0,1,0,0,1,0}, {1,0,0,1,0,0}, {0,0,1,0,0,1}}}; // lookup table collision byte[][][] table = {{{0,0,0,0,0,0},{0,0,0,0,0,0}}, {{0,0,0,0,0,1},{0,0,1,0,0,0}}, {{0,0,0,0,1,0},{0,1,0,0,0,0}}, {{0,0,0,0,1,1},{0,1,1,0,0,0}}, {{0,0,0,1,0,0},{1,0,0,0,0,0}}, {{0,0,0,1,0,1},{1,0,1,0,0,0}}, {{0,0,0,1,1,0},{1,1,0,0,0,0}}, {{0,0,0,1,1,1},{1,1,1,0,0,0}}, {{0,0,1,0,0,0},{0,0,0,0,0,1}}, {{0,0,1,0,0,1},{1,0,0,1,0,0}}, {{0,0,1,0,1,0},{0,1,0,0,0,1}}, {{0,0,1,0,1,1},{0,1,1,0,0,1}}, {{0,0,1,1,0,0},{1,0,0,0,0,1}}, {{0,0,1,1,0,1},{1,0,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, {{1,1,0,0,0,1},{0,0,1,1,1,0}}, {{1,1,0,0,1,0},{0,1,0,1,1,0}}, {{1,1,0,0,1,1},{0,1,1,1,1,0}}, {{1,1,0,1,0,0},{1,0,0,1,1,0}}, {{1,1,0,1,0,1},{1,0,1,1,1,0}}, {{1,1,0,1,1,0},{1,1,0,1,1,0}}, {{1,1,0,1,1,1},{1,1,1,1,1,0}}, {{1,1,1,0,0,0},{0,0,0,1,1,1}}, {{1,1,1,0,0,1},{0,0,1,1,1,1}}, {{1,1,1,0,1,0},{0,1,0,1,1,1}}, {{1,1,1,0,1,1},{0,1,1,1,1,1}}, {{1,1,1,1,0,0},{1,0,0,1,1,1}}, {{1,1,1,1,0,1},{1,0,1,1,1,1}}, {{1,1,1,1,1,0},{1,1,0,1,1,1}}, {{1,1,1,1,1,1},{1,1,1,1,1,1}}}; public fluid () { } // 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<6;i++) { particle[i] = new Color(0.3f+((float)(i/14.0f)),0f,0f) ; } for(int j=0;j=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; } } } int countsh = 0; int alt =0; //set full lattice for a square for(int j=offset;j400)&&(last_mx<410)&&(last_my>300)&&(last_my<310)) { //clear = true; } } }); // event model 1.1 mouse listener this.addMouseMotionListener(new MouseMotionAdapter() { public void mouseMoved(MouseEvent e) { int x = e.getX(), y = e.getY(); if ((x>50)&&(x<((xdim-1)*4)+50)&&(y>50)&&(y<((ydim-1)*4)+50)){ //last_x = Math.min(x,800); //last_y = Math.min(y,600); //dt = (x-99)/100.0f; 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+size,centy+size); case 1: bufferGraphics.drawLine(centx,centy,centx-size,centy+size); case 2: bufferGraphics.drawLine(centx,centy,centx-size,centy); case 3: bufferGraphics.drawLine(centx,centy,centx-size,centy-size); case 4: bufferGraphics.drawLine(centx,centy,centx+size,centy-size); case 5: 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) { fluid applet = new fluid(); 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 ); } }