Sha256: 14bcbabdcf69a8e7243683f5062ff3bad52becccb53a4d4023f19288a6c301cd

Contents?: true

Size: 899 Bytes

Versions: 3

Compression:

Stored size: 899 Bytes

Contents

# -*- coding: utf-8 -*-


require 'rays/ext'


module Rays


  class Color

    include Comparable

    def to_a ()
      [red, green, blue, alpha]
    end

    def [] (index)
      case index
      when 0 then red
      when 1 then green
      when 2 then blue
      when 3 then alpha
      else raise IndexError
      end
    end

    def []= (index, val)
      case index
      when 0 then self.red   = val
      when 1 then self.green = val
      when 2 then self.blue  = val
      when 3 then self.alpha = val
      else raise IndexError
      end
    end

    def <=> (o)
      ret = red   <=> o.red;   return ret if ret != 0
      ret = green <=> o.green; return ret if ret != 0
      ret = blue  <=> o.blue;  return ret if ret != 0
            alpha <=> o.alpha
    end

    def inspect ()
      "#<Rays::Color r=#{red}, g=#{green}, b=#{blue}, a=#{alpha}>"
    end

  end# Color


end# Rays

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
rays-0.1.6 lib/rays/color.rb
rays-0.1.5 lib/rays/color.rb
rays-0.1.4 lib/rays/color.rb