class RTanque::Gui::Bot::HealthColorCalculator

Constants

FULL_HEALTH_COLOR

different health-clors as RGB values

LOW_HEALTH_COLOR
MEDIUM_HEALTH_COLOR

Attributes

health[R]

Public Class Methods

new(health) click to toggle source
# File lib/rtanque/gui/bot/health_color_calculator.rb, line 13
def initialize(health)
  @health = health
end

Public Instance Methods

color_as_rgb() click to toggle source
# File lib/rtanque/gui/bot/health_color_calculator.rb, line 17
def color_as_rgb
  if health > 50
    percentage = ((100 - health) / 50)
    color_between FULL_HEALTH_COLOR, MEDIUM_HEALTH_COLOR, percentage
  else
    percentage = ((50 - health) / 50)
    color_between MEDIUM_HEALTH_COLOR, LOW_HEALTH_COLOR, percentage
  end
end
color_between(color_a, color_b, percentage) click to toggle source
# File lib/rtanque/gui/bot/health_color_calculator.rb, line 27
def color_between(color_a, color_b, percentage)
  [
    (color_b[0] - color_a[0]) * percentage + color_a[0],
    (color_b[1] - color_a[1]) * percentage + color_a[1],
    (color_b[2] - color_a[2]) * percentage + color_a[2]
  ]
end