Skip to content

Commit 2871100

Browse files
committed
no more
1 parent bb871c6 commit 2871100

File tree

47 files changed

+800
-35
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+800
-35
lines changed

contributed/gravity.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ def initialize(x, y, mass)
5959
def collect_force
6060
@x_accel, @y_accel = 0, 0
6161
@min_dist = 1000
62-
$app.particles.each do |p|
62+
Propane.app.particles.each do |p|
6363
next if p == self
6464
g_dist = hypot(x0 - p.x0, y0 - p.y0)
6565
g_theta = -angle_of(x0, y0, p.x0, p.y0)
@@ -80,7 +80,7 @@ def move
8080
end
8181

8282
def grabbed?
83-
$app.grabbed == self
83+
Propane.app.grabbed == self
8484
end
8585

8686
def run
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
#!/usr/bin/env jruby -v -W2
2+
require 'propane'
3+
require 'pbox2d'
4+
require 'forwardable'
5+
6+
# The Nature of Code
7+
# Daniel Shiffman
8+
# http://natureofcode.com
9+
10+
# Example demonstrating distance joints
11+
# A bridge is formed by connected a series of particles with joints
12+
class DistanceJoint < Propane::App
13+
load_library :distance_joint
14+
15+
attr_reader :box2d, :boundaries, :system
16+
17+
def settings
18+
size(640, 360)
19+
end
20+
21+
def setup
22+
sketch_title 'Distance Joint'
23+
# Initialize box2d physics and create the world
24+
@box2d = WorldBuilder.build(app: self)
25+
@system = ParticleSystem.new
26+
@boundaries = []
27+
# Add a bunch of fixed boundaries
28+
boundaries << Boundary.new(width / 4, height - 5, width / 2 - 50, 10)
29+
boundaries << Boundary.new(3 * width / 4, height - 50, width / 2 - 50, 10)
30+
end
31+
32+
def draw
33+
background(255)
34+
system.run
35+
# Display all the boundaries
36+
boundaries.each(&:display)
37+
fill(0)
38+
text('Click mouse to add connected particles.', 10, 20)
39+
end
40+
41+
def mouse_pressed
42+
system.add_pair(mouse_x, mouse_y)
43+
end
44+
end
45+
46+
DistanceJoint.new
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
require_relative 'lib/boundary'
2+
require_relative 'lib/pair'
3+
require_relative 'lib/particle'
4+
require_relative 'lib/particle_system'

external_library/gem/pbox2d/distance_joint/boundary.rb renamed to examples/forwardable_module_examples/pbox2d/distance_joint/library/distance_joint/lib/boundary.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class Boundary
1313

1414
def initialize(x, y, w, h)
1515
@x, @y, @w, @h = x, y, w, h
16-
@app = $app
16+
@app = Propane.app
1717
# Define the polygon
1818
sd = PolygonShape.new
1919
# Figure out the box2d coordinates

external_library/gem/pbox2d/distance_joint/pair.rb renamed to examples/forwardable_module_examples/pbox2d/distance_joint/library/distance_joint/lib/pair.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ class Pair
99
attr_reader :p1, :p2, :len, :joint
1010
# Chain constructor
1111
def initialize(x, y)
12-
@app = $app
12+
@app = Propane.app
1313
@len = 32
1414
@p1 = Particle.new(x, y)
1515
@p2 = Particle.new(x + rand(-1..1.0), y + rand(-1..1.0))

external_library/gem/pbox2d/distance_joint/particle.rb renamed to examples/forwardable_module_examples/pbox2d/distance_joint/library/distance_joint/lib/particle.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ class Particle
1212

1313
def initialize(x, y)
1414
@r = 8
15-
@app = $app
15+
@app = Propane.app
1616
# Define a body
1717
bd = BodyDef.new
1818
# Set its position

external_library/gem/pbox2d/distance_joint/particle_system.rb renamed to examples/forwardable_module_examples/pbox2d/distance_joint/library/distance_joint/lib/particle_system.rb

File renamed without changes.
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
require_relative 'lib/box'
2+
require_relative 'lib/boundary'
3+
require_relative 'lib/spring'
4+
require_relative 'lib/dummy_spring'

external_library/gem/pbox2d/mouse_joint/boundary.rb renamed to examples/forwardable_module_examples/pbox2d/mouse_joint/library/mouse_joint/lib/boundary.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ class Boundary
1212

1313
def initialize(x, y, w, h, a)
1414
@x, @y, @w, @h, @a = x, y, w, h, a
15-
@app = $app
15+
@app = Propane.app
1616
# Define the polygon
1717
sd = PolygonShape.new
1818
# Figure out the box2d coordinates

external_library/gem/pbox2d/mouse_joint/box.rb renamed to examples/forwardable_module_examples/pbox2d/mouse_joint/library/mouse_joint/lib/box.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ class Box
1111
attr_accessor :body, :w, :h
1212
# Constructor
1313
def initialize(x, y)
14-
@app = $app
14+
@app = Propane.app
1515
@w, @h = 24, 24
1616
# Add the box to the box2d world
1717
make_body(Vec2.new(x, y), w, h)

0 commit comments

Comments
 (0)