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.
IndexProgramming Questions & HelpSound,  Music Libraries › Moved Making 3D sound reactive trees
Page Index Toggle Pages: 1
Moved Making 3D sound reactive trees (Read 1379 times)
Moved Making 3D sound reactive trees
Dec 4th, 2007, 1:35pm
 
Hi again,

I'm trying to get this very nice 2D tree from sG (ScreamyGuy.net) to react to music properly, but I'm having huge problems.
You can get the source from here:
http://pwns.dk/source.rar

I've basically got two questions:

1)
I've managed to get the tree to spawn every time a sound is detected, but I can't figure out how to change the ellipses in to spheres without destroying everything.

2)
Is it possible to change how many times the tree is allowed to "grow when you click "T" on your keyboard, so after say, 2 growths, it spawns back into a new tree?
Something like:

-------------------------
if (beat.isHat()) {
      trunk.branch();  
       swide*=1.1; }
(insert code that tells tree to stop growing after 2 growths and instead spawn into a new tree here).
-------------------------

Again, I'm sorry for asking all these retarded questions, and I promise you that once anyone asks questions I'm able to answer, I'll actively help where I can.
Moved Making 3D sound reactive trees
Reply #1 - Dec 13th, 2007, 9:08am
 
1) First off, changing the ellipses to spheres requires a little bit of porting -- this was a 2D app to begin with.  Most obviously, replace calls to ellipse with calls to sphere. The ellipse command takes location parameters, but sphere doesn't, so you'll need to use the translate command prior to calling it. Additionally, you'll need to push/pop the matrix to save your place. So:

Code:

ellipse((int)((x+dx*length.getVal())-length.g... blah blah


becomes

Code:

pushMatrix();
translate(x+dx*length.getVal(),y+dy*length.getVal(),z+dz*length.getVal());
sphere(20);
popMatrix();


You'll want to drop the sphere detail so you don't melt your machine.

Also, all the tree points need to carry z coords too, and the branching code needs to spawn off into the 3rd dimension so that the tree isn't smooshed.

You'll also need to turn off transparency on the leaves or use some depth sorting to prevent overlap issues.

2) Regarding limiting the tree depth, just keep a global variable for the depth and increment on every beat.  When the depth gets above a set level, reset the tree and depth.

Code:

if (beat.isSnare()) {
if (depth < 4){
trunk.branch();
swide*=1.1;
depth++;
}
else{
trunk = new Point(this, 0,-1,0,20,75,2);
trunk.branch();
depth = 0;
swide = 1.1;
}
}



As a side note, I've modded the camera code to point at the trunk -- it's a little bit easier to control.

Code:

cam = new SGCamera(this,width/2,350,500,width/2,350,0);


I don't have the ID3 lib, so I clipped those parts .. sorry. Hope this helps.

video here http://www.vimeo.com/431611

code here http://www.screamyguy.net/tree/tree_v3.zip
Page Index Toggle Pages: 1