Advertise here with Carbon Ads

This site is made possible by member support. โค๏ธ

Big thanks to Arcustech for hosting the site and offering amazing tech support.

When you buy through links on kottke.org, I may earn an affiliate commission. Thanks for supporting the site!

kottke.org. home of fine hypertext products since 1998.

๐Ÿ”  ๐Ÿ’€  ๐Ÿ“ธ  ๐Ÿ˜ญ  ๐Ÿ•ณ๏ธ  ๐Ÿค   ๐ŸŽฌ  ๐Ÿฅ”

Magnetic snakes

Taking a bit of code from here and a snippet from there, Robert Hodgin made an animation of 3-D snakes in Processing. Check out Hodgin’s use of constraints to spur the invention of a way to keep the snakes from overlapping.

I had no interest in adding a complete 3D physics library because my needs at this time are fairly simple. I am not worried about environment… I just want the snakes to crawl over each other. I decided to try magnetic repulsion despite thinking it probably wouldn’t work well enough. The thinking is this: Take each segment of a snake (200 segments each), and check its distance to every single other segment of every other snake on screen. Stupid, right? Yeah, pretty much. But with some optimization and only checking the segment distances if the snakes in question are close enough for overlap to be possible, I got it to run at 60 fps with 10 snakes.

Actually, when you get right down to it โ€” the atoms in snakes’ bodies, that is โ€” magnetic repulsion isn’t that far off from how matter achieves its electromagnetic opacity. Hodgin also made a video in which the snakes react to music. I wonder if this one’s gonna end up in iTunes. (via waxy)