Skip to content

Commit 6bdcdb8

Browse files
committed
cool use of instance_eval
1 parent 082aa84 commit 6bdcdb8

1 file changed

Lines changed: 43 additions & 0 deletions

File tree

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
load_library :hype
2+
include_package 'hype'
3+
java_import 'hype.extended.layout.HGridLayout'
4+
# string color array
5+
PALETTE = %w(
6+
CLEAR
7+
WHITE
8+
BLACK
9+
LGREY
10+
GREY
11+
DGREY
12+
RED
13+
GREEN
14+
BLUE
15+
CYAN
16+
YELLOW
17+
MAGENTA
18+
).freeze
19+
# format string see fill below
20+
FSTRING = 'H::%s'.freeze
21+
22+
def settings
23+
size(640, 640)
24+
end
25+
26+
def setup
27+
sketch_title 'Color Presets'
28+
H.init(self)
29+
H.background(color('#242424'))
30+
grid = HGridLayout.new(3).spacing(210, 157).start_loc(10, 10)
31+
PALETTE.each do |col|
32+
H.add(HRect.new(200, 147))
33+
.stroke_weight(3)
34+
.stroke(H::BLACK, 150.0) # Note we call hype constants
35+
.fill(instance_eval(format(FSTRING, col))) # and using eval
36+
.loc(grid.get_next_point)
37+
end
38+
end
39+
40+
def draw
41+
H.draw_stage
42+
no_loop
43+
end

0 commit comments

Comments
 (0)