Sha256: 5a46404639d56087baab1e2ac3ccc4e3c37ebfe62f0ec792b137b4ad40458c3b
Contents?: true
Size: 1.12 KB
Versions: 10
Compression:
Stored size: 1.12 KB
Contents
# Click on the box and drag it across the screen. def setup size 640, 360 smooth 4 @block = {x: width/2.0, y: height/2.0} @block_diff = {x: 0.0, y: 0.0} @locked = false @over_block = false @block_width = 75 rect_mode RADIUS end def draw background 0 fill 153 if (mouse_x > @block[:x] - @block_width && # Test if the cursor is over the box mouse_x < @block[:x] + @block_width && mouse_y > @block[:y] - @block_width && mouse_y < @block[:y] + @block_width ) @over_block = true stroke 255 fill 255 if block_locked? else @over_block = false stroke 153 end # Draw the box rect @block[:x], @block[:y], @block_width, @block_width end def block_locked? @block_locked end def over_block? @over_block end def mouse_pressed if over_block? @block_locked = true fill 255 else @block_locked = false end @block_diff[:x] = mouse_x - @block[:x] @block_diff[:y] = mouse_y - @block[:y] end def mouse_dragged if block_locked? @block[:x] = mouse_x - @block_diff[:x] @block[:y] = mouse_y - @block_diff[:y] end end def mouse_released @block_locked = false end
Version data entries
10 entries across 10 versions & 1 rubygems