Class: Pruim::Color

Inherits:
Object
  • Object
show all
Defined in:
lib/pruim/color.rb

Constant Summary collapse

BRIGHT_TRESHOLD =
382

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.rgb(r, g, b) ⇒ Object



7
8
9
# File 'lib/pruim/color.rb', line 7

def self.rgb(r, g, b)
  return rgba(r, g, b, 255)
end

.rgba(r, g, b, a) ⇒ Object



3
4
5
# File 'lib/pruim/color.rb', line 3

def self.rgba(r, g, b, a)
  (a | (b << 8) | (g << 16) | (r << 24))
end

.to_rgb(color) ⇒ Object



20
21
22
23
# File 'lib/pruim/color.rb', line 20

def self.to_rgb(color)
  r, g, b, a = to_rgba(color)
  return r, g, b
end

.to_rgba(color) ⇒ Object

Cpolors are encoded in abgr



12
13
14
15
16
17
18
# File 'lib/pruim/color.rb', line 12

def self.to_rgba(color)
  a = (color)       & 255
  b = (color >> 8)  & 255
  g = (color >> 16) & 255
  r = (color >> 24) & 255
  return r, g, b, a
end

Instance Method Details

#to_bool(treshold = BRIGHT_TRESHOLD) ⇒ Object

Returns true if the color is bright (above threshold) And false if black. Transparency is takeninto account as well.



29
30
31
# File 'lib/pruim/color.rb', line 29

def to_bool(treshold = BRIGHT_TRESHOLD)
  
end