Module: Color
- Defined in:
- lib/color/util.rb,
lib/color.rb,
lib/color/hsb.rb,
lib/color/rgb.rb,
lib/color/scheme.rb,
lib/color/palette.rb,
lib/color/full_palette.rb,
lib/color/sample_palette.rb
Overview
shows a set of colors, in text and html
Defined Under Namespace
Classes: Analogous, Complementary, DoubleComplementary, FullPalette, HSB, Hues, Monochromatic, Palette, RGB, SamplePalette, Scheme, SplitComplementary, Triadic
Constant Summary collapse
- VERSION =
'0.0.1'
Class Method Summary collapse
-
.check_constraint(val, str, minimum, maximum) ⇒ Object
should be riel.
-
.distribution(total, len) ⇒ Object
returns an array, of length len, of numbers, equally (or near-equally) distributed for the total.
- .random_in_range(from, to, interval) ⇒ Object
- .round(num, places) ⇒ Object
Class Method Details
.check_constraint(val, str, minimum, maximum) ⇒ Object
should be riel
6 7 8 9 10 |
# File 'lib/color/util.rb', line 6 def self.check_constraint(val, str, minimum, maximum) if val < minimum || val > maximum raise RuntimeError.new("#{str} must be (#{minimum} .. #{maximum}), not: #{val}") end end |
.distribution(total, len) ⇒ Object
returns an array, of length len, of numbers, equally (or near-equally) distributed for the total
19 20 21 22 23 24 |
# File 'lib/color/util.rb', line 19 def self.distribution(total, len) base_per = total.to_f / len pivot = total - (base_per.floor * len) (0 ... len).collect { |idx| base_per.floor + (idx < pivot ? 1 : 0) } end |
.random_in_range(from, to, interval) ⇒ Object
26 27 28 |
# File 'lib/color/util.rb', line 26 def self.random_in_range(from, to, interval) from + rand((to.to_f - from) / interval).round * interval end |
.round(num, places) ⇒ Object
12 13 14 |
# File 'lib/color/util.rb', line 12 def self.round(num, places) (num * 10 ** places).round / (10 ** places).to_f end |