Sha256: b0e1ceb60657542606f471fa5af8136bf7a936a2c0bc376fa1aa6ad34548acd1

Contents?: true

Size: 880 Bytes

Versions: 6

Compression:

Stored size: 880 Bytes

Contents

# The bubble library, include BubbleStruct

class Bubble
  include Processing::Proxy

  attr_reader :x, :y, :diameter, :name, :over

  # Create  the Bubble
  def initialize(x, y, diameter, name)
    @x = x
    @y = y
    @diameter = diameter
    @name = name
    @over = false
  end

  # Checking if mouse is over the Bubble
  def rollover(px, py)
    d = dist(px,py,x,y)
    @over = (d < diameter/2)? true : false
  end

  # Display the Bubble
  def display
    stroke(0)
    stroke_weight(2)
    noFill
    ellipse(x, y, diameter, diameter)
    if (over)
      fill(0)
      text_align(CENTER)
      text(name, x, y + diameter / 2 + 20)
    end
  end

  def to_hash
    {'position' => {'x' => x, 'y' => y}, 'diameter' => diameter, 'label' => name}
  end

  def to_struct
    BubbleStruct.new(x, y, diameter, name)
  end
end

BubbleStruct = Struct.new(:x, :y, :diameter, :label)

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
ruby-processing-2.6.3 samples/processing_app/topics/advanced_data/library/bubble/bubble.rb
ruby-processing-2.6.2 samples/processing_app/topics/advanced_data/library/bubble/bubble.rb
ruby-processing-2.6.1 samples/processing_app/topics/advanced_data/library/bubble/bubble.rb
ruby-processing-2.6.0 samples/processing_app/topics/advanced_data/library/bubble/bubble.rb
ruby-processing-2.5.1 samples/processing_app/topics/advanced_data/library/bubble/bubble.rb
ruby-processing-2.5.0 samples/processing_app/topics/advanced_data/library/bubble/bubble.rb