Skip to content

Commit 12a3620

Browse files
committed
binary intersection
1 parent 13cf027 commit 12a3620

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
#!/usr/bin/env jruby
2+
require 'propane'
3+
require 'geomerative'
4+
5+
class BinaryIntersection < Propane::App
6+
include_package 'geomerative'
7+
attr_reader :shp1, :shp2, :shp3, :cursor_shape
8+
9+
def setup
10+
sketch_title 'Binary Intersection'
11+
RG.init(self)
12+
@shp1 = RShape.create_ring(0, 0, 120, 50)
13+
@shp2 = RShape.create_star(0, 0, 100.0, 80.0, 20)
14+
end
15+
16+
def draw
17+
background(255)
18+
translate(width / 2, height / 2)
19+
@cursor_shape = RShape.new(shp2)
20+
cursor_shape.translate(mouse_x - width / 2, mouse_y - height / 2)
21+
# Only intersection does not work for shapes with more than one path
22+
@shp3 = RG.diff(shp1, cursor_shape)
23+
stroke_weight 3
24+
if mouse_pressed?
25+
fill(220, 0, 0, 30)
26+
stroke(120, 0, 0)
27+
RG.shape(cursor_shape)
28+
fill(0, 220, 0, 30)
29+
stroke(0, 120, 0)
30+
RG.shape(shp1)
31+
else
32+
fill(220)
33+
stroke(120)
34+
RG.shape(shp3)
35+
end
36+
end
37+
38+
def settings
39+
size(400, 400)
40+
smooth
41+
end
42+
end
43+
44+
BinaryIntersection.new

0 commit comments

Comments
 (0)