11require 'picrate'
22
3- # The sketch class
43class 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
1518
16- PALETTE = %w( #FFFFFF #F7F7F7 #ECECEC #333333 #0095a8 #00616f #FF3300 #FF6600 ) . freeze
17- PALETTE2 = %w( #242424 #111111 #ECECEC ) . freeze
1819 attr_reader :swarm , :canvas , :colors , :pool , :tween , :count
1920
2021 def settings
@@ -25,63 +26,63 @@ def setup
2526 sketch_title 'Hype Swarm'
2627 H . init ( self )
2728 @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 )
3131 H . background ( colors2 [ 0 ] )
3232 H . add ( @canvas = HCanvas . new . auto_clear ( false ) . fade ( 40 ) )
3333 @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 )
3838 @pool = HDrawablePool . new ( 10 )
3939 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
6161 HTimer . new . interval ( 2_000 ) . callback ( &on_anim )
6262 end
63- . request_all
63+ . request_all
6464 end
6565
6666 def draw
6767 if count < 100
6868 swarm . add_target (
6969 canvas . add (
7070 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 )
7575 )
7676 )
7777 @count += 1
7878 end
7979 H . draw_stage
8080 it = swarm . goals . iterator
81- while it . has_next?
81+ while it . has_next
8282 it . remove
83- # it.next
83+ it . next
8484 end
85+
8586 pool . each do |d |
8687 swarm . add_goal ( d . x , d . y )
8788 end
0 commit comments