indexing description: "Takes a value between 0 and 1 and maps it to a color" author: "" date: "$Date$" revision: "$Revision$" deferred class EM_COLOR_MAPPER feature compute_color(a_value: DOUBLE) is -- take a value between 0.0 and 1.0 and map it to a color require value_valid: a_value >= 0.0 and a_value <= 1.0 do -- Initialize variables is_last_color_grayscale := false last_color_internal := void last_red := 0 last_green := 0 last_blue := 0 last_alpha := 0 -- Call Color mapper function compute_color_internal(a_value) ensure last_color_internal_not_set: last_color_internal = void end is_last_color_grayscale: BOOLEAN last_red: INTEGER last_green: INTEGER last_blue: INTEGER last_alpha: INTEGER last_grayscale: INTEGER is -- get the last grayscale value require is_last_color_grayscale = true do Result := last_red end last_color: EM_COLOR is -- return the last computed color (created on demand) do if last_color_internal = void then last_color_internal := create {EM_COLOR}.make_with_rgba(last_red, last_green, last_blue, last_alpha) end Result := last_color_internal end feature {NONE} compute_color_internal(a_value: DOUBLE) is -- Set the following values in this function: -- last_red -- last_green -- last_blue -- last_alpha -- do not set last_color_internal (this is for internal purposes only) require value_valid: a_value >= 0.0 and a_value <= 1.0 deferred ensure last_color_internal_not_set: last_color_internal = void end feature {NONE} last_color_internal: EM_COLOR invariant valid_grayscale: is_last_color_grayscale implies last_grayscale = last_red and last_red = last_green and last_green = last_blue end