PDA

View Full Version : Help with generative code



mandril
November 4th, 2009, 04:22 AM
Hi!!

I want to do something that I'm not really sure where or how to start...

I would like to create an image like the attachment based on an XML that has a list of names, each one with a list of attributes. Each name would create a diferent big red circle, while its attributes would create the "branches" with the smaller circles.

Any ideas how to approach something like this? If anyone knows how to do it in AS2 that would be ok too. Speaking of which, is it ok to post the same question on both forums at the same time? There might be people that uses AS2 that doesn't visit this section, right?

Anyway, thanks in advance for any help!

_kp
November 4th, 2009, 06:22 AM
I would write a class node that receives a reference to it's parent node and a number of 'how far' it is away from the center (i.e 0 for the center, 1 for each subnode of it, ...). Depending on that number it draws itself in different size and color. It needs a method to draw a line to its parent.
I think the hardest part of this will be calculation positions of each node so they don't overlap and don't look to random or sorted .

rkalexander
March 25th, 2010, 01:14 AM
I think _kp is on the right track here. Anyone have code like this in AS3?

halcyon42
March 26th, 2010, 10:37 AM
I think _kp is on the right track here. Anyone have code like this in AS3?

I would really like to see some code like this.

nook
March 26th, 2010, 06:54 PM
Think circular math. One turn is 360 degrees. Divide 360 in as many sub circles you need. Choose a default length. Add some randomness to the angles and length.

Use Point and Point.distance() for calculation.

If you need many levels it will be a bit tricky not to overlap other lines.

Sorry for the vague explanation, I'm a bit tired. :-/