diff options
| -rw-r--r-- | lib/ruby2d/color.rb | 8 | ||||
| -rw-r--r-- | lib/ruby2d/renderable.rb | 8 | ||||
| -rw-r--r-- | test/color_spec.rb | 11 |
3 files changed, 25 insertions, 2 deletions
diff --git a/lib/ruby2d/color.rb b/lib/ruby2d/color.rb index e429e5c..1103c1b 100644 --- a/lib/ruby2d/color.rb +++ b/lib/ruby2d/color.rb @@ -15,7 +15,9 @@ module Ruby2D def length @colors.length end - + + def opacity; @colors[0].opacity end + def opacity=(opacity) @colors.each do |color| color.opacity = opacity @@ -95,7 +97,9 @@ module Ruby2D Color.new(input) end end - + + def opacity; @a end + def opacity=(opacity) @a = opacity end diff --git a/lib/ruby2d/renderable.rb b/lib/ruby2d/renderable.rb index 3be6121..c8fac82 100644 --- a/lib/ruby2d/renderable.rb +++ b/lib/ruby2d/renderable.rb @@ -11,5 +11,13 @@ module Ruby2D Application.remove(self) end end + + def opacity + self.color.opacity + end + + def opacity=(val) + self.color.opacity = val + end end end diff --git a/test/color_spec.rb b/test/color_spec.rb index 95033a9..0fb65c8 100644 --- a/test/color_spec.rb +++ b/test/color_spec.rb @@ -32,4 +32,15 @@ RSpec.describe Ruby2D::Color do end end + describe '#opacity' do + it 'sets and returns the opacity' do + s1 = Square.new + s1.opacity = 0.5 + s2 = Square.new(0, 0, 0, ['red', 'green', 'blue', 'yellow']) + s2.opacity = 0.7 + expect(s1.opacity).to eq 0.5 + expect(s2.opacity).to eq 0.7 + end + end + end |
