Skip to content

Commit 4b479b0

Browse files
committed
boolean shapes
1 parent 52b0d60 commit 4b479b0

File tree

1 file changed

+58
-0
lines changed

1 file changed

+58
-0
lines changed
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
#!/usr/bin/env jruby
2+
# frozen_string_literal: true
3+
require 'propane'
4+
require 'toxiclibs'
5+
6+
# The Sketch Class
7+
class BooleanShapes < Propane::App
8+
load_library :control_panel
9+
attr_reader :gfx, :bool, :panel, :type, :hide, :polies
10+
include Toxi
11+
12+
TYPE = [BooleanShapeBuilder::Type::UNION,
13+
BooleanShapeBuilder::Type::XOR].freeze
14+
KEY = %w(union xor).freeze
15+
16+
def setup
17+
sketch_title 'Boolean Shapes'
18+
@gfx = Gfx::ToxiclibsSupport.new(self)
19+
@bool = KEY.zip(TYPE).to_h
20+
control_panel do |c|
21+
c.title = 'Select Type'
22+
c.menu :type, KEY, 'union'
23+
@panel = c
24+
end
25+
@hide = false
26+
end
27+
28+
def draw
29+
unless hide
30+
@hide = true
31+
panel.set_visible(hide)
32+
end
33+
background(160)
34+
builder = BooleanShapeBuilder.new(bool[type])
35+
phi = frame_count * 0.01
36+
builder.add_shape(Circle.new(mouse_x, mouse_y, 50))
37+
builder.add_shape(Ellipse.new(150, 130 + sin(phi) * 50, 120, 60))
38+
builder.add_shape(Rect.new(200 + sin(phi * 13 / 8) * 50, 180, 100, 100))
39+
builder.add_shape(
40+
Triangle2D.create_equilateral_from(
41+
TVec2D.new(50 + sin(phi * 15 / 13) * 50, 200), TVec2D.new(300, 200)
42+
)
43+
)
44+
builder.add_shape(
45+
Circle.new(100, 300, 50 + 30 * sin(phi * 21 / 15)).toPolygon2D(6)
46+
)
47+
fill(125)
48+
stroke(255, 0, 0)
49+
@polies = builder.compute_shapes
50+
polies.each { |p| gfx.polygon2D(p) }
51+
end
52+
53+
def settings
54+
size(400, 400)
55+
end
56+
end
57+
58+
BooleanShapes.new

0 commit comments

Comments
 (0)