Skip to content

Commit 67b6590

Browse files
committed
proximity example
1 parent 255a2b5 commit 67b6590

1 file changed

Lines changed: 62 additions & 0 deletions

File tree

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
# encoding: utf-8
2+
load_library :hype
3+
include_package 'hype'
4+
java_import 'hype.extended.behavior.HProximity'
5+
java_import 'hype.extended.behavior.HOscillator'
6+
7+
PALETTE = %w(#242424 #00FF00 #FF3300 #4D4D4D).freeze
8+
KEY = %i(background fill_one fill_two stroke).freeze
9+
10+
attr_reader :colors
11+
12+
def settings
13+
size(640, 640)
14+
end
15+
16+
def setup
17+
sketch_title 'Hype Proximity'
18+
@colors = KEY.zip(web_to_color_array(PALETTE)).to_h
19+
H.init(self)
20+
H.background(colors[:background])
21+
canvas = H.add(HCanvas.new.auto_clear(false).fade(5))
22+
r1 = HRect.new(5)
23+
r1.no_stroke
24+
.fill(colors[:fill_one])
25+
.loc(width/2, height/2)
26+
.rotate(45)
27+
.anchor_at(H::CENTER)
28+
canvas.add(r1)
29+
r2 = HRect.new(5, 10)
30+
.rounding(4)
31+
r2.no_stroke
32+
.fill(colors[:fill_two])
33+
.x(40)
34+
.y(height / 2)
35+
.anchor_at(H::CENTER)
36+
canvas.add(r2)
37+
HProximity.new
38+
.target(r2)
39+
.neighbor(r1)
40+
.property(H::HEIGHT)
41+
.spring(0.99)
42+
.ease(0.7)
43+
.min(10)
44+
.max(200)
45+
.radius(250)
46+
HOscillator.new
47+
.target(r2)
48+
.property(H::X)
49+
.range(40, 600)
50+
.speed(5)
51+
.freq(0.5)
52+
.current_step(-180)
53+
end
54+
55+
def draw
56+
H.draw_stage
57+
# outline to show area of proximity
58+
ellipse_mode(CENTER)
59+
stroke(colors[:stroke])
60+
no_fill
61+
ellipse(width / 2, height / 2, 500, 500)
62+
end

0 commit comments

Comments
 (0)