How to make irregular SVG shapes bounce?
in
Programming Questions
•
3 years ago
I have begun developing the first of a long series of Processing sketches for use in a high school chemistry curriculum. The idea is to use simulations of molecular activity to supplement lab and reading activity in learning chemistry concepts. So far Processing has been a great tool for this project; my supervisor has been pleased with the functionality of Processing visualizations over previous Flash and Netlogo attempts.
I've run into a particular problem with molecule interactions, however. My question:
How can I make two irregular shapes, floating across the Processing canvas, "bounce" off of one another when they overlap?
Initially, I was rendering molecules in Processing with a series of different sized ellipses; making molecules bounce was a matter of calculating the radii of the atoms in a molecule, returning these radii in an array, and checking the array against the radii array of another molecule; if any radii overlapped, the molecules would bounce. Pretty straightforward.
However, the visual sophistication and variation between various molecules, in addition to requests for frequent updates in molecular structure and appearance, has pushed me toward creating the molecules in Adobe Illustrator, and importing Illustrator SVG files into Processing for use in my sketches. Thus, since the files are SVG imports, I don't think I have access to their boundaries... the only thing I can think of is calculating which pixels the shapes occupy: this seems a horrible kluge, and I'm not sure how to do it.
Does anyone have any other ideas? I'm all ears.
If you would like to see an early version of this project (with molecules drawn via Processing ellipses):
1