Skip to content

Commit

Permalink
fix: returned hue shift
Browse files Browse the repository at this point in the history
  • Loading branch information
Marko Grizelj committed Sep 2, 2024
1 parent 2509310 commit b025df1
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions src/rand/models.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ fn hue(preset: &Randomizer, objects: &mut Objects, rng: &mut Xoshiro256StarStar)

let mut texture_tim = Tim::from(texture_raw);

let mut new_hue = 0.0;
let mut hue_shift = 0.0;
for _ in 0..preset.shuffles {
new_hue = (rng.next_u32() % 360) as f64;
hue_shift = (rng.next_u32() % 360) as f64;
}

for i in 0..64 {
Expand Down Expand Up @@ -56,10 +56,24 @@ fn hue(preset: &Randomizer, objects: &mut Objects, rng: &mut Xoshiro256StarStar)
let min = r.min(g).min(b);
let delta = max - min;

let h = if delta == 0.0 {
0.0
} else if max == r {
60.0 * (((g - b) / delta) % 6.0)
} else if max == g {
60.0 * (((b - r) / delta) + 2.0)
} else {
60.0 * (((r - g) / delta) + 4.0)
};

let h = if h < 0.0 { h + 360.0 } else { h };

let s = if max == 0.0 { 0.0 } else { delta / max };

let v = max;

let new_hue = (h + hue_shift).rem_euclid(360.0);

let c = v * s;
let x = c * (1.0 - ((new_hue / 60.0) % 2.0 - 1.0).abs());
let m = v - c;
Expand Down

0 comments on commit b025df1

Please sign in to comment.