1
1
require 'picrate'
2
2
3
- # The sketch class
4
3
class HypeSwarm < Processing ::App
5
- load_library :hype , :color_group
6
- java_import 'hype.interfaces.HLocatable'
7
- HYPE = %w[ H HDrawablePool HCanvas HRect ] . freeze
8
- hype_format = 'hype.%s'
9
- HYPE . each { |klass | java_import format ( hype_format , klass ) }
10
- EXTENDED = %w[
11
- colorist.HColorPool behavior.HSwarm behavior.HTween behavior.HTimer
12
- ] . freeze
13
- hype_extended_format = 'hype.extended.%s'
14
- EXTENDED . each { |klass | java_import format ( hype_extended_format , klass ) }
4
+ load_library :hype
5
+ include_package 'hype'
6
+ # Access through Hype namespace
7
+ module Hype
8
+ java_import 'hype.extended.behavior.HSwarm'
9
+ java_import 'hype.extended.behavior.HTimer'
10
+ java_import 'hype.extended.behavior.HTween'
11
+ java_import 'hype.extended.colorist.HColorPool'
12
+ java_import 'hype.interfaces.HLocatable'
13
+ end
14
+
15
+ PALETTE = %w[ #FFFFFF #F7F7F7 #ECECEC #333333 #0095a8 #00616f #FF3300 #FF6600 ] . freeze
16
+ PALETTE2 = %w[ #242424 #111111 #ECECEC ] . freeze
17
+ include Hype
15
18
16
- PALETTE = %w( #FFFFFF #F7F7F7 #ECECEC #333333 #0095a8 #00616f #FF3300 #FF6600 ) . freeze
17
- PALETTE2 = %w( #242424 #111111 #ECECEC ) . freeze
18
19
attr_reader :swarm , :canvas , :colors , :pool , :tween , :count
19
20
20
21
def settings
@@ -25,63 +26,63 @@ def setup
25
26
sketch_title 'Hype Swarm'
26
27
H . init ( self )
27
28
@count = 0
28
- color_group = ColorGroup . from_web_array ( PALETTE . to_java ( :string ) )
29
- @colors = HColorPool . new ( color_group . colors )
30
- colors2 = ColorGroup . from_web_array ( PALETTE2 . to_java ( :string ) ) . colors
29
+ @colors = HColorPool . new ( web_to_color_array ( PALETTE ) )
30
+ colors2 = web_to_color_array ( PALETTE2 )
31
31
H . background ( colors2 [ 0 ] )
32
32
H . add ( @canvas = HCanvas . new . auto_clear ( false ) . fade ( 40 ) )
33
33
@swarm = HSwarm . new
34
- . speed ( 4 )
35
- . turn_ease ( 0.1 )
36
- . twitch ( 15 )
37
- . idle_goal ( width / 2 , height / 2 )
34
+ . speed ( 4 )
35
+ . turn_ease ( 0.1 )
36
+ . twitch ( 15 )
37
+ . idle_goal ( width / 2 , height / 2 )
38
38
@pool = HDrawablePool . new ( 10 )
39
39
pool . auto_add_to_stage
40
- . add ( HRect . new ( 10 ) . rounding ( 5 ) )
41
- . on_create do |obj |
42
- obj . stroke_weight ( 2 )
43
- . stroke ( colors2 [ 2 ] )
44
- . fill ( colors2 [ 1 ] )
45
- . loc ( rand ( 100 ..540 ) , rand ( 100 ..540 ) )
46
- . anchor_at ( H ::CENTER )
47
- . rotation ( 45 )
48
- @tween = HTween . new
49
- . target ( obj ) . property ( H ::LOCATION )
50
- . start ( obj . x , obj . y )
51
- . end ( rand ( 0 ..width ) , rand ( 0 ..height ) )
52
- . ease ( 0.01 )
53
- . spring ( 0.9 )
54
- on_anim = proc do
55
- tween . start ( obj . x , obj . y )
56
- . end ( rand ( 100 ..540 ) , rand ( 100 ..540 ) )
57
- . ease ( 0.01 )
58
- . spring ( 0.9 )
59
- . register
60
- end
40
+ . add ( HRect . new ( 10 ) . rounding ( 5 ) )
41
+ . on_create do |obj |
42
+ obj . stroke_weight ( 2 )
43
+ . stroke ( colors2 [ 1 ] )
44
+ . fill ( colors2 [ 2 ] )
45
+ . loc ( rand ( 100 ..540 ) , rand ( 100 ..540 ) )
46
+ . anchor_at ( H ::CENTER )
47
+ . rotation ( 45 )
48
+ @tween = HTween . new
49
+ . target ( obj ) . property ( H ::LOCATION )
50
+ . start ( obj . x , obj . y )
51
+ . end ( rand ( 0 ..width ) , rand ( 0 ..height ) )
52
+ . ease ( 0.01 )
53
+ . spring ( 0.9 )
54
+ on_anim = proc do
55
+ tween . start ( obj . x , obj . y )
56
+ . end ( rand ( 100 ..540 ) , rand ( 100 ..540 ) )
57
+ . ease ( 0.01 )
58
+ . spring ( 0.9 )
59
+ . register
60
+ end
61
61
HTimer . new . interval ( 2_000 ) . callback ( &on_anim )
62
62
end
63
- . request_all
63
+ . request_all
64
64
end
65
65
66
66
def draw
67
67
if count < 100
68
68
swarm . add_target (
69
69
canvas . add (
70
70
HRect . new ( 8 , 2 )
71
- . rounding ( 4 )
72
- . anchor_at ( H ::CENTER )
73
- . no_stroke
74
- . fill ( colors . get_color )
71
+ . rounding ( 4 )
72
+ . anchor_at ( H ::CENTER )
73
+ . no_stroke
74
+ . fill ( colors . get_color )
75
75
)
76
76
)
77
77
@count += 1
78
78
end
79
79
H . draw_stage
80
80
it = swarm . goals . iterator
81
- while it . has_next?
81
+ while it . has_next
82
82
it . remove
83
- # it.next
83
+ it . next
84
84
end
85
+
85
86
pool . each do |d |
86
87
swarm . add_goal ( d . x , d . y )
87
88
end
0 commit comments