Skip to content

Commit

Permalink
Fixed (Valthrun#53 (comment)) color errors
Browse files Browse the repository at this point in the history
  • Loading branch information
Fotonnn committed Oct 10, 2023
1 parent 31eabf8 commit 766821d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 19 deletions.
2 changes: 1 addition & 1 deletion controller/src/settings/ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ impl SettingsUI {
ui.checkbox(obfstr!("2DBOX: Show Health Bar"), &mut settings.esp_health_bar);
if settings.esp_health_bar {
ui.same_line();
ui.slider_config(obfstr!("Width"), 3.0, 10.0)
ui.slider_config(obfstr!("Width"), 1.0, 10.0)
.build(&mut settings.health_bar_width);
ui.checkbox(obfstr!("Rainbow Health Bar (Random colors!)"), &mut settings.rainbow_health_bar);
}
Expand Down
32 changes: 14 additions & 18 deletions controller/src/view/world.rs
Original file line number Diff line number Diff line change
Expand Up @@ -221,25 +221,21 @@ impl ViewController {
}

pub fn calculate_rainbow_color(&self, value: f32) -> [f32; 4] {
let frequency = 0.1;
let r = (frequency * value).sin() * 127.0 + 128.0;
let g = (frequency * value + 2.0 * std::f32::consts::PI / 3.0).sin() * 127.0 + 128.0;
let b = (frequency * value + 4.0 * std::f32::consts::PI / 3.0).sin() * 127.0 + 128.0;
[r / 255.0, g / 255.0, b / 255.0, 1.0]
let frequency: f32 = 0.1;
let sin_value = |offset: f32| (frequency * value + offset).sin() * 0.5 + 1.0;
let r: f32 = sin_value(0.0);
let g: f32 = sin_value(2.0 * std::f32::consts::PI / 3.0);
let b: f32 = sin_value(4.0 * std::f32::consts::PI / 3.0);
[r, g, b, 1.0]
}

pub fn calculate_health_color(&self, health_percentage: f32) -> [f32; 4] {
if health_percentage > 0.6 {
[
2.0 - 2.0 * health_percentage,
2.0 * health_percentage,
0.0,
1.0,
]
} else if health_percentage > 0.3 {
[1.0, 1.0, 2.0 - 2.0 * health_percentage, 1.0]
} else {
[1.0, 2.0 * health_percentage, 0.0, 1.0]
}
}
let clamped_percentage = health_percentage.clamp(0.0, 1.0);

let r = 1.0 - clamped_percentage;
let g = clamped_percentage;
let b = 0.0;

[r, g, b, 1.0]
}
}

0 comments on commit 766821d

Please sign in to comment.