Class: RTanque::Gui::Bot::HealthColorCalculator
- Inherits:
-
Object
- Object
- RTanque::Gui::Bot::HealthColorCalculator
- Defined in:
- lib/rtanque/gui/bot/health_color_calculator.rb
Constant Summary collapse
- FULL_HEALTH_COLOR =
different health-clors as RGB values
[ 74, 190, 74].map { |v| v/255.0 }
- MEDIUM_HEALTH_COLOR =
[255, 190, 0].map { |v| v/255.0 }
- LOW_HEALTH_COLOR =
[220, 0, 0].map { |v| v/255.0 }
Instance Attribute Summary collapse
-
#health ⇒ Object
readonly
Returns the value of attribute health.
Instance Method Summary collapse
- #color_as_rgb ⇒ Object
- #color_between(color_a, color_b, percentage) ⇒ Object
-
#initialize(health) ⇒ HealthColorCalculator
constructor
A new instance of HealthColorCalculator.
Constructor Details
#initialize(health) ⇒ HealthColorCalculator
Returns a new instance of HealthColorCalculator.
13 14 15 |
# File 'lib/rtanque/gui/bot/health_color_calculator.rb', line 13 def initialize(health) @health = health end |
Instance Attribute Details
#health ⇒ Object (readonly)
Returns the value of attribute health.
11 12 13 |
# File 'lib/rtanque/gui/bot/health_color_calculator.rb', line 11 def health @health end |
Instance Method Details
#color_as_rgb ⇒ Object
17 18 19 20 21 22 23 24 25 |
# 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) ⇒ Object
27 28 29 30 31 32 33 |
# 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 |