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 & HelpSyntax Questions › Recursion and Arrays
Page Index Toggle Pages: 1
Recursion and Arrays (Read 1742 times)
Recursion and Arrays
Feb 22nd, 2010, 6:29pm
 
Hi Processing Friends!

I have been cranking away on a project that creates a textured 3d Globe in processing, allows the user to rotate around the globe and, finally, animates curves from one point on the globe to another. (An arrow flying from Japan to LA).

I have run into some issues with the integration of recursion in processing.

In order to draw the curve, I will be calculating a point on the curve and then recursively drawing each point thereafter.

I have a list that stores values in a function that I would like to populate using recursion. However, my draw() function re-draws every frame and appears to empty my lists.

Before boring you and making you sift through code, I was wondering if anyone had any simple examples of Processing using lists and recursion.

I have seen the recursion example on processing.org's site but would like one with an array if possible. (/learning/basics/recursion.html)

Thank you!

--
Ayari
Re: Recursion and Arrays
Reply #1 - Feb 22nd, 2010, 8:18pm
 
You can keep your array / list between draw cycles by declaring it globally (outside of all functions).  Then your reiterative function can be called once, during setup, to populate the array.  (Or, if the values are meant to be dynamic, you can run the recursive function from draw().)

Edit: Just re-read your post...if you just want to create a path of points, then as PhilLo points out, recursion isn't necessary.  But global arrays might still be useful.
Re: Recursion and Arrays
Reply #2 - Feb 22nd, 2010, 11:20pm
 
Mmm, some strange points in your message...
"I will be calculating a point on the curve and then recursively drawing each point thereafter"
At this point, I don't see why it should be recursive instead of iterative.

"I have a list that stores values in a function"
You cannot store values in a function (unless you mean the recursion stack?).

"Before boring you and making you sift through code"
Sometime, it is more effective to isolate the specific logic where you have an issue, in a simpler sketch (avoid 3D and other external stuff like images). That's less code to scrutinize, and sometime this exercise is enough for the poster to find some logic flaw... Smiley
Re: Recursion and Arrays
Reply #3 - Mar 3rd, 2010, 11:23am
 
Thank you so much for your replies. I can absolutely simplify what i'm doing to provide an example. I'm sorting out my thoughts first! Thank you again for the guidance!
Re: Recursion and Arrays
Reply #4 - Mar 4th, 2010, 1:47am
 
Something like this

http://www.vimeo.com/8504219

It's pretty easy to do...


James
Re: Recursion and Arrays
Reply #5 - Mar 4th, 2010, 2:21am
 
you can do make the animations smoother by tweening through the points on the bezier/curve which can be done with my tweenpath class:

http://processing.org/discourse/yabb2/?num=1265049539
Re: Recursion and Arrays
Reply #6 - Mar 12th, 2010, 10:51am
 
Yes, James! That's exactly what I'm trying to do. Smiley
Is there anywhere I can see sample code or documentation?

Page Index Toggle Pages: 1