forked from ruby2d/ruby2d
-
Notifications
You must be signed in to change notification settings - Fork 0
/
contains.rb
32 lines (26 loc) · 914 Bytes
/
contains.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
require 'ruby2d'
set title: "Ruby 2D — Contains", height: 350
if RUBY_ENGINE == 'opal'
media = "../test/media"
font = "sans-serif"
else
media = "media"
font = "#{media}/bitstream_vera/vera.ttf"
end
objects = []
objects.push Square.new(x: 50, y: 50, size: 100)
objects.push Rectangle.new(x: 200, y: 50, width: 100, height: 75)
objects.push Quad.new(x1: 350, y1: 50, x2: 500, y2: 75, x3: 450, y3: 150, x4: 375, y4: 125)
objects.push Triangle.new(x1: 550, y1: 50, x2: 600, y2: 125, x3: 500, y3: 150)
objects.push Line.new(x1: 225, y1: 175, x2: 375, y2: 225, width: 20)
objects.push Image.new(x: 50, y: 200, path: "#{media}/colors.png")
objects.push Text.new(x: 450, y: 200, text: "Hello", size: 50, font: font)
on :key_down do |event|
close if event.key == 'escape'
end
update do
objects.each do |o|
o.contains?(get(:mouse_x), get(:mouse_y)) ? o.opacity = 1.0 : o.opacity = 0.5
end
end
show