Skip to content

Commit

Permalink
Add Gradients
Browse files Browse the repository at this point in the history
  • Loading branch information
wdevauld committed Jan 14, 2009
1 parent 18fba73 commit 8c1f99b
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
29 changes: 29 additions & 0 deletions lib/colour.rb
Expand Up @@ -82,6 +82,35 @@ def triadic(&block)
end
end


def gradient_to(colour, steps=10)
c = self.class.name.downcase
origin = self.to_rgb
destination = colour.to_rgb
gradient = []

#TODO: *_range isn't really being used
red_range = destination.r - origin.r
red_increment = red_range / steps
green_range = destination.g - origin.g
green_increment = green_range / steps
blue_range = destination.b - origin.b
blue_increment = blue_range / steps

steps.times do |i|
intermediate = RGB.new(
origin.r + red_increment * i,
origin.g + green_increment * i,
origin.b + blue_increment * i
)
gradient << intermediate.send("to_" + c)
if block_given? then
yield intermediate.send("to_" + c)
end
end
gradient
end

#Bones specific stuff

# :stopdoc:
Expand Down
4 changes: 4 additions & 0 deletions spec/colour_spec.rb
Expand Up @@ -23,6 +23,10 @@
@green.web_safe.should eql("#0F0")
end

it "should gradient through the RGB space towards another colour" do
gradient = @green.gradient_to(RGB.new(1,0,1), steps=3)
end

it "should provide a complementary colour" do
end

Expand Down

0 comments on commit 8c1f99b

Please sign in to comment.