class Rubyvis::Color::Rgb

Represents a color in RGB space.

Attributes

a[R]

The alpha channel, a float in [0, 1].

b[R]

The blue channel, an integer in [0, 255].

g[R]

The green channel, an integer in [0, 255].

r[R]

The red channel, an integer in [0, 255].

Public Class Methods

new(r,g,b,a) click to toggle source

Constructs a new RGB color with the specified channel values.

# File lib/rubyvis/color/color.rb, line 290
def initialize(r,g,b,a)
  @r=r
  @b=b
  @g=g
  @a=a
  @opacity=a
  @color= @a > 0 ? "rgb(#{r.to_i},#{g.to_i},#{b.to_i})" : "none"
end

Public Instance Methods

==(v) click to toggle source
# File lib/rubyvis/color/color.rb, line 298
def ==(v)
  self.class==v.class and @r==v.r and @b==v.b and @g==v.g and @a==v.a
end
alpha(a1) click to toggle source

Constructs a new RGB color with the same red, green and blue channels as this color, with the specified alpha channel.

# File lib/rubyvis/color/color.rb, line 320
def alpha(a1)
  Rubyvis.rgb(r,g,b,a1)
end
blue(b1) click to toggle source

Constructs a new RGB color with the same red, green and alpha channels as this color, with the specified blue channel.

# File lib/rubyvis/color/color.rb, line 314
def blue(b1)
  Rubyvis.rgb(r,g,b1,a)
end
brighter(k=1) click to toggle source

Returns a new color that is a brighter version of this color. This method applies an arbitrary scale factor to each of the three RGB components of this color to create a brighter version of this color. Although brighter and darker are inverse operations, the results of a series of invocations of these two methods might be inconsistent because of rounding errors.

# File lib/rubyvis/color/color.rb, line 332
def brighter(k=1)
  k = 0.7**k
  i = 30
  r=self.r
  g=self.g
  b=self.b
  return Rubyvis.rgb(i, i, i, a) if (!r and !g and !b) 
  r = i if (r and (r < i)) 
  g = i if (g and (g < i)) 
  b = i if (b and (b < i))
  Rubyvis.rgb(
    [255, (r/k).floor].min,
    [255, (g/k).floor].min,
    [255, (b/k).floor].min,
  a)
end
darker(k=1) click to toggle source

Returns a new color that is a darker version of this color. This method applies an arbitrary scale factor to each of the three RGB components of this color to create a darker version of this color. Although brighter and darker are inverse operations, the results of a series of invocations of these two methods might be inconsistent because of rounding errors.

# File lib/rubyvis/color/color.rb, line 353
def darker(k=1)
  k = 0.7 ** k
  Rubyvis.rgb(
    [0, (k * r).floor].max,
    [0, (k * g).floor].max,
    [0, (k * b).floor].max,
    a)
end
green(g1) click to toggle source

Constructs a new RGB color with the same red, blue and alpha channels as this color, with the specified green channel.

# File lib/rubyvis/color/color.rb, line 309
def green(g1)
  Rubyvis.rgb(r,g1,b,a)
end
red(r1) click to toggle source

Constructs a new RGB color with the same green, blue and alpha channels as this color, with the specified red channel.

# File lib/rubyvis/color/color.rb, line 304
def red(r1)
  Rubyvis.rgb(r1,g,b,a)
end
rgb() click to toggle source

Returns the RGB color equivalent to this color. This method is abstract and must be implemented by subclasses.

# File lib/rubyvis/color/color.rb, line 324
def rgb
  self
end
to_s() click to toggle source
# File lib/rubyvis/color/color.rb, line 362
def to_s
  @color
end