I'm getting started with toxiclibs and I have a question about whether to use springs or attraction.
I'm trying to show four separate clusters of nodes grouped around different points. I'd like to have each node 'attracted' to the centre of its cluster and also slightly repelled from other nodes to avoid overlap.
Should I be using springs to attach all the different nodes to their cluster's centre? Or, can / should I be applying an AttractionBehaviour that would attract a cluster's nodes to the centre?
In generally, when I want two objects or masses to maintain a specific distance from each other, I use springs. If I want an object to be attracted or repelled by another object (something that happens a lot in flocking behaviors for example), I use attractions. If you want the nodes in your cluster to maintain a fixed distance from the central point, then springs are good. Sometimes it makes sense to combine them. For example, I might use attraction to to prevent any two objects from getting too close, as well as keeping the objects onscreen (by repelling from each other, and attracting to the center of the screen), while at the same time, using springs to maintain a network of branch relationships.
Is there a way to have an attraction behaviour only affect some nodes and not others? I'll have a several clusters close together and I'd like nodes to ignore the attraction of other cluster's attraction behaviours.
I can see from reading Shiffman's Nature of Code book that I can set a diameter in the attraction constructor to limit the attraction range. I don't think that will work for me since I have nodes that will spawn at random locations on the screen.
As for adding attractors only applied to certain nodes: You can add behaviors on a global (engine) or local (node) level with toxiclibs, exactly for that reason. The bundled examples all make use of global behaviours, but you could just do this:
VerletParticle2D p = new VerletParticle2D();
If you want to add a behaviour to a sub-set of all particles (e.g. a cluster) then it'd help to keep those particles in a separate collection and then just iterate over that and apply the behavior to each:
I am trying to get from the 2 column example of the cluster example to multi column examples. I am trying to parse from 3 or more columns with data, that has a parent-child relationship. Just like the image you posted. But I couldn't wrap my head around it. Could you please point out the main differences in the code, necessary to achieve this . Especially Hashmap and Parsing the csv, where I believe to be the differences.
Thanks a lot !
Leave a comment on luckyo2's reply
Change topic type
Link this topic
Provide the permalink of a topic that is related to this topic