int INIT_N = 200; class TheWorld { Vector nodes; int iRepType = 0; public int fProxemicDistance = 30; public TheWorld(int width, int height){ nodes = new Vector(); int tmpW = (int)sqrt(INIT_N); for(int y = 0; y < tmpW ; y++){ for(int x = 0; x < tmpW ; x++){ Node node = new Node(); float locX = (float)x / (float)tmpW * width + width/tmpW / 2.; float locY = (float)y / (float)tmpW * height + height/tmpW / 2.; // float locX = (float)width/2 + random(300) - 150; // float locY = (float)height/2 + random(300) - 150; node.pPosition.setLocation(locX, locY); node.pDestination.setLocation(locX, locY); nodes.add(node); node.setType(Node.NEUTRAL); } } } public void timeLapse(){ invokeInteractions(); } public void invokeInteractions(){ for(int i = 0 ; i < nodes.size(); i++){ Node srcNode = (Node)nodes.elementAt(i); Vector neighbours = getNeighbours(srcNode); for(int n = 0 ; n < neighbours.size(); n++){ Node neighbour = (Node)neighbours.elementAt(n); srcNode.getSignalFrom(neighbour); } srcNode.nextCycle(); } } public void disturb(int x, int y){ float effectiveDistance = 50.0; for(int i = 0 ; i < nodes.size(); i++){ Node tmpNode = (Node)nodes.elementAt(i); float distance = (float)tmpNode.pPosition.distance(new Point2D.Float((float)x, (float)y)); if(effectiveDistance > distance){ tmpNode.pDestination.setLocation(tmpNode.pDestination.getX() +(float)(tmpNode.pPosition.getX() - x), tmpNode.pDestination.getY() + (float)(tmpNode.pPosition.getY() - y)); tmpNode.pRepulsion.setLocation((tmpNode.pPosition.getX() - (float)x)/distance*10., (tmpNode.pPosition.getY() - (float)y) /distance*10.); tmpNode.fUrgeToMove = 2.0; if(tmpNode.fFrequency < 1.0){ tmpNode.fFrequency *= 1.1; } } } } public void draw(){ for(int i = 0 ; i < nodes.size(); i++){ Node tmpNode = (Node)nodes.elementAt(i); tmpNode.draw(iRepType); } } /* Node specific functions */ public Vector getNeighbours(Node src) { Vector retval = new Vector(); for(int i = 0; i < nodes.size(); i++){ Node tmpNode = (Node)nodes.elementAt(i); if(tmpNode != src) if(src.pPosition.distance(tmpNode.pPosition) < fProxemicDistance) retval.add(tmpNode); } return retval; } // set the type of representation public void setRepresentation(int type){ iRepType = type; } }