From d4505d63eba991160f6ea633df04f78aca48969b Mon Sep 17 00:00:00 2001 From: Martin Prout Date: Mon, 21 Oct 2019 13:13:05 +0100 Subject: [PATCH] various eb color fixes --- demo/arc_tesselation.rb | 4 +- demo/fading.rb | 9 +- demo/recursive_pentagon.rb | 3 +- external_library/java/hype/color_pool.rb | 6 +- .../java/hype/color_pool_wovns.rb | 4 +- external_library/java/hype/h_orbiter.rb | 4 +- external_library/java/hype/h_oscillator.rb | 2 +- external_library/java/hype/h_rotate.rb | 2 +- external_library/java/hype/h_sprite.rb | 2 +- external_library/java/hype/hype_swarm.rb | 97 ++++++++++--------- external_library/java/hype/magnetic_field.rb | 6 +- external_library/java/hype/polar_layout.rb | 3 +- external_library/java/hype/proximity.rb | 3 +- external_library/java/hype/random_trigger.rb | 4 +- external_library/java/hype/rotate_gear.rb | 4 +- external_library/java/hype/tween_example.rb | 82 ++++++++-------- .../java/hype/tween_lambda_example.rb | 3 +- 17 files changed, 115 insertions(+), 123 deletions(-) diff --git a/demo/arc_tesselation.rb b/demo/arc_tesselation.rb index f3824c7..2d314d5 100644 --- a/demo/arc_tesselation.rb +++ b/demo/arc_tesselation.rb @@ -21,7 +21,7 @@ def setup sketch_title 'Arc Tesselation' # create a java primitive array of signed int # @cols = web_to_color_array(PALETTE) - @group = ColorGroup.from_web_array(PALETTE.to_java(:string)) + @group = ColorGroup.from_web_array(PALETTE) @cols = group.colors stroke_weight 1.5 stroke_cap SQUARE @@ -72,8 +72,6 @@ def mouse_pressed puts group.ruby_string # prints out current web colors as an array of String end - - def key_typed case key when 'c', 'C' diff --git a/demo/fading.rb b/demo/fading.rb index da9a2f2..86cb4ea 100644 --- a/demo/fading.rb +++ b/demo/fading.rb @@ -5,13 +5,12 @@ class Fading < Processing::App NUM_ELEM = 100 PALETTE = %w[#F58F12 #0B9EE7 #4EA731 #F4D910 #F334E3 #202020] - attr_reader :my_dots, :frm, :save_anim, :group + attr_reader :my_dots, :frm, :save_anim, :colors def setup sketch_title 'Fading Arcs' - @group = ColorGroup.from_web_array(PALETTE.to_java(:string) - colors = group.colors - background(group.last) + @colors = web_to_color_array(PALETTE) + background(colors.last) no_stroke @save_anim = false @my_dots = (0..NUM_ELEM).map do @@ -25,7 +24,7 @@ def setup end def draw - fill(group.last, 10) + fill(colors.last, 10) rect(0, 0, width, height) my_dots.each(&:display) return unless save_anim diff --git a/demo/recursive_pentagon.rb b/demo/recursive_pentagon.rb index 7f59b28..a9d70c7 100644 --- a/demo/recursive_pentagon.rb +++ b/demo/recursive_pentagon.rb @@ -9,8 +9,7 @@ def setup sketch_title 'Recursive Pentagons' @strut_factor = 0.2 @renderer = GfxRender.new g # so we can send Vec2D :to_vertex - group = ColorGroup.from_web_array(PALETTE.to_java(:string)) - @cols = group.colors + @cols = web_to_color_array(PALETTE) no_loop end diff --git a/external_library/java/hype/color_pool.rb b/external_library/java/hype/color_pool.rb index fb2053f..d93b43f 100644 --- a/external_library/java/hype/color_pool.rb +++ b/external_library/java/hype/color_pool.rb @@ -8,7 +8,7 @@ class ColorPool < Processing::App end %w[colorist.HColorPool layout.HGridLayout].freeze.each do |klass| java_import "hype.extended.#{klass}" - end + end PALETTE = %w[#FFFFFF #F7F7F7 #ECECEC #0095A8 #00616F #333333 #FF3300 #FF6600].freeze @@ -20,8 +20,8 @@ def setup sketch_title 'Color Pool' H.init(self) H.background(color('#242424')) - color_group = ColorGroup.from_web_array(PALETTE.to_java(:string) - colors = HColorPool.new(color_group.colors) + + colors = HColorPool.new(web_to_color_array(PALETTE)) pool = HDrawablePool.new(15_876) pool.auto_add_to_stage .add(HRect.new(5)) diff --git a/external_library/java/hype/color_pool_wovns.rb b/external_library/java/hype/color_pool_wovns.rb index ce40a5d..4b08bad 100644 --- a/external_library/java/hype/color_pool_wovns.rb +++ b/external_library/java/hype/color_pool_wovns.rb @@ -21,8 +21,8 @@ def setup sketch_title 'Color Pool Wovns' H.init(self) H.background(color('#242424')) - group = ColorGroup.from_web_array(PALETTE.to_java(:string)) - colors = HColorPool.new(group.colors) + group = web_to_color_array(PALETTE) + colors = HColorPool.new(web_to_color_array(PALETTE)) pool = HDrawablePool.new(15_876) pool.auto_add_to_stage .add(HRect.new(50)) diff --git a/external_library/java/hype/h_orbiter.rb b/external_library/java/hype/h_orbiter.rb index 5b9d97f..bcf1567 100644 --- a/external_library/java/hype/h_orbiter.rb +++ b/external_library/java/hype/h_orbiter.rb @@ -20,7 +20,7 @@ def settings def setup sketch_title('HOrbiter Example') - group = ColorGroup.from_web_array(PALETTE.to_java(:string)) + group = web_to_color_array(PALETTE) H.init(self) H.background(color('#242424')) H.use3D(true) @@ -34,7 +34,7 @@ def setup @pool = HDrawablePool.new(100) pool.autoAddToStage .add(HSphere.new) - .colorist(HColorPool.new(group.colors).fill_only) + .colorist(HColorPool.new(web_to_color_array(PALETTE)).fill_only) .on_create do |obj| ran_size = 10 + (rand(0..3) * 7) obj.size(ran_size).stroke_weight(0).no_stroke.anchor_at(H::CENTER) diff --git a/external_library/java/hype/h_oscillator.rb b/external_library/java/hype/h_oscillator.rb index 1721f69..685c928 100644 --- a/external_library/java/hype/h_oscillator.rb +++ b/external_library/java/hype/h_oscillator.rb @@ -23,7 +23,7 @@ def setup .cols(90) pool.auto_add_to_stage .add(HRect.new(6).rounding(10).anchor_at(H::CENTER).no_stroke) - .colorist(HColorPool.new(ColorGroup.from_web_array(PALETTE.to_java(:string)).colors)) + .colorist(HColorPool.new(web_to_color_array(PALETTE))) .layout(layout) .on_create do |obj| i = pool.current_index diff --git a/external_library/java/hype/h_rotate.rb b/external_library/java/hype/h_rotate.rb index ffffd25..0105d72 100644 --- a/external_library/java/hype/h_rotate.rb +++ b/external_library/java/hype/h_rotate.rb @@ -15,7 +15,7 @@ def settings def setup sketch_title 'HRotate' H.init(self) - @colors = ColorGroup.from_web_array(PALETTE.to_java(:string)).colors + @colors = web_to_color_array(PALETTE) H.background(colors[0]) H.use3D(true) # rotate on the x axis diff --git a/external_library/java/hype/h_sprite.rb b/external_library/java/hype/h_sprite.rb index cebb795..4d77ef8 100644 --- a/external_library/java/hype/h_sprite.rb +++ b/external_library/java/hype/h_sprite.rb @@ -25,7 +25,7 @@ def setup .add(HSprite.new(50,50).texture(HImage.new(data_path('tex1.png')))) .add(HSprite.new(50,50).texture(HImage.new(data_path('tex2.png')))) .add(HSprite.new(50,50).texture(HImage.new(data_path('tex3.png')))) - .colorist(HColorPool.new(ColorGroup.from_web_array(PALETTE.to_java(:string)).colors).fill_only) + .colorist(HColorPool.new(web_to_color_array(PALETTE)).fill_only) .on_create do |obj| i = pool.current_index obj.anchorAt(H::CENTER).rotation(45) diff --git a/external_library/java/hype/hype_swarm.rb b/external_library/java/hype/hype_swarm.rb index fae52f9..552e0dd 100644 --- a/external_library/java/hype/hype_swarm.rb +++ b/external_library/java/hype/hype_swarm.rb @@ -1,20 +1,21 @@ require 'picrate' -# The sketch class class HypeSwarm < Processing::App - load_library :hype, :color_group - java_import 'hype.interfaces.HLocatable' - HYPE = %w[H HDrawablePool HCanvas HRect].freeze - hype_format = 'hype.%s' - HYPE.each { |klass| java_import format(hype_format, klass) } - EXTENDED = %w[ - colorist.HColorPool behavior.HSwarm behavior.HTween behavior.HTimer - ].freeze - hype_extended_format = 'hype.extended.%s' - EXTENDED.each { |klass| java_import format(hype_extended_format, klass) } + load_library :hype + include_package 'hype' + # Access through Hype namespace + module Hype + java_import 'hype.extended.behavior.HSwarm' + java_import 'hype.extended.behavior.HTimer' + java_import 'hype.extended.behavior.HTween' + java_import 'hype.extended.colorist.HColorPool' + java_import 'hype.interfaces.HLocatable' + end + + PALETTE = %w[#FFFFFF #F7F7F7 #ECECEC #333333 #0095a8 #00616f #FF3300 #FF6600].freeze + PALETTE2 = %w[#242424 #111111 #ECECEC].freeze + include Hype - PALETTE = %w(#FFFFFF #F7F7F7 #ECECEC #333333 #0095a8 #00616f #FF3300 #FF6600).freeze - PALETTE2 = %w(#242424 #111111 #ECECEC).freeze attr_reader :swarm, :canvas, :colors, :pool, :tween, :count def settings @@ -25,42 +26,41 @@ def setup sketch_title 'Hype Swarm' H.init(self) @count = 0 - color_group = ColorGroup.from_web_array(PALETTE.to_java(:string)) - @colors = HColorPool.new(color_group.colors) - colors2 = ColorGroup.from_web_array(PALETTE2.to_java(:string)).colors + @colors = HColorPool.new(web_to_color_array(PALETTE)) + colors2 = web_to_color_array(PALETTE2) H.background(colors2[0]) H.add(@canvas = HCanvas.new.auto_clear(false).fade(40)) @swarm = HSwarm.new - .speed(4) - .turn_ease(0.1) - .twitch(15) - .idle_goal(width / 2, height / 2) + .speed(4) + .turn_ease(0.1) + .twitch(15) + .idle_goal(width / 2, height / 2) @pool = HDrawablePool.new(10) pool.auto_add_to_stage - .add(HRect.new(10).rounding(5)) - .on_create do |obj| - obj.stroke_weight(2) - .stroke(colors2[2]) - .fill(colors2[1]) - .loc(rand(100..540), rand(100..540)) - .anchor_at(H::CENTER) - .rotation(45) - @tween = HTween.new - .target(obj).property(H::LOCATION) - .start(obj.x, obj.y) - .end(rand(0..width), rand(0..height)) - .ease(0.01) - .spring(0.9) - on_anim = proc do - tween.start(obj.x, obj.y) - .end(rand(100..540), rand(100..540)) - .ease(0.01) - .spring(0.9) - .register - end + .add(HRect.new(10).rounding(5)) + .on_create do |obj| + obj.stroke_weight(2) + .stroke(colors2[1]) + .fill(colors2[2]) + .loc(rand(100..540), rand(100..540)) + .anchor_at(H::CENTER) + .rotation(45) + @tween = HTween.new + .target(obj).property(H::LOCATION) + .start(obj.x, obj.y) + .end(rand(0..width), rand(0..height)) + .ease(0.01) + .spring(0.9) + on_anim = proc do + tween.start(obj.x, obj.y) + .end(rand(100..540), rand(100..540)) + .ease(0.01) + .spring(0.9) + .register + end HTimer.new.interval(2_000).callback(&on_anim) end - .request_all + .request_all end def draw @@ -68,20 +68,21 @@ def draw swarm.add_target( canvas.add( HRect.new(8, 2) - .rounding(4) - .anchor_at(H::CENTER) - .no_stroke - .fill(colors.get_color) + .rounding(4) + .anchor_at(H::CENTER) + .no_stroke + .fill(colors.get_color) ) ) @count += 1 end H.draw_stage it = swarm.goals.iterator - while it.has_next? + while it.has_next it.remove - # it.next + it.next end + pool.each do |d| swarm.add_goal(d.x, d.y) end diff --git a/external_library/java/hype/magnetic_field.rb b/external_library/java/hype/magnetic_field.rb index c6ea2b2..213f0b5 100644 --- a/external_library/java/hype/magnetic_field.rb +++ b/external_library/java/hype/magnetic_field.rb @@ -1,13 +1,13 @@ require 'picrate' -# The sketch class class MagneticField < Processing::App load_library :hype - %w[H HDrawablePool HRect HShape].freeze.each do |klass| + %w[H HRect HShape HDrawablePool].freeze.each do |klass| java_import "hype.#{klass}" end - %w[layout.HGridLayout behavior.HMagneticField behavior.HSwarm].freeze.each do |klass| + + %w[behavior.HMagneticField behavior.HSwarm layout.HGridLayout].freeze.each do |klass| java_import "hype.extended.#{klass}" end diff --git a/external_library/java/hype/polar_layout.rb b/external_library/java/hype/polar_layout.rb index 86bbfd0..ff8a7f8 100644 --- a/external_library/java/hype/polar_layout.rb +++ b/external_library/java/hype/polar_layout.rb @@ -21,8 +21,7 @@ def settings def setup sketch_title 'Polar Layout' H.init(self) - group = ColorGroup.from_web_array(PALETTE.to_java(:string)) - @colors = HColorPool.new(group.colors) + @colors = HColorPool.new(web_to_color_array(PALETTE)) H.background(group.last) H.use3D(true) @ranSeedNum = 1 diff --git a/external_library/java/hype/proximity.rb b/external_library/java/hype/proximity.rb index d697901..9fbcecd 100644 --- a/external_library/java/hype/proximity.rb +++ b/external_library/java/hype/proximity.rb @@ -22,8 +22,7 @@ def settings def setup sketch_title 'Hype Proximity' - group = ColorGroup.from_web_array(PALETTE.to_java(:string)) - @colors = KEY.zip(group.colors).to_h + @colors = KEY.zip(web_to_color_array(PALETTE)).to_h H.init(self) H.background(colors[:background]) canvas = H.add(HCanvas.new.auto_clear(false).fade(5)) diff --git a/external_library/java/hype/random_trigger.rb b/external_library/java/hype/random_trigger.rb index dce8419..7ba40f2 100644 --- a/external_library/java/hype/random_trigger.rb +++ b/external_library/java/hype/random_trigger.rb @@ -20,8 +20,8 @@ def settings def setup sketch_title 'Random Trigger' - group = ColorGroup.from_web_array(PALETTE.to_java(:string)) - col = KEY.zip(group.colors).to_h + group = web_to_color_array(PALETTE) + col = KEY.zip(web_to_color_array(PALETTE)).to_h H.init(self) H.background(col[:background]) # Create a new randTrigger with a 1 in 15 chance diff --git a/external_library/java/hype/rotate_gear.rb b/external_library/java/hype/rotate_gear.rb index e16f42b..c9fe9cd 100644 --- a/external_library/java/hype/rotate_gear.rb +++ b/external_library/java/hype/rotate_gear.rb @@ -17,8 +17,8 @@ def settings def setup sketch_title 'HRotate Gears' H.init(self) - color_group = ColorGroup.from_web_array(PALETTE.to_java(:string)) - @colors = color_group.colors + color_group = web_to_color_array(PALETTE) + @colors = web_to_color_array(PALETTE) H.background(colors[0]) svg1 = HShape.new(data_path('cog_sm.svg')) svg2 = HShape.new(data_path('cog_lg.svg')) diff --git a/external_library/java/hype/tween_example.rb b/external_library/java/hype/tween_example.rb index fe15785..3e9a6ba 100644 --- a/external_library/java/hype/tween_example.rb +++ b/external_library/java/hype/tween_example.rb @@ -12,53 +12,51 @@ class TweenExample < Processing::App end java_import 'hype.extended.colorist.HColorPool' + PALETTE = %w[#FFFFFF #F7F7F7 #ECECEC #333333 #0095a8 #00616f #FF3300 #FF6600].freeze -PALETTE = %w[#FFFFFF #F7F7F7 #ECECEC #333333 #0095a8 #00616f #FF3300 #FF6600].freeze - -def settings - size(640, 640) -end + def settings + size(640, 640) + end -def setup - sketch_title('Tween Example') - H.init(self) - H.background(color('#000000')) - group = ColorGroup.from_web_array(PALETTE.to_java(:string)) - colors = HColorPool.new(group.colors) - canvas = HCanvas.new - H.add(canvas).autoClear(false).fade(1) - tween_trigger = HRandomTrigger.new(1.0 / 6) - tween_trigger.callback do - r = canvas.add(HRect.new(25 + (rand(0..5) * 25)).rounding(10)) - .stroke_weight(1) - .stroke(colors.getColor) - .fill(color('#000000'), 25) - .loc(rand(0..width), rand(0..height)) - .anchor_at(H::CENTER) - tween1 = HTween.new - .target(r).property(H::SCALE) - .start(0).end(1).ease(0.03).spring(0.95) - tween2 = HTween.new - .target(r).property(H::ROTATION) - .start(-90).end(90).ease(0.01).spring(0.7) - tween3 = HTween.new - .target(r).property(H::ALPHA) - .start(0).end(255).ease(0.1).spring(0.95) - r.scale(0).rotation(-90).alpha(0) - timer = HTimer.new.interval(250).unregister - tween3.callback { timer.register } - timer.callback do - timer.unregister - tween1.start(1).end(2).ease(0.01).spring(0.99).register - tween2.start(90).end(-90).ease(0.01).spring(0.7).register - tween3.start(255).end(0).ease(0.01).spring(0.95).register.callback { canvas.remove(r) } + def setup + sketch_title('Tween Example') + H.init(self) + H.background(color('#000000')) + colors = HColorPool.new(web_to_color_array(PALETTE)) + canvas = HCanvas.new + H.add(canvas).autoClear(false).fade(1) + tween_trigger = HRandomTrigger.new(1.0 / 6) + tween_trigger.callback do + r = canvas.add(HRect.new(25 + (rand(0..5) * 25)).rounding(10)) + .stroke_weight(1) + .stroke(colors.getColor) + .fill(color('#000000'), 25) + .loc(rand(0..width), rand(0..height)) + .anchor_at(H::CENTER) + tween1 = HTween.new + .target(r).property(H::SCALE) + .start(0).end(1).ease(0.03).spring(0.95) + tween2 = HTween.new + .target(r).property(H::ROTATION) + .start(-90).end(90).ease(0.01).spring(0.7) + tween3 = HTween.new + .target(r).property(H::ALPHA) + .start(0).end(255).ease(0.1).spring(0.95) + r.scale(0).rotation(-90).alpha(0) + timer = HTimer.new.interval(250).unregister + tween3.callback { timer.register } + timer.callback do + timer.unregister + tween1.start(1).end(2).ease(0.01).spring(0.99).register + tween2.start(90).end(-90).ease(0.01).spring(0.7).register + tween3.start(255).end(0).ease(0.01).spring(0.95).register.callback { canvas.remove(r) } + end end end -end -def draw - H.draw_stage -end + def draw + H.draw_stage + end end TweenExample.new diff --git a/external_library/java/hype/tween_lambda_example.rb b/external_library/java/hype/tween_lambda_example.rb index 750bc39..113ccde 100644 --- a/external_library/java/hype/tween_lambda_example.rb +++ b/external_library/java/hype/tween_lambda_example.rb @@ -23,8 +23,7 @@ def setup sketch_title('Lambda Tween Example') H.init(self) H.background(color('#000000')) - color_group = ColorGroup.from_web_array(PALETTE.to_java(:string) - colors = HColorPool.new(color_group.colors) + colors = HColorPool.new(web_to_color_array(PALETTE)) H.add(@canvas = HCanvas.new).autoClear(false).fade(1) tween_trigger = HRandomTrigger.new(1.0 / 6) tween_trigger.callback do