rcade_colors 0.0.4 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/Rakefile +7 -0
- data/lib/rcade_colors.rb +19 -12
- data/rcade_colors.gemspec +1 -1
- data/test/rcade_colors_test.rb +52 -0
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d21ad581309ec030e0493349400ef654b7d9a5ca
|
4
|
+
data.tar.gz: 7093a8ee0f53e4f446a104ebb31a70fe1f2fd554
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 77df3348ea9d3964df22ebe78cd359d538e4b25dce9046dc16a6aa2bc62eb95f94c664976746699c3fd544d3999318f374b7a3d33b06d0c79becae26b0545003
|
7
|
+
data.tar.gz: 3a2126aa128f65d62ecf50b6b873f272c9e98022c8b15f82d61c2e1ebd76d82e9e255168c3a50026eb570ab41fb0eba0a220b967f052326dc9c1d375651985f9
|
data/README.md
CHANGED
data/Rakefile
CHANGED
data/lib/rcade_colors.rb
CHANGED
@@ -1,6 +1,14 @@
|
|
1
1
|
require 'gosu'
|
2
|
-
|
3
|
-
|
2
|
+
|
3
|
+
class Gosu::Color
|
4
|
+
# Provides the ability to adjust the opacity (alpha).
|
5
|
+
# The opacity argument should be a float 0.0..1.0
|
6
|
+
def opacity(opacity)
|
7
|
+
a = alpha * opacity
|
8
|
+
hex_string = "0x%02x%02x%02x%02x" % [(alpha * opacity), red, green, blue]
|
9
|
+
self.class.argb(hex_string.to_i(16))
|
10
|
+
end
|
11
|
+
end
|
4
12
|
|
5
13
|
module Rcade
|
6
14
|
class Color < Gosu::Color
|
@@ -12,22 +20,21 @@ module Rcade
|
|
12
20
|
# "#fed"
|
13
21
|
# "cabbed"
|
14
22
|
# "#cabbed"
|
15
|
-
def self.from_hex(
|
16
|
-
|
17
|
-
|
23
|
+
def self.from_hex(string)
|
24
|
+
h = string.scan(/\h/)
|
25
|
+
if h.size == 3
|
26
|
+
h.map! {|v| (v * 2) } # expand to 6 character format
|
27
|
+
end
|
28
|
+
hex_string = "0xff" + h.join # fully opaque
|
29
|
+
self.argb(hex_string.to_i(16))
|
18
30
|
end
|
19
31
|
|
20
32
|
def self.named(color_name)
|
33
|
+
require 'color/css'
|
21
34
|
color = ::Color::CSS[color_name]
|
22
35
|
raise 'Invalid color name' unless color
|
23
36
|
self.from_hex(color.html)
|
24
37
|
end
|
25
38
|
|
26
|
-
# opacity should be a float 0.0..1.0
|
27
|
-
def opacity(opacity)
|
28
|
-
a = alpha * opacity
|
29
|
-
self.from_ahsv(a, hue, saturation, value)
|
30
|
-
end
|
31
|
-
|
32
39
|
end
|
33
|
-
end
|
40
|
+
end
|
data/rcade_colors.gemspec
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |spec|
|
4
4
|
spec.name = "rcade_colors"
|
5
|
-
spec.version = "0.0.
|
5
|
+
spec.version = "0.0.5"
|
6
6
|
spec.authors = ["Andrew Havens"]
|
7
7
|
spec.email = ["email@andrewhavens.com"]
|
8
8
|
spec.description = %q{Provides additional CSS Hex value and opacity support for Gosu.}
|
@@ -0,0 +1,52 @@
|
|
1
|
+
require "minitest/spec"
|
2
|
+
require "minitest/autorun"
|
3
|
+
require 'rcade_colors'
|
4
|
+
|
5
|
+
describe Rcade::Color do
|
6
|
+
|
7
|
+
it 'can create black from hex' do
|
8
|
+
c = Rcade::Color.from_hex('000000')
|
9
|
+
[c.red, c.green, c.blue, c.alpha].must_equal [0,0,0,255]
|
10
|
+
c = Rcade::Color.from_hex('000')
|
11
|
+
[c.red, c.green, c.blue, c.alpha].must_equal [0,0,0,255]
|
12
|
+
c = Rcade::Color.from_hex('#000000')
|
13
|
+
[c.red, c.green, c.blue, c.alpha].must_equal [0,0,0,255]
|
14
|
+
c = Rcade::Color.from_hex('#000')
|
15
|
+
[c.red, c.green, c.blue, c.alpha].must_equal [0,0,0,255]
|
16
|
+
end
|
17
|
+
|
18
|
+
it 'can create white from hex' do
|
19
|
+
c = Rcade::Color.from_hex('ffffff')
|
20
|
+
[c.red, c.green, c.blue, c.alpha].must_equal [255,255,255,255]
|
21
|
+
c = Rcade::Color.from_hex('fff')
|
22
|
+
[c.red, c.green, c.blue, c.alpha].must_equal [255,255,255,255]
|
23
|
+
c = Rcade::Color.from_hex('#ffffff')
|
24
|
+
[c.red, c.green, c.blue, c.alpha].must_equal [255,255,255,255]
|
25
|
+
c = Rcade::Color.from_hex('#fff')
|
26
|
+
[c.red, c.green, c.blue, c.alpha].must_equal [255,255,255,255]
|
27
|
+
c = Rcade::Color.from_hex('fFf') # case shouldnt matter
|
28
|
+
[c.red, c.green, c.blue, c.alpha].must_equal [255,255,255,255]
|
29
|
+
end
|
30
|
+
|
31
|
+
it 'can create red from hex' do
|
32
|
+
c = Rcade::Color.from_hex('ff0000')
|
33
|
+
[c.red, c.green, c.blue, c.alpha].must_equal [255,0,0,255]
|
34
|
+
c = Rcade::Color.from_hex('f00')
|
35
|
+
[c.red, c.green, c.blue, c.alpha].must_equal [255,0,0,255]
|
36
|
+
c = Rcade::Color.from_hex('#ff0000')
|
37
|
+
[c.red, c.green, c.blue, c.alpha].must_equal [255,0,0,255]
|
38
|
+
c = Rcade::Color.from_hex('#f00')
|
39
|
+
[c.red, c.green, c.blue, c.alpha].must_equal [255,0,0,255]
|
40
|
+
end
|
41
|
+
|
42
|
+
it 'can modify opacity' do
|
43
|
+
c = Rcade::Color.from_hex('#f00').opacity(0)
|
44
|
+
[c.red, c.green, c.blue, c.alpha].must_equal [255,0,0,0]
|
45
|
+
|
46
|
+
color = Rcade::Color.from_hex('#f00').opacity(1)
|
47
|
+
color.alpha.must_equal(255)
|
48
|
+
|
49
|
+
color = Rcade::Color.from_hex('#f00').opacity(0.5)
|
50
|
+
color.alpha.must_equal(127)
|
51
|
+
end
|
52
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rcade_colors
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andrew Havens
|
@@ -81,6 +81,7 @@ files:
|
|
81
81
|
- Rakefile
|
82
82
|
- lib/rcade_colors.rb
|
83
83
|
- rcade_colors.gemspec
|
84
|
+
- test/rcade_colors_test.rb
|
84
85
|
homepage: https://github.com/ruby-rcade/rcade_colors
|
85
86
|
licenses:
|
86
87
|
- MIT
|
@@ -105,4 +106,5 @@ rubygems_version: 2.0.2
|
|
105
106
|
signing_key:
|
106
107
|
specification_version: 4
|
107
108
|
summary: Provides additional CSS Hex value and opacity support for Gosu.
|
108
|
-
test_files:
|
109
|
+
test_files:
|
110
|
+
- test/rcade_colors_test.rb
|