Module: RandPalette

Defined in:
lib/rand_palette.rb,
lib/rand_palette/version.rb

Defined Under Namespace

Classes: RGBA

Constant Summary collapse

Scalar =
(0..255)
ScalarDesc =
Scalar.to_a.reverse.slice 1,254
Palette =
[Scalar.map{|c| [255, c, 0] },
ScalarDesc.map{|c| [c, 255, 0] },
Scalar.map{|c| [0, 255, c] },
ScalarDesc.map{|c| [0, c, 255] },
Scalar.map{|c| [c, 0, 255] },
ScalarDesc.map{|c| [255, 0, c] }].flatten 1
VERSION =
"0.1.2"

Class Method Summary collapse

Class Method Details

.random(n, alpha: 1) ⇒ Object

Raises:

  • (RangeError)


15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/rand_palette.rb', line 15

def self.random n, alpha: 1
  return [] if n <= 0
  raise RangeError, "No more than #{range} kinds od color" if n > range

  picked = rand range
  steps = range / n
  n.times.map do |t|
    picked = picked + steps
    picked = picked - range if picked >= range
    picked
  end.map do |picked|
    RGBA.new(Palette[picked] + [alpha]).to_s
  end
end

.rangeObject



30
31
32
# File 'lib/rand_palette.rb', line 30

def self.range
  Palette.size
end