summaryrefslogtreecommitdiffhomepage
path: root/lib
diff options
context:
space:
mode:
authorMario Visic <[email protected]>2018-12-27 21:30:58 +0800
committerTom Black <[email protected]>2019-01-03 20:15:29 -0800
commit3ef35cdf4fd699cce93a51b1167d765324a213bd (patch)
treef2e6aa3a950b0e1e36cd30ea20780c886b906be6 /lib
parentddc3d31a09557d4d24068078e9d4011df260dc93 (diff)
downloadruby2d-3ef35cdf4fd699cce93a51b1167d765324a213bd.tar.gz
ruby2d-3ef35cdf4fd699cce93a51b1167d765324a213bd.zip
Allow color to initialize from an existing color object
Setting a 2d object's color to be random is great, however it's difficult to re-use that color without manually extracting out the rgba values from that color object. Ideally it would be convenient to be able to do this: ```ruby square = Square.new(color: 'random') square_two = Square.new(color: square.color) ``` This patch allows this behavior from any 2d shape, making it much easier to reuse those random colors :)
Diffstat (limited to 'lib')
-rw-r--r--lib/ruby2d/color.rb3
1 files changed, 3 insertions, 0 deletions
diff --git a/lib/ruby2d/color.rb b/lib/ruby2d/color.rb
index be223d3..8b72dbb 100644
--- a/lib/ruby2d/color.rb
+++ b/lib/ruby2d/color.rb
@@ -66,6 +66,8 @@ module Ruby2D
end
when Array
@r, @g, @b, @a = [c[0], c[1], c[2], c[3]]
+ when Color
+ @r, @g, @b, @a = [c.r, c.g, c.b, c.a]
end
end
end
@@ -90,6 +92,7 @@ module Ruby2D
# Check if the color is valid
def self.is_valid?(c)
+ c.is_a?(Color) || # color object
@@colors.key?(c) || # keyword
self.is_hex?(c) || # hexadecimal value