We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexDiscussionEvents,  Publications,  Opportunities › CodeTree: Grow a Tree Volunteer
Page Index Toggle Pages: 1
CodeTree: Grow a Tree Volunteer? (Read 789 times)
CodeTree: Grow a Tree Volunteer?
Apr 10th, 2006, 1:38pm
 
Is there anyone out there that would be willing to volunteer their work for the Grow a Tree section on http://www.CodeTree.org ? Dan Shiffman’s example has been up since February, I had to recover from a hard drive meltdown in March, and the next month’s submitter has been overwhelmed with penning a Processing book.

I think that the Grow a Tree section on the CodeTree site has been a success and is something that’s definitely worth building upon. I really like the suggestions of nominating any submission to start a tree (along the lines of starting your own chatroom) but that will take some reworking of the page interfaces as well as the databases–something that I unfortunately do not have the time to do at the moment. In the meanwhile, I’d like to keep things going and continue with the monthly Grow a Tree. Any takers?
Re: CodeTree: Grow a Tree Volunteer?
Reply #1 - Apr 15th, 2006, 4:50pm
 
How about grow a binary tree
Code:

BTree btree;
void setup(){
size(400, 400);
btree = new BTree(5, height / 2, 10);
smooth();
ellipseMode(CENTER);
}
void draw(){
background(255);
btree.draw();
}
class BTree{
int depth;
Vec2 [] node;
BTree(float x, float y, int depth){
this.depth = depth;
node = new Vec2[(int)pow(2,depth + 1)];
node[1] = new Vec2(x, y);
for(int i = 1; i < node.length - (int)pow(2, depth); i++){
float xn = node[i].x + cos(random(1.0)) * (50.0);
float yn = node[i].y + sin(random(1.0)) * (50.0);
node[2 * i] = new Vec2(xn, yn);
xn = node[i].x + cos(-random(1.0)) * (50.0);
yn = node[i].y + sin(-random(1.0)) * (50.0);
node[1 + 2 * i] = new Vec2(xn, yn);
}
}
void draw(){
for(int i = 1; i < node.length - (int)pow(2, depth); i++){
ellipse(node[i].x, node[i].y, 10, 10);
line(node[i].x, node[i].y, node[2 * i].x, node[2 * i].y);
line(node[i].x, node[i].y, node[1 + 2 * i].x, node[1 + 2 * i].y);
}
}
}

static class Vec2{
float x,y;
Vec2(float x, float y){
this.x = x;
this.y = y;
}
}

I think the Complete Binary Tree has scope for being polished up into some nice and to the point little applets and Flash objects. I haven't quite figured out how to calculate the depth of a node, but I thought perhaps that's something for other people to expand on.

I don't mind if someone posts a more compact or easier to read version of this code. I'm not exactly a poet when it comes to syntax.
Page Index Toggle Pages: 1