Skip to content

Commit f54f829

Browse files
committed
HRotate example
1 parent 8666d40 commit f54f829

1 file changed

Lines changed: 38 additions & 0 deletions

File tree

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# encoding: utf-8
2+
load_library :hype
3+
include_package 'hype'
4+
java_import 'hype.extended.behavior.HRotate'
5+
attr_reader :box_x, :box_y, :box_z, :colors
6+
PALETTE = %w(#242424 #FF3300 #00CC00).freeze
7+
8+
def settings
9+
size(640, 640, P3D)
10+
end
11+
12+
def setup
13+
sketch_title 'HRotate'
14+
H.init(self)
15+
@colors = web_to_color_array(PALETTE)
16+
H.background(colors[0])
17+
H.use3D(true)
18+
# rotate on the x axis
19+
H.add(@box_x = HBox.new).size(75).no_stroke.fill(colors[1]).loc((width / 2) - 175, height / 2)
20+
HRotate.new.target(box_x).speed_x(1).speed_y(0).speed_z(0)
21+
# rotate on the y axis
22+
H.add(@box_y = HBox.new).size(75).no_stroke.fill(colors[1]).loc(width / 2, height / 2)
23+
HRotate.new.target(box_y).speed_x(0).speed_y(1).speed_z(0)
24+
# rotate on the z axis
25+
H.add(@box_z = HBox.new).size(75).no_stroke.fill(colors[1]).loc((width / 2) + 175, height / 2)
26+
HRotate.new.target(box_z).speed_x(0).speed_y(0).speed_z(1)
27+
end
28+
29+
def draw
30+
lights
31+
H.draw_stage
32+
# visualize axis rotation rods
33+
no_fill
34+
stroke(colors[2])
35+
line((width / 2) - (175 + 75), height / 2, 0, (width / 2) - (175 - 75), height / 2, 0) # x axis
36+
line(width / 2, (height / 2) - 75, 0, width / 2, (height / 2) + 75, 0) # y axis
37+
line((width / 2) + 175, height / 2, -100 ,(width / 2) + 175, height / 2, + 100) # z axis
38+
end

0 commit comments

Comments
 (0)