[ANN] Springz 1.0

G

Gavin Kistner

The Springz library allows you to attach two objects together (in 2D
space) with a spring, and simulate how they pull/push each other.

Boring when used between two objects, it becomes interesting when you
attach thousands of springs with different strenghts and distances
between hundreds of nodes, and let the simulation determine the best
configuration of those nodes. (I wrote this library specifically to
create a social network diagram from a large amount of data. I had
written it first in Javascript + SVG, and it was working, but too
slowly: 3 hours to render the first frame, and 12+ hours for each frame
after that.)

Despite the very visual nature of this application, this library
doesn't know jack about graphics; it just knows how to push/pull
theoretical objects around in theoretical 2D space. Making this visible
to the user is up to you. (My application reads in XML data and then
outputs a few frames of SVG pre-rendered animation.)

The documentation for the Springz class lists the key features at the
top of it.
You can read this laboriously-written documentation, and download the
file itself, from:
http://phrogz.net/RubyLibs/ (click on Springz.rb under the Files
listing).


If you happen to have the Adobe SVG plugin (freely avail for
Win/Mac/Linux/Solaris) installed, you can see the JS version of this
library in action at http://phrogz.net/SVG/SpringzTest.svg -- click the
green rectangle to start the simulation, and then drag objects around
and/or click the orange button to scatter them about.


WANTED: If anyone is a matrix/math geek and knows of speedier ways to
do what I'm laboriously calculating, I'd love to trade a few emails.


Enjoy!
 
S

Shashank Date

Gavin Kistner said:
You can read this laboriously-written documentation, and download the
file itself, from:
http://phrogz.net/RubyLibs/ (click on Springz.rb under the Files
listing).

What does the method "delete" on Lines 234, 235 do:

<snip>

def remove_thyself
@@all.delete(self)
delete @@lookup[@o1][@o2] if @@lookup[@o1]
#^^^^^
delete @@lookup[@o2][@o1] if @@lookup[@o2]
#^^^^^
@@objs={}
@@all.each{ |s|
@@objs[s.o1] = @@objs[s.o2] = 1
}
end

<snip>

Thanks,
--shanko
 
G

Gavin Kistner

What does the method "delete" on Lines 234, 235 do:

<snip>

def remove_thyself
@@all.delete(self)
delete @@lookup[@o1][@o2] if @@lookup[@o1]
#^^^^^
delete @@lookup[@o2][@o1] if @@lookup[@o2]
#^^^^^


Heh...oops. :)

Apparently I got confused in the middle of converting from JS to Ruby.
(In my app I never actually used remove_thyself, so it wasn't been
tested.)

Thanks for pointing that out. The correct code should be:

@@lookup[@o1].delete(@o2) if @@lookup[@o1]
@@lookup[@o2].delete(@o1) if @@lookup[@o2]

(or, if you like:
@@lookup[@o1] && @@lookup[@o1].delete(@o2)
@@lookup[@o2] && @@lookup[@o2].delete(@o1)
)


and has been updated to match.

(The 'delete' statement in Javascript removes a property from an
object.)
 
S

Shashank Date

Gavin Kistner said:
Thanks for pointing that out. The correct code should be:

@@lookup[@o1].delete(@o2) if @@lookup[@o1]
@@lookup[@o2].delete(@o1) if @@lookup[@o2]

That is exactly what I did ... will let you know when I get it
to work with visualization (using wxRuby).

Thanks,
-- shanko
 
P

Paul Brannan

The Springz library allows you to attach two objects together (in 2D
space) with a spring, and simulate how they pull/push each other.

A library like this has a very large number of applications. The most
obvious ones are in physics, but seeing this library reminded me of a
talk I saw by Jim Coplien a few years ago on organizational patterns,
where they found use for a similar library. This page talks briefly
about it:

http://www.easycomp.org/cgi-bin/OrgPatterns?SocialNetworkTheoryFoundations

An (over)-simplication of what they do is get employees to fill out some
forms that determine how strong the interaction is between them and
other employees, represent that interaction as a force (such as a
spring), throw the graph into a simulator not different from Springz and
see where they land. Roles that end up in the center turn out to be the
most active roles. From these diagrams they can then identify
organizational patterns.

Thought y'all might find this interesting since the Ruby community is no
stranger to patterns (design patterns and otherwise) in software
development.

Paul
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,147
Messages
2,570,835
Members
47,383
Latest member
EzraGiffor

Latest Threads

Top