Skip to content

Commit

Permalink
karm-gfx: Added a simple helper function for generating colors in hue…
Browse files Browse the repository at this point in the history
… order.

Pretty usefull for debugging
  • Loading branch information
sleepy-monax committed Dec 31, 2024
1 parent f904629 commit 91c82c8
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 7 deletions.
23 changes: 23 additions & 0 deletions src/libs/karm-gfx/colors.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#include "colors.h"

namespace Karm::Gfx {

Color randomColor(Math::Rand &rand) {
return COLORS[rand.nextInt(COLORS.len())];
}

Color randomColor() {
static Math::Rand rand{123};
return randomColor(rand);
}

Gfx::Color rainbowColor() {
static f64 hue = 0;
auto res = Gfx::hsvToRgb({hue, 1, 1});
hue += 1;
if (hue > 360)
hue = 0;
return res;
}

} // namespace Karm::Gfx
11 changes: 4 additions & 7 deletions src/libs/karm-gfx/colors.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,13 +72,10 @@ MAKE_COLOR_RAMP(ROSE, 0xfff1f2, 0xffe4e6, 0xfecdd3, 0xfda4af, 0xfb7185, 0xf43f5e
PINK, ROSE
};

inline Color randomColor(Math::Rand &rand) {
return COLORS[rand.nextInt(COLORS.len())];
}
Color randomColor(Math::Rand &rand);

inline Color randomColor() {
static Math::Rand rand{123};
return randomColor(rand);
}
Color randomColor();

Gfx::Color rainbowColor();

} // namespace Karm::Gfx

0 comments on commit 91c82c8

Please sign in to comment.