// redFri - version 060225 class ALocation { AWorld world; float x, y, z; public ALocation(AWorld _world, float _x, float _y, float _z) { world= _world; x= _x; y= _y; z= _z; } float distance(ALocation other) { return abs(sqrt(pow(other.x-x, 2)+pow(other.y-y, 2)+pow(other.z-z, 2))); } void add(ADirection dir) { x= x+dir.vx; y= y+dir.vy; z= z+dir.vz; } } class ADirection { float vx, vy, vz; public ADirection(float _vx, float _vy, float _vz) { vx= _vx; vy= _vy; vz= _vz; } void mul(float _const) { vx= vx*_const; vy= vy*_const; vz= vz*_const; } } class AWorld { Agent[] agents; int dim, w, h, d; float damp; public AWorld(int _dim, int _w, int _h, int _d, float _damp) { dim= _dim; w= _w; h= _h; d= _d; damp= _damp; } } //-- abstract class Agent { ALocation loc; ADirection dir; float energy; color col, borderCol; int agentSize; public Agent(ALocation _loc, ADirection _dir, float _energy, color _col, color _borderCol, int _agentSize) { loc= _loc; dir= _dir; energy= _energy; col= _col; borderCol= _borderCol; agentSize= _agentSize; } void draw() { stroke(borderCol); fill(col); drawShape(); } void drawShape() {} //to override void move() { loc.add(dir); dir.mul(loc.world.damp); } } //-- class Agent1D extends Agent { public Agent1D(ALocation _loc, ADirection _dir, float _energy, color _col, color _borderCol, int _agentSize) { super(_loc, _dir, _energy, _col, _borderCol, _agentSize); } void drawShape() { point(loc.x*width, height/2); //agentSize??? } } class Agent2D extends Agent { public Agent2D(ALocation _loc, ADirection _dir, float _energy, color _col, color _borderCol, int _agentSize) { super(_loc, _dir, _energy, _col, _borderCol, _agentSize); } void drawShape() { rect(loc.x*width, loc.y*height, agentSize, agentSize); } } class Agent3D extends Agent { public Agent3D(ALocation _loc, ADirection _dir, float _energy, color _col, color _borderCol, int _agentSize) { super(_loc, _dir, _energy, _col, _borderCol, _agentSize); } void drawShape() { pushMatrix(); translate(loc.x*width, loc.y*height, loc.z*100); box(agentSize, agentSize, agentSize); popMatrix(); } }