diff options
| author | Tom Black <[email protected]> | 2016-04-26 16:08:14 -0400 |
|---|---|---|
| committer | Tom Black <[email protected]> | 2016-04-26 16:08:14 -0400 |
| commit | 94fc1f516b2f1c2624b5dc2d1cbaf0cbfe8e4796 (patch) | |
| tree | 991eec9ed70c39d47c1a5c38b15197d29e6b6503 /lib | |
| parent | aa41134d58b16b1fb88482865a80bb44eb9e1052 (diff) | |
| parent | 56d5bed2650e2a448e58427e2967856ec39ada3e (diff) | |
| download | ruby2d-94fc1f516b2f1c2624b5dc2d1cbaf0cbfe8e4796.tar.gz ruby2d-94fc1f516b2f1c2624b5dc2d1cbaf0cbfe8e4796.zip | |
Merge pull request #15 from kamishettysreeja25/master
Adds hex to RGB conversion algorithm, addresses the first task in #1
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/ruby2d/color.rb | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/lib/ruby2d/color.rb b/lib/ruby2d/color.rb index c7bb72d..2768086 100644 --- a/lib/ruby2d/color.rb +++ b/lib/ruby2d/color.rb @@ -67,6 +67,20 @@ module Ruby2D end return b end + #convert from "#FFF000" to Float (0.0..1.0) + def hex_to_f(a) + c=[] + b=a.delete("#") + n=(b.length) + #n1=n/3 + j=0 + for i in (0..n-1).step(n/3) + c[j]=Integer("0x".concat(b[i,n/3])) + j=j+1 + end + f = to_f(c) + return f + end end end |
