Module: PaletteCreator
- Defined in:
- lib/palette_creator.rb
Overview
- Author
-
Sean McCarthy
- Copyright
-
Copyright © 2012 Sean McCarthy
- License
-
GPL3
Class Method Summary collapse
-
.create(options = {}) ⇒ Object
Create a colour palette.
- .rgb_as_hex(rgb_array) ⇒ Object
Class Method Details
.create(options = {}) ⇒ Object
Create a colour palette
options can have the following keys:
-
count: number of colours to generate
-
frequency: frequency of the sine wave
-
phases:
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/palette_creator.rb', line 16 def self.create(={}) opts = OpenStruct.new() count = opts.count || 32 frequency = opts.frequency || 0.3 phases = opts.phases || [0, 2, 4] amplitude = 127 # ~ 255/2 center = 128 # ~ 255/2 palette = [] count.times do |i| red = Math.sin(frequency*i + phases[0]) * amplitude + center; green = Math.sin(frequency*i + phases[1]) * amplitude + center; blue = Math.sin(frequency*i + phases[2]) * amplitude + center; palette << [red.to_i, green.to_i, blue.to_i] end palette end |
.rgb_as_hex(rgb_array) ⇒ Object
34 35 36 |
# File 'lib/palette_creator.rb', line 34 def self.rgb_as_hex(rgb_array) rgb_array.map{|val| "%02x" % val}.join('').upcase end |