Sha256: 22623e714f5fe55128c39dc4898e439e856c18d999457c40300eee058e358e12

Contents?: true

Size: 1011 Bytes

Versions: 4

Compression:

Stored size: 1011 Bytes

Contents

load_library :guido
import 'de.bezier.guido'

def setup
  size 400, 400
  Interactive.make self
  @slider = Slider.new  10, height - 20, width - 20, 10
end

def draw
  background 180
  fill 255
  v = 10 + @slider.value * (width - 30)
  ellipse width / 2, height / 2, v, v
end

class Slider < ActiveElement
  
  attr_reader :value
  
  def initialize (x, y, w, h)
    super x, y, w, h
    @x = x
    @y = y
    @width = w
    @height = h
    @hover = false
    @value = 0
    @value_x = x
  end
  
  def mouseEntered(mx, my)
    @hover = true
  end
  
  def mouseExited(mx, my)
    @hover = false
  end
  
  def mouseDragged(mx, my, dx, dy)
    @value_x = mx - @height / 2    
    @value_x = @x if (@value_x < @x) 
    @value_x = @x + @width - @height if (@value_x > @x + @width - @height)    
    @value = map(@value_x, @x, @x + @width - @height, 0, 1)
  end
  
  def draw
    no_stroke
    fill @hover ? 220 : 150
    rect @x, @y, @width, @height
    fill 120
    rect @value_x, @y, @height, @height
  end
end 

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
ruby-processing-2.6.3 samples/external_library/java_processing/guido/slider.rb
ruby-processing-2.6.2 samples/external_library/java_processing/guido/slider.rb
ruby-processing-2.6.1 samples/external_library/java_processing/guido/slider.rb
ruby-processing-2.6.0 samples/external_library/java_processing/guido/slider.rb