Skip to content

Instantly share code, notes, and snippets.

@alexdean
Last active December 15, 2015 21:48
Show Gist options
  • Save alexdean/5327972 to your computer and use it in GitHub Desktop.
Save alexdean/5327972 to your computer and use it in GitHub Desktop.
ruby-processing and fisica
require 'ruby-processing'
# ruby port of http://www.ricardmarxer.com/fisica/examples/ContactResize/applet/ContactResize.pde
class TalkPileApp < Processing::App
load_libraries :fisica
java_import "fisica.Fisica"
java_import "fisica.FWorld"
java_import "fisica.FDrawable"
java_import "fisica.FBody"
java_import "fisica.FCircle"
java_import "fisica.FContact"
def setup
size 400, 400
smooth
Fisica.init self
@world = FWorld.new
@world.setGravity 0, 100
@world.setEdges
end
def draw
background 255
if (frameCount % 50 == 0)
sz = random(30, 60);
b = FCircle.new(sz);
b.setPosition(random(0+30, width-30), 50);
b.setVelocity(0, 100);
b.setRestitution(0.7);
b.setDamping(0.01);
b.setNoStroke();
b.setFill(200, 30, 90);
@world.add(b);
end
@world.draw();
@world.step();
end
def contactEnded(c)
if !c.getBody1().isStatic()
b = c.getBody1();
if b.getSize() > 5
b.setSize(b.getSize()*0.9);
end
end
if !c.getBody2().isStatic()
b = c.getBody2();
if b.getSize()>5
b.setSize(b.getSize()*0.9);
end
end
end
end
TalkPileApp.new :title => "Talk Pile"
@monkstone
Copy link

For processing-2.0, sketch should be "bare" delete line 1, 5, 61 and 63, java_import might be a synonym for it but I would also replace it with include_package. Since processing-2.0 you can use rand(0+30 .. width-30) in place of processing random.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment