class Node { Color myColor; ArrayList children; Node parent; boolean end; boolean visited; Blob myBlob; Node() { myBlob = new Blob(width, height); myColor = myBlob.getColor(); children = new ArrayList(); end = false; visited = false; } Blob getBlob() { return myBlob; } void setChildren( ArrayList nodes ) { for(int i =0; i= 0) { addTree((Node)children.get(i), cmplx, depth-1); } } rooter.setChildren(children); } void visitNode(Node node) { node.setVisited(); currentNode = node; } void render() { bg.render(); if(currentNode.isEnd()) { return; } if(currentNode != root) { currentNode.getParent().render(); } ArrayList temp = currentNode.getChildren(); for(int i = 0; i< temp.size(); ++i) { ((Node)temp.get(i)).render(); } drawTree(root, width/2, 10, 0, width); } void update() { bg.update(); if(currentNode.isEnd()) { bg.changeBG(new Color(0, 0, 0, 255)); return; } if(currentNode != root) { currentNode.getParent().update(); } ArrayList temp = currentNode.getChildren(); for(int i = 0; i< temp.size(); ++i) { ((Node)temp.get(i)).update(); } } void mouseClick(int x, int y) { ArrayList temp = currentNode.getChildren(); for(int i = temp.size()-1; i>=0; --i) { if(((Node)temp.get(i)).isInside(x, y)) { ((Node)(currentNode.getChildren().get(i))).setVisited(); currentNode = (Node)(currentNode.getChildren().get(i)); bg.changeBG(((Blob)currentNode.getBlob()).getColor()); /* for( int k = 0; k < temp.size(); ++k) { ((Blob)Blobs.get(k)).animate(2); } */ return; } } if(currentNode != root) { if(currentNode.getParent().isInside(x, y)) { currentNode.getParent().setVisited(); currentNode = currentNode.getParent(); bg.changeBG(((Blob)currentNode.getBlob()).getColor()); return; } } } void drawTree(Node rooter, int x, int y, int b, int e) { ArrayList children = rooter.getChildren(); if(children.size() > 0) { int step = (e-b)/(children.size()+1); int step2 = (e-b)/(children.size()); for(int i = 0; i< children.size(); ++i) { strokeWeight(3); stroke(0, 0, 0, 50);//, (life/birth)*a); line(x, y, b + step*(i+1), y + ((height-30)/(myDepth+1))); if( ((Node)children.get(i)).hasVisited()) { drawTree((Node)children.get(i), b + step*(i+1), y + ((height-30)/(myDepth+1)), b + step2*i, e - step2*(children.size()-1-i)); } } } if(rooter == currentNode ) rooter.renderAtCurrent(x,y); else rooter.renderAt(x, y); } boolean isDone() { return currentNode.isEnd(); } }