### Home Classes Methods

### In Files

- lib/rubygame/color/models/base.rb

### Methods

- #*
- #+
- #-
- #/
- #average
- #over

### Files

- CREDITS
- LICENSE
- NEWS
- README
- ROADMAP
- custom_sdl_load_paths.rdoc
- getting_started.rdoc
- keyboard_symbols.rdoc
- macosx_install.rdoc
- managing_framerate.rdoc
- surface_palettes.rdoc
- windows_install.rdoc

### Class/Module Index

Quicksearch

- Rubygame
- Rubygame::ActiveEvent
- Rubygame::Clock
- Rubygame::Color
- Rubygame::Color::ColorBase
- Rubygame::Color::ColorHSL
- Rubygame::Color::ColorHSV
- Rubygame::Color::ColorRGB
- Rubygame::Color::Palette
- Rubygame::Event
- Rubygame::EventActions
- Rubygame::EventActions::BlockAction
- Rubygame::EventActions::MethodAction
- Rubygame::EventActions::MultiAction
- Rubygame::EventHandler
- Rubygame::EventHandler::HasEventHandler
- Rubygame::EventHook
- Rubygame::EventQueue
- Rubygame::EventTriggers
- Rubygame::EventTriggers::AndTrigger
- Rubygame::EventTriggers::AttrTrigger
- Rubygame::EventTriggers::BlockTrigger
- Rubygame::EventTriggers::InstanceOfTrigger
- Rubygame::EventTriggers::KeyPressTrigger
- Rubygame::EventTriggers::KeyReleaseTrigger
- Rubygame::EventTriggers::KindOfTrigger
- Rubygame::EventTriggers::MouseMoveTrigger
- Rubygame::EventTriggers::MousePressTrigger
- Rubygame::EventTriggers::MouseReleaseTrigger
- Rubygame::EventTriggers::OrTrigger
- Rubygame::EventTriggers::TickTrigger
- Rubygame::EventTriggers::YesTrigger
- Rubygame::Events
- Rubygame::Events::ClockTicked
- Rubygame::Events::InputFocusGained
- Rubygame::Events::InputFocusLost
- Rubygame::Events::JoystickAxisMoved
- Rubygame::Events::JoystickBallMoved
- Rubygame::Events::JoystickButtonEvent
- Rubygame::Events::JoystickButtonPressed
- Rubygame::Events::JoystickButtonReleased
- Rubygame::Events::JoystickHatMoved
- Rubygame::Events::KeyPressed
- Rubygame::Events::KeyReleased
- Rubygame::Events::KeyboardEvent
- Rubygame::Events::MouseButtonEvent
- Rubygame::Events::MouseFocusGained
- Rubygame::Events::MouseFocusLost
- Rubygame::Events::MouseMoved
- Rubygame::Events::MousePressed
- Rubygame::Events::MouseReleased
- Rubygame::Events::QuitRequested
- Rubygame::Events::WindowExposed
- Rubygame::Events::WindowMinimized
- Rubygame::Events::WindowResized
- Rubygame::Events::WindowUnminimized
- Rubygame::ExposeEvent
- Rubygame::Ftor
- Rubygame::GL
- Rubygame::Hotspot
- Rubygame::JoyAxisEvent
- Rubygame::JoyBallEvent
- Rubygame::JoyDownEvent
- Rubygame::JoyHatEvent
- Rubygame::JoyUpEvent
- Rubygame::Joystick
- Rubygame::Key
- Rubygame::KeyDownEvent
- Rubygame::KeyUpEvent
- Rubygame::MailQueue
- Rubygame::MediaBag
- Rubygame::Mixer
- Rubygame::Mixer::Music
- Rubygame::Mixer::Sample
- Rubygame::Mouse
- Rubygame::MouseDownEvent
- Rubygame::MouseMotionEvent
- Rubygame::MouseUpEvent
- Rubygame::Music
- Rubygame::NamedResource
- Rubygame::NamedResource::NamedResourceClassMethods
- Rubygame::QuitEvent
- Rubygame::Rect
- Rubygame::ResizeEvent
- Rubygame::SDLError
- Rubygame::SFont
- Rubygame::Screen
- Rubygame::Sound
- Rubygame::Sprites
- Rubygame::Sprites::DepthSortGroup
- Rubygame::Sprites::Group
- Rubygame::Sprites::LimitGroup
- Rubygame::Sprites::Sprite
- Rubygame::Sprites::UpdateGroup
- Rubygame::Surface
- Rubygame::TTF

No matching classes.

# Rubygame::Color::ColorBase

A mix-in module defining color arithmetic operations.

### Public Instance Methods

*(other) click to toggle source

Perform color multiplication with another color of any type. The alpha of the new color will be equal to the alpha of the receiver.

    # File lib/rubygame/color/models/base.rb, line 43
    def *(other)
            wrap( simple_op(other)  { |a,b|  a * b } )
    end

+(other) click to toggle source

Perform color addition with another color of any type. The alpha of the new color will be equal to the alpha of the receiver.

    # File lib/rubygame/color/models/base.rb, line 29
    def +(other)
            wrap( simple_op(other)  { |a,b| a + b } )
    end

-(other) click to toggle source

Perform color subtraction with another color of any type. The alpha of the new color will be equal to the alpha of the receiver.

    # File lib/rubygame/color/models/base.rb, line 36
    def -(other)
            wrap( simple_op(other)  { |a,b|  a - b } )
    end

/(other) click to toggle source

Perform color division with another color of any type. The alpha of the new color will be equal to the alpha of the receiver.

    # File lib/rubygame/color/models/base.rb, line 50
    def /(other)
            wrap( simple_op(other)  { |a,b|  a / b } )
    end

average(other, weight=0.5) click to toggle source

Average this color with another color. (Linear weighted average)

A weight of 0.0 means 0% of this color, 100% of the other. A weight of 1.0 means 100% of this color, 0% of the other. A weight of 0.5 means 50% of each color.

    # File lib/rubygame/color/models/base.rb, line 74
    def average(other, weight=0.5)
            c1, c2 = self.to_rgba_ary, other.to_rgba_ary

            rgba = [0,1,2,3].collect do |i|
                    clamp( c1.at(i)*weight + c2.at(i)*(1-weight) )
            end

            wrap( rgba )
    end

over(other) click to toggle source

Layer this color over another color.

    # File lib/rubygame/color/models/base.rb, line 55
    def over(other)
            c1, c2 = self.to_rgba_ary, other.to_rgba_ary
            a1, a2 = c1[3], c2[3]

            rgba = [0,1,2].collect do |i|
                    clamp( a1*c1.at(i) + a2*c2.at(i)*(1-a1) )
            end

            rgba << ( a1 + a2*(1-a1) )

            wrap( rgba )
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.