Created
September 30, 2008 19:06
-
-
Save ab5tract/13918 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Experimental | |
class Palette | |
def initialize(colors) | |
@colors = []; @names = {} | |
if colors.first.length == 2 # This is how we prefer our input, but you can make a palette without it. | |
colors.each {|n, c| @names[n] = c; @colors << c } | |
else | |
colors.each {|c| @colors << c } | |
end | |
end | |
def [](arg) | |
if arg.is_a? Integer | |
@colors[arg] | |
else | |
@names[arg] | |
end | |
end | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Palettes | |
module Butterflies | |
class ButterflyBrown < Palette | |
def initialize | |
super %w{ ["wood shadows","#502B1B"] ["like the earth","#9A592F"] ["soft shades of soil","#BC8751"] | |
["light tree bark","#D09E59"] ["make them look","#C7232C"] } | |
end | |
end | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Experimental | |
module Palettes | |
class ColourLovers < Palette | |
def initialize(args) | |
if args.is_a? Hash | |
raise ArgumentError if args[:keywords].nil? | |
params = args.inject {|p,(a,v)| p + "#{a}=#{b}&" } # We will always add a format, so don't fear the trailing '&' | |
else | |
params = "keywords=#{args}&" if args.is_a? String | |
end | |
json = JSON.load( Net::HTTP.get( URI.parse 'http://www.colourlovers.com/api/palettes?' + params + 'format=json' )) | |
json.colors.nil? ? raise ArgumentError, "no such palette found by COLOURLovers" : super json.colors | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment