Permalink
Browse files

Reverted auto application of layers

  • Loading branch information...
1 parent 283bc22 commit e38d3cc3caa2ab4b9023a6696855008c201cebd0 Ian Smith-Heisters committed Aug 20, 2009
Showing with 27 additions and 13 deletions.
  1. +15 −13 lib/layers.rb
  2. +12 −0 spec/layer_spec.rb
View
28 lib/layers.rb
@@ -7,6 +7,19 @@ def initialize count, universe
super(count){|i|Rdmx::Layer.new(self)}
end
+ def apply!
+ universe.values = blend
+ end
+
+ def blend
+ inject(Array.new(universe.values.size, 0)) do |blended, layer|
+ layer.values.each_index do |i|
+ blended[i] = [([(blended[i] + layer[i]), 255].min), 0].max
+ end
+ blended
+ end
+ end
+
def push *obj
if obj.empty? || (obj.size == 1 && obj.first.is_a?(Integer))
num = obj.pop || 1
@@ -17,26 +30,15 @@ def push *obj
end
class Layer
+ include Rdmx::Universe::Accessors
attr_accessor :values, :fixtures, :parent
def initialize parent
self.parent = parent
- self.values = parent.universe.values
+ self.values = Array.new parent.universe.values.size, 0
self.fixtures = Rdmx::Universe::FixtureArray.new self,
parent.universe.fixture_class
end
-
- def update_channel channel, *new_values
- new_values = extrapolate_pattern channel, new_values
- index = coerce_index channel, new_values.size
- blended = values[*index].each_with_index.map do |v, i|
- new_value = new_values[i]
- new_value ? [[v + new_values[i], 255].min, 0].max : v
- end
- self.values[*index] = blended
- end
-
- include Rdmx::Universe::Accessors # after redefinition so alias works
end
end
View
12 spec/layer_spec.rb
@@ -11,24 +11,28 @@
it "should be easy to wash the background" do
@layers[0][0..-1] = 255, 0, 0
+ @layers.apply!
@universe.values.should == (([255, 0, 0] * (Rdmx::Universe::NUM_CHANNELS / 3)) + [0, 0])
end
it "should be easy to create a blend" do
@layers[0][0..-1] = 255, 0, 0
@layers[1][0..-1] = 0, 255, 0
+ @layers.apply!
@universe.values.should == (([255, 255, 0] * (Rdmx::Universe::NUM_CHANNELS / 3)) + [0, 0])
end
it "should not blend higher than 255" do
@layers[0][0] = 255
@layers[1][0] = 1
+ @layers.apply!
@universe.values[0].should == 255
end
it "should not blend lower than 0" do
@layers[0][0] = 1
@layers[1][0] = -3
+ @layers.apply!
@universe.values[0].should == 0
end
@@ -43,6 +47,7 @@
@layers[0][0..-1] = 255, 0, 0
@layers[1][0..-1] = 0, 255, 0
@layers[2][0..-1] = 0, 0, 255
+ @layers.apply!
@universe.values.should == (([255, 255, 255] * (Rdmx::Universe::NUM_CHANNELS / 3)) + [0, 0])
end
@@ -52,6 +57,13 @@
@layers[0][0..-1] = 255, 0, 0
@layers[1][0..-1] = 0, 255, 0
@layers[11][0..-1] = 0, 0, 255
+ @layers.apply!
@universe.values.should == (([255, 255, 255] * (Rdmx::Universe::NUM_CHANNELS / 3)) + [0, 0])
end
+
+ it "should not copy values from the parent universe" do
+ @universe[0..-1] = 100
+ @layers.push
+ @layers.last.values.uniq.should == [0]
+ end
end

0 comments on commit e38d3cc

Please sign in to comment.