/**
* codedocII.java
*

*

Assignment:
Connect and move three points
Solutions:
Explore the possibility space of basic 2D graphics

Explore instancing as a method of generating complexity

 
General Parameters:

Size of Applet

 

Number of Columns and rows

  Probabilities for Point Parameters
   
Point Parameters:
Direction of motion ( x, y, x&y)
Color (Black or Red)
Speed of Buffer Refresh
Trails (on or off )
  Speed of point (step size in pixels)
   
Comments:
Even though the visual concept was to answer the assignment by presenting possibility spaces,
the coding turned into an exercise in instancing and how to arrange the creation of new parameter sets.

* ©John F. Simon, Jr. - 7.7.3
* @1.0ß
*/


package menage;
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
import java.util.*;


public class codedocII extends java.applet.Applet implements Runnable
{

boolean done = false;
int speed = 5;
Thread grow;

int appletWidth = 800;
int appletHeight = 600;

int width, height;

Vector thePossibilities = new Vector();

int maxRows = 9;
int maxColumns = 11;
int numRows;
int numColumns;

public void initComponents() throws Exception
{

Integer tNum = new Integer(0);

/****

Allow Outside settings - From the HTML page you can set the applet size, the maximum number of rows and columns, and the starting number of rows and columns. If you nave the machine for it, you can push the max pretty high!

****/


tNum = tNum.valueOf(getParameter("maxRows"));
maxRows = tNum.intValue();
if( (maxRows <= 0 ) ) maxRows = 9;

tNum = tNum.valueOf( getParameter("maxColumns"));
maxColumns = tNum.intValue();
if( (maxColumns <= 0 ) ) maxColumns = 11;

tNum = tNum.valueOf(getParameter("rows"));
numRows = tNum.intValue();
if( (numRows <= 0 ) || (numRows > maxRows ) ) numRows = maxRows;

tNum = tNum.valueOf(getParameter("columns"));
numColumns = tNum.intValue();
if( (numColumns <= 0 ) || (numColumns > maxColumns ) ) numColumns = maxColumns;

tNum = tNum.valueOf(getParameter("height"));
height = tNum.intValue();
if( (height <= 0 ) ) height = 600;

tNum = tNum.valueOf(getParameter("width"));
width = tNum.intValue();
if( (width <= 0 ) ) width = 800;

appletWidth = width;
appletHeight = height;

createPossibilities();
setSize(new java.awt.Dimension(appletWidth, appletHeight));
createBuffers();

}

public void createPossibilities()
{

appletWidth = (appletWidth/numColumns) * numColumns;
appletHeight = (appletHeight/numRows) * numRows;

//Create Instances of 3 point possibility space -
//create a different number each time -
//and each time a new set of values -

for( int i = 0; i < numRows * numColumns; i ++)
thePossibilities.addElement(new threePointPossibility());

}

public void resetPossibilities()
{

destroyBuffers();
thePossibilities.removeAllElements();

appletWidth = width;
appletHeight = height;

setRandomGridSize();
createPossibilities();
setSize(new java.awt.Dimension(appletWidth, appletHeight));
createBuffers();

}

public void setRandomGridSize()
{

numRows = (int) (Math.random() * maxRows) + 1;
numColumns = (int) (Math.random() * maxColumns) + 1;

}

public void createBuffers()
{

threePointPossibility tObject;
Dimension d = size();
Enumeration threePoints = thePossibilities.elements();
int i = 0;
do
{

tObject = ((threePointPossibility)(threePoints.nextElement()));
tObject.bufferImage = createImage(d.width/numColumns,d.height/numRows);
tObject.xOrigin = (d.width/numColumns) * (i%numColumns);
tObject.yOrigin = (d.height/numRows) * (i/numColumns);


tObject.setSizes(d.width/numColumns,d.height/numRows, (i%numColumns), (i/numColumns));
tObject.setParameters();
i++;

}while( threePoints.hasMoreElements());

}

public void destroyBuffers()
{


Enumeration threePoints = thePossibilities.elements();
do
{
((threePointPossibility)(threePoints.nextElement())).bufferImage.flush();
}while( threePoints.hasMoreElements());


}

public void start() {


done = false;
grow = new Thread(this);
grow.start();


}

public void stop() { done = true; }

public void run()
{


while (!done) {
paintPoints();
try {Thread.currentThread().sleep(speed);} catch (InterruptedException e){} }


}


public void paintPoints()
{


Graphics g = getGraphics();
threePointPossibility tObject;

Enumeration threePoints = thePossibilities.elements();
do
{

tObject = ((threePointPossibility)(threePoints.nextElement()));
if( tObject.delayCount >= tObject.delayLimit )
{
tObject.paintPoints();
tObject.display(g);
tObject.delayCount = 0;

}
else tObject.delayCount++;
}while( threePoints.hasMoreElements());

g.drawLine(0,appletHeight-1,appletWidth, appletHeight-1);
g.drawLine(appletWidth-1,0,appletWidth-1, appletHeight);


}

// Initialize the applet
public void init()

{

try {

initComponents();

addMouseListener(new java.awt.event.MouseAdapter() {
public void mousePressed(java.awt.event.MouseEvent e) {
MousePressed(e);
}});

}
catch (Exception e) {
e.printStackTrace();
}

}


public void MousePressed(java.awt.event.MouseEvent e)
{

resetPossibilities();


}


}





View subclasses

launch project

artists' comments