Skip to content

Commit c98c5ea

Browse files
committed
re-organise
1 parent bcc5b64 commit c98c5ea

File tree

161 files changed

+297
-12887
lines changed

Some content is hidden

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

161 files changed

+297
-12887
lines changed

demo/circle_collision.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ def check_collision(other_ball)
6060
# calculate magnitude of the vector separating the balls
6161
return unless difference.mag < (r + other_ball.r)
6262
# get angle of difference
63-
theta = difference.heading
63+
theta = difference.fast_heading
6464
# precalculate trig values
6565
sine = sin(theta)
6666
cosine = cos(theta)

demo/library/circle/lib/triangle_point.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ def direction(acc)
1818
@accel = acc
1919
# magnitude of the acceleration is proportional to the angle between
2020
# acceleration and velocity
21-
dif = acc.angle_between(vel)
21+
dif = acc.fast_angle_between(vel)
2222
dif = map1d(dif, 0..PI, 0.1..0.001)
2323
@accel = acc * dif
2424
end

external_library/gems/geomerative/data/bot1.svg

+5-5
Loading

external_library/gems/geomerative/hello_svg_to_pdf.rb

+3-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
require 'geomerative'
44

55
class HelloSvgToPDF < Processing::App
6-
load_library 'pdf'
6+
load_library :pdf
7+
include_package 'processing.pdf'
78
attr_reader :grp, :pdf
89

910
def settings
@@ -14,7 +15,7 @@ def setup
1415
sketch_title 'SVG to PDF sketch'
1516
RG.init(self)
1617
@grp = RG.load_shape(data_path('bot1.svg'))
17-
@pdf = create_graphics(width, height, PDF, 'bot1.pdf')
18+
@pdf = create_graphics(width, height, 'processing.pdf.PGraphicsPDF', data_path('bot1.pdf'))
1819
end
1920

2021
def draw
Original file line numberDiff line numberDiff line change
@@ -1,77 +1,84 @@
1-
require 'toxiclibs'
1+
#!/usr/bin/env jruby -w
2+
require 'picrate'
23
require 'geomerative'
4+
require 'toxiclibs'
35

4-
attr_reader :font, :input, :physics
6+
class PhysicsType < Processing::App
57

6-
def settings
7-
size(1280, 720, P3D)
8-
smooth
9-
end
8+
attr_reader :font, :input, :physics
109

11-
def setup
12-
sketch_title 'Physics Type'
13-
@input = 'Hello!'
14-
RG.init(self)
15-
fnt = RG.load_font(data_path('ReplicaBold.ttf')) # file name
16-
RG.text_font(fnt, 330) # RFont object, size
17-
@font = RG.get_text(input) # String to RShape
18-
RG.set_polygonizer(RCommand::UNIFORMLENGTH)
19-
RG.set_polygonizer_length(10) # length of segment
20-
init_physics
21-
fill(255)
22-
end
10+
def settings
11+
size(1280, 720, P3D)
12+
smooth
13+
end
2314

24-
def draw
25-
physics.update
26-
background(0)
27-
stroke(255)
28-
physics.springs.each do |s|
29-
line(s.a.x, s.a.y, s.b.x, s.b.y)
15+
def setup
16+
sketch_title 'Physics Type'
17+
@input = 'Hello!'
18+
RG.init(self)
19+
fnt = RG.load_font(data_path('ReplicaBold.ttf')) # file name
20+
RG.text_font(fnt, 330) # RFont object, size
21+
@font = RG.get_text(input) # String to RShape
22+
RG.set_polygonizer(RCommand::UNIFORMLENGTH)
23+
RG.set_polygonizer_length(10) # length of segment
24+
init_physics
25+
fill(255)
3026
end
31-
physics.particles.each do |p|
32-
ellipse(p.x, p.y, 3, 3)
27+
28+
def draw
29+
physics.update
30+
background(0)
31+
stroke(255)
32+
physics.springs.each do |s|
33+
line(s.a.x, s.a.y, s.b.x, s.b.y)
34+
end
35+
physics.particles.each do |p|
36+
ellipse(p.x, p.y, 3, 3)
37+
end
3338
end
34-
end
3539

36-
def init_physics
37-
@physics = Physics::VerletPhysics2D.new
38-
# set screen bounds as bounds for physics sim
39-
physics.set_world_bounds(Toxi::Rect.new(0, 0, width, height))
40-
# add gravity along positive Y axis
41-
physics.add_behavior(Physics::GravityBehavior2D.new(TVec2D.new(0, 0.1)))
42-
# multidimensional array of x and y coordinates
43-
paths = font.get_points_in_paths
44-
offset = TVec2D.new(200, 250)
45-
return if paths.nil?
46-
paths.length.times do |ii|
47-
points = paths[ii]
48-
path_particles = []
49-
points.length.times do |i|
50-
p = Physics::VerletParticle2D.new(
51-
points[i].x + offset.x,
52-
points[i].y + offset.y
53-
)
54-
physics.addParticle(p)
55-
path_particles << p
56-
physics.addSpring(
57-
Physics::VerletSpring2D.new(
58-
path_particles[i - 1],
59-
p,
60-
path_particles[i - 1].distanceTo(p),
61-
1
40+
def init_physics
41+
@physics = Physics::VerletPhysics2D.new
42+
# set screen bounds as bounds for physics sim
43+
physics.set_world_bounds(Toxi::Rect.new(0, 0, width, height))
44+
# add gravity along positive Y axis
45+
physics.add_behavior(Physics::GravityBehavior2D.new(TVec2D.new(0, 0.1)))
46+
# multidimensional array of x and y coordinates
47+
paths = font.get_points_in_paths
48+
offset = TVec2D.new(200, 250)
49+
return if paths.nil?
50+
paths.length.times do |ii|
51+
points = paths[ii]
52+
path_particles = []
53+
points.length.times do |i|
54+
p = Physics::VerletParticle2D.new(
55+
points[i].x + offset.x,
56+
points[i].y + offset.y
6257
)
63-
) if i > 0
58+
physics.addParticle(p)
59+
path_particles << p
60+
physics.addSpring(
61+
Physics::VerletSpring2D.new(
62+
path_particles[i - 1],
63+
p,
64+
path_particles[i - 1].distanceTo(p),
65+
1
66+
)
67+
) if i > 0
68+
end
69+
first = path_particles.first
70+
last = path_particles.last
71+
physics.add_spring(
72+
Physics::VerletSpring2D.new(
73+
first,
74+
last,
75+
first.distance_to(last),
76+
1
77+
)
78+
)
79+
first.lock
80+
end
6481
end
65-
first = path_particles.first
66-
last = path_particles.last
67-
physics.add_spring(
68-
Physics::VerletSpring2D.new(
69-
first,
70-
last,
71-
first.distance_to(last),
72-
1
73-
)
74-
)
75-
first.lock
7682
end
77-
end
83+
84+
PhysicsType.new
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,39 @@
1+
#!/usr/bin/env jruby -w
2+
require 'picrate'
13
require 'geomerative'
24

3-
attr_reader :bounds, :my_rect
5+
class GeomerativeBoundary < Processing::App
6+
attr_reader :bounds, :my_rect
47

5-
def settings
6-
size(600, 480, P2D)
7-
end
8-
9-
def setup
10-
sketch_title 'Geomerative Boundary Test'
11-
RG.init(self)
12-
RG.set_polygonizer(RG.ADAPTATIVE)
13-
@bounds = RShape.create_rectangle(100, 100, 100, 50)
14-
end
8+
def settings
9+
size(600, 480, P2D)
10+
end
1511

16-
def draw
17-
fill 255
18-
stroke 0
19-
@my_rect = RShape.create_rectangle(mouseX, mouseY, 10, 10)
20-
bounds.draw
21-
draw_my_rect
22-
end
12+
def setup
13+
sketch_title 'Geomerative Boundary Test'
14+
RG.init(self)
15+
RG.set_polygonizer(RG.ADAPTATIVE)
16+
@bounds = RShape.create_rectangle(100, 100, 100, 50)
17+
end
2318

24-
def draw_my_rect
25-
if bounds.contains_shape(my_rect)
26-
no_stroke
27-
fill 255, 0, 0
28-
else
29-
stroke 0
19+
def draw
3020
fill 255
21+
stroke 0
22+
@my_rect = RShape.create_rectangle(mouseX, mouseY, 10, 10)
23+
bounds.draw
24+
draw_my_rect
25+
end
26+
27+
def draw_my_rect
28+
if bounds.contains_shape(my_rect)
29+
no_stroke
30+
fill 255, 0, 0
31+
else
32+
stroke 0
33+
fill 255
34+
end
35+
my_rect.draw
3136
end
32-
my_rect.draw
3337
end
38+
39+
GeomerativeBoundary.new
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,47 @@
1+
#!/usr/bin/env jruby -w
2+
require 'picrate'
13
require 'geomerative'
2-
attr_reader :grp, :ignoring_styles
34

4-
def setup
5-
sketch_title 'Mouse Inside RShape?'
6-
RG.init(self)
7-
@ignoring_styles = false
8-
RG.ignore_styles(ignoring_styles)
9-
RG.set_polygonizer(RG.ADAPTATIVE)
10-
@grp = RG.load_shape(data_path('mapaAzimutal.svg'))
11-
grp.center_in(g, 100, 1, 1)
12-
end
5+
class ShapeContains < Processing::App
6+
attr_reader :grp, :ignoring_styles
137

14-
def draw
15-
translate(width / 2, height / 2)
16-
background(255)
17-
stroke(0)
18-
no_fill
19-
grp.draw
20-
# pre-cast to java, avoids issues with overloaded constructor
21-
point = [mouse_x - width / 2, mouse_y - height / 2].to_java(:float)
22-
p = RPoint.new *point
23-
grp.children.each do |child|
24-
next unless child.contains(p)
25-
RG.ignore_styles(true)
26-
fill(0, 100, 255, 250)
27-
no_stroke
28-
child.draw
8+
def setup
9+
sketch_title 'Mouse Inside RShape?'
10+
RG.init(self)
11+
@ignoring_styles = false
2912
RG.ignore_styles(ignoring_styles)
13+
RG.set_polygonizer(RG.ADAPTATIVE)
14+
@grp = RG.load_shape(data_path('mapaAzimutal.svg'))
15+
grp.center_in(g, 100, 1, 1)
3016
end
31-
end
3217

33-
def mouse_pressed
34-
@ignoring_styles = !ignoring_styles
35-
RG.ignore_styles(ignoring_styles)
36-
end
18+
def draw
19+
translate(width / 2, height / 2)
20+
background(255)
21+
stroke(0)
22+
no_fill
23+
grp.draw
24+
# pre-cast to java, avoids issues with overloaded constructor
25+
point = [mouse_x - width / 2, mouse_y - height / 2].to_java(:float)
26+
p = RPoint.new *point
27+
grp.children.each do |child|
28+
next unless child.contains(p)
29+
RG.ignore_styles(true)
30+
fill(0, 100, 255, 250)
31+
no_stroke
32+
child.draw
33+
RG.ignore_styles(ignoring_styles)
34+
end
35+
end
3736

38-
def settings
39-
size(600, 600)
37+
def mouse_pressed
38+
@ignoring_styles = !ignoring_styles
39+
RG.ignore_styles(ignoring_styles)
40+
end
41+
42+
def settings
43+
size(600, 600)
44+
end
4045
end
46+
47+
ShapeContains.new

0 commit comments

Comments
 (0)