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 & HelpPrograms › Setting up layer-like functionality...
Page Index Toggle Pages: 1
Setting up layer-like functionality... (Read 604 times)
Setting up layer-like functionality...
Feb 10th, 2006, 10:40pm
 
I have a sketch where I draw nodes (as ellipses) and connect them with lines. The node object has a method to draw it's connections and a method to update its ellipsis.

I want to avoid having lines run over node ellipses. In my draw method I have solved this by first looping my node object array and draw all lines. Then I loop it again and draw all ellipses (which thus ends up on top of the lines).

This degrades performance as I have to loop my object array twice.

Is there a better way to achieve this? I guess I am looking for some typ of layer functionality so that I can loop my node objects in one pass and do all necessary updates.
Re: Setting up layer-like functionality...
Reply #1 - Feb 11th, 2006, 6:48am
 
Peter,
a simple way to address this problem is to draw your lines only to the edges of your ellipses.

For a circular geometry, you can just draw a line to the center minus the radius.  I'm not sure what your ellipses look like, but a similarly easy mathematical solution is out there for you regardless of your node shape.

If you really don't like math, or if you have an absurdly complicated free-form node, you could create almost all of your graphics in one for loop, since you can call as many functions as you like within the loop.  You will initially draw the line to the left of your node, the for loop will draw the line to the right of the node, then the node (and repeat ad infinitum).
Re: Setting up layer-like functionality...
Reply #2 - Feb 11th, 2006, 11:29am
 
Boiscribble, thank you for your reply. That was my initial idea too, but the problem is that I have many nodes and they are all moving. So, there are cases when a line from one node to another will pass straight through another node (which may have moved over the line).
Re: Setting up layer-like functionality...
Reply #3 - Feb 11th, 2006, 6:52pm
 
I imagine looping twice will probably be less expensive than other solutions.  I'd record object coords, then plot line and then nodes (which I suspect is what you were doing.)
Page Index Toggle Pages: 1