The DummySpring class
# dummy_spring.rb by Martin Prout # using duck-typing so class can stand in for Spring # Using this class avoids test for nil class DummySpring def initialize; end # If it exists we set its target to the mouse location def update(_x, _y); end def display; end # This is the key function where # we attach the spring to an x,y location # and the Box object's location def bind(x, y, box) spring = Spring.new spring.bind(x, y, box) spring end def destroy; end end
The only slightly tricky thing was the sketch needs to know that DummyString bind returns an instance of Spring, but otherwise it all looks pretty cool. Would make a good example except that pbox2d confounds things (we have two worlds a jbox2d physics world and a processing sketch world, and we track both).
No comments:
Post a Comment