import java.util.ArrayList; import processing.core.PApplet; public class Ant { private AutonomousAgentsOne _app; private float _xV; private float _yV; private float _a; private ArrayList _prevL; private int _multiplier; private int _colorOne; private int _colorTwo; public Ant( AutonomousAgentsOne app, float initX, float initY, int colorOne, int colorTwo, int multiplier ) { //PApplet.println( "Ant object created" ); set_app(app); set_xV( initX ); set_yV( initY ); set_colorOne( colorOne ); set_colorTwo( colorTwo ); set_multiplier( multiplier ); init(); } public void init() { _a = 0; //_prevL = new ArrayList(); /*_pixels = new boolean [ _app.width ][ _app.height ]; for ( int i = 0; i < _app.width; i++ ) { for ( int j = 0; j < _app.height; j++ ) { _pixels[ i ][ j ] = false; } }*/ //_app.setPixel( false, _xV, _yV ); //moveAnt(); } public void moveAnt() { float tX = PApplet.cos( _a ) * this._multiplier; float tY = PApplet.sin( _a ) * this._multiplier; _xV = PApplet.round( _xV + tX ); _yV = PApplet.round( _yV + tY ); if ( _xV < this._app.width && _xV >= 0 && _yV < this._app.height && _yV >= 0 ) { testNeighbours(); } } // THIS IS THE REAL DEAL! private void testNeighbours() { boolean [][] tArr = _app.get_pixels(); boolean tBool = tArr[ ( int ) _xV ][ ( int ) _yV ]; int tColor; if ( !tBool ) { _a += ( Math.PI / 2 ); tColor = this.get_colorOne(); } else { _a -= ( Math.PI / 2 ); tColor = this.get_colorTwo(); } _app.setPixel( tColor, _xV, _yV ); tArr[ ( int ) _xV ][ ( int ) _yV ] = !tBool; /*Location tLoc; for ( int i = 0; i < _prevL.size(); i++ ) { tLoc = _prevL.get( i ); if ( tLoc.get_xV() == _xV && tLoc.get_yV() == _yV ) { _a -= ( Math.PI / 2 ); tBool = true; _app.setPixel( tBool, _xV, _yV ); _prevL.remove( i ); break; } } if ( !tBool ) { _a += ( Math.PI / 2 ); _app.setPixel( tBool, _xV, _yV ); tLoc = new Location( _xV, _yV ); _prevL.add( tLoc ); }*/ } public ArrayList get_prevL() { return _prevL; } public void set_xV( float xV ) { this._xV = xV; } public void set_yV( float yV ) { this._yV = yV; } public void set_app( AutonomousAgentsOne _app ) { this._app = _app; } public AutonomousAgentsOne get_app() { return _app; } public void set_colorOne( int colorOne ) { this._colorOne = colorOne; } public int get_colorOne() { return this._colorOne; } public void set_colorTwo( int colorTwo ) { this._colorTwo = colorTwo; } public int get_colorTwo() { return _colorTwo; } public void set_multiplier( int multiplier ) { this._multiplier = multiplier; } }