Sha256: 74f4a14e0b12286640aca70d36c4317b71ba344b37099473d8e5a12857d8da75

Contents?: true

Size: 1.17 KB

Versions: 3

Compression:

Stored size: 1.17 KB

Contents

require 'toxiclibs'
load_library :control_panel
attr_reader :gfx, :bool, :panel, :type, :hide, :polies
include Toxi

TYPE = [BooleanShapeBuilder::Type::UNION, BooleanShapeBuilder::Type::XOR]
KEY = %w(union xor).freeze

def setup
  sketch_title 'Boolean Shapes'
  @gfx = Gfx::ToxiclibsSupport.new(self)
  @bool = KEY.zip(TYPE).to_h
  control_panel do |c|
    c.title = 'Control Panel'
    c.menu :type, KEY, 'union'
    @panel = c
  end
  @hide = false
end

def draw
  unless hide
    @hide = true
    panel.set_visible(hide)
  end
  background(160)
  builder = BooleanShapeBuilder.new(bool[type])
  phi = frame_count * 0.01
  builder.add_shape(Circle.new(mouse_x, mouse_y, 50))
  builder.add_shape(Ellipse.new(150, 130 + sin(phi) * 50, 120, 60))
  builder.add_shape(Rect.new(200 + sin(phi * 13 / 8) * 50, 180, 100, 100))
  builder.add_shape(Triangle2D.create_equilateral_from(
    TVec2D.new(50 + sin(phi * 15 / 13) * 50, 200), TVec2D.new(300, 200))
  )
  builder.add_shape(
    Circle.new(100, 300, 50 + 30 * sin(phi * 21 / 15)).toPolygon2D(6)
  )
  fill(125)
  stroke(255, 0, 0)
  @polies = builder.compute_shapes
  polies.each { |p| gfx.polygon2D(p) }
end

def settings
  size(400, 400)
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
toxiclibs-1.0.0 examples/boolean_shapes.rb
toxiclibs-0.9.3 examples/boolean_shapes.rb
toxiclibs-0.9.2 examples/boolean_shapes.rb