3 variables change after 1 'set' is called

require ‘wx’

col_sample2.rb

this sets up the colour constants to be used in this program

BLACK = Wx::Colour.new(0, 0, 0)
RED = Wx::Colour.new(128, 0, 0)

class Symbol_Class

=begin
This class will hold the variables and procedure necessary to
change a symbol in a series of steps from a background colour
to a foreground colour. For example: using black as the
background colour and red as the foreground colour, the symbol
colour will start out as the background colour and become the
foreground colour in 128 steps.
=end

def initialize
    @background_colour = BLACK
    @symbol_colour = BLACK
    @foreground_colour = RED

    @delta_red = 0.0
    @delta_green = 0.0
    @delta_blue = 0.0

    @float_red = 0.0
    @float_green = 0.0
    @float_blue = 0.0

    @symbol_value = "@"
end

def set_symbol(bg_colour, fg_colour)

    if(bg_colour != @background_colour) then
        @background_colour = bg_colour
    end

    if(fg_colour != @foreground_colour) then
        @foreground_colour = fg_colour
    end

    @symbol_colour = @background_colour

    tempBC = @background_colour
    tempFC = @foreground_colour

    compute_delta_colours(tempBC, tempFC)
    update_forward_colours
end

def update_forward_colours

=begin
This routine has behaviour which I do not understand. When
executed the symbol colour changes using the @symbol_colour.set
routine. Unfortunately, both the background colour and temp
colour change even though only one set command was executed.
=end

    puts "ufc1: @background_colour #{@background_colour}"
    puts "ufc1: @symbol_colour #{@symbol_colour}"

    @float_red = (@float_red + @delta_red)
    @float_green = (@float_green + @delta_green)
    @float_blue = (@float_blue + @delta_blue)

    temp_colour = @background_colour
    puts "ufc2: @background_colour #{@background_colour}"
    puts "ufc2: @symbol_colour #{@symbol_colour}"
    puts "ufc2: temp_colour #{temp_colour}"

  @symbol_colour.set((@float_red + 0.5).to_i,
                             (@float_green + 0.5).to_i,
                             (@float_blue + 0.5).to_i)

=begin
Only the symbol_colour should change. Not the temp_colour nor
the background colour however, all three change as shown in the
‘puts’ statements.
=end

    puts "ufc3: temp_colour #{temp_colour}"
    puts "ufc3: @background_colour #{@background_colour}"
    puts "ufc3: @symbol_colour #{@symbol_colour}"

end

def compute_delta_colours(start_colour, end_colour)

    @delta_red = (end_colour.red - start_colour.red) / 128.0
    @delta_green = 0.0
    @delta_blue = 0.0

    @float_red = @symbol_colour.red + 0.0
    @float_green = @symbol_colour.green + 0.0
    @float_blue = @symbol_colour.blue + 0.0
end

end

=begin output from program using ruby1.9
ufc1: @background_colour #<Wx::Colour: (0, 0, 0 *255)>
ufc1: @symbol_colour #<Wx::Colour: (0, 0, 0 *255)>
ufc2: @background_colour #<Wx::Colour: (0, 0, 0 *255)>
ufc2: @symbol_colour #<Wx::Colour: (0, 0, 0 *255)>
ufc2: temp_colour #<Wx::Colour: (0, 0, 0 *255)>
ufc3: temp_colour #<Wx::Colour: (1, 0, 0 *255)>
ufc3: @background_colour #<Wx::Colour: (1, 0, 0 *255)>
ufc3: @symbol_colour #<Wx::Colour: (1, 0, 0 *255)>
=end

class MyApp < Wx::App
@end_app = 0

def on_init
    @symbol = Symbol_Class.new
    bg = BLACK
  fg = RED
    @symbol.set_symbol(bg, fg)
end

end # class

app = MyApp.new
app.main_loop