Skip to content

Commit 997d3f4

Browse files
committed
Add CHANGELOG
1 parent 574c672 commit 997d3f4

File tree

5 files changed

+59
-4
lines changed

5 files changed

+59
-4
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
**v0.3.0** Initial version

lib/color_group.rb

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
java_import Java::Monkstone::ColorUtil
2+
3+
# class wraps a java color array, supports shuffle!, last and ruby_string
4+
# as well as ability to initialize with an array of "web" color string
5+
class ColorGroup
6+
attr_reader :colors
7+
def initialize(p5cols)
8+
@colors = p5cols
9+
end
10+
11+
def self.from_web_array(web)
12+
ColorGroup.new(ColorUtil.web_array(web.to_java(:string)))
13+
end
14+
15+
def shuffle!
16+
@colors = ColorUtil.shuffle(colors)
17+
end
18+
19+
def ruby_string
20+
ColorUtil.rubyString(colors)
21+
end
22+
23+
def last
24+
colors[0]
25+
end
26+
end

lib/vecmath.rb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
require 'java'
22
require 'vecmath/version'
33
require 'vecmath.jar'
4-
5-
4+
require 'core.jar'
65
module Vecmath
76
Java::Monkstone::JRLibrary.load(JRuby.runtime)
87
end

test/color_tool_test.rb

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# frozen_string_literal: true
2+
require_relative 'test_helper'
3+
4+
class ColorGroupTest < Minitest::Test
5+
6+
PALETTE = %w[#FFFFFF #FF0000 #0000FF].freeze
7+
COLORS = [16777215, 16711680, 255].to_java(:int)
8+
9+
def test_new
10+
group = ColorGroup.new(COLORS)
11+
assert group.kind_of? ColorGroup
12+
end
13+
14+
def test_from_web_array
15+
group = ColorGroup.from_web_array(PALETTE)
16+
assert group.kind_of? ColorGroup
17+
end
18+
19+
def test_ruby_string
20+
p5array = [16777215, 16711680, 255]
21+
group = ColorGroup.new(COLORS)
22+
ruby_string = "%w[#FFFFFF #FF0000 #0000FF]\n"
23+
result = group.ruby_string
24+
assert_equal(result, ruby_string)
25+
end
26+
end

test/test_helper.rb

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
$LOAD_PATH.unshift File.expand_path("../../lib", __FILE__)
2-
require "vecmath"
2+
require 'vecmath'
3+
require 'color_group'
34

4-
require "minitest/autorun"
5+
gem 'minitest' # don't use bundled minitest
6+
require 'minitest/autorun'
7+
require 'minitest/pride'

0 commit comments

Comments
 (0)