Skip to content

Commit

Permalink
Saving
Browse files Browse the repository at this point in the history
  • Loading branch information
livingkurt committed Aug 9, 2024
1 parent 436ad19 commit 9e5fad0
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
10 changes: 10 additions & 0 deletions Helios/Colorset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,16 @@ bool Colorset::operator!=(const Colorset &other) const
return !operator==(other);
}

uint32_t Colorset::crc32() const
{
uint32_t hash = 5381;
for (uint8_t i = 0; i < NUM_COLOR_SLOTS; ++i) {
hash = ((hash << 5) + hash) + m_palette[i].raw();
}
hash = ((hash << 5) + hash) + m_numColors;
return hash;
}

void Colorset::init(RGBColor c1, RGBColor c2, RGBColor c3, RGBColor c4,
RGBColor c5, RGBColor c6, RGBColor c7, RGBColor c8)
{
Expand Down
3 changes: 3 additions & 0 deletions Helios/Colorset.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ class Colorset
// index operator to access color index
RGBColor operator[](int index) const;

// crc the colorset
uint32_t crc32() const;

enum ValueStyle : uint8_t
{
// Random values
Expand Down
7 changes: 4 additions & 3 deletions Helios/Helios.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ void Helios::handle_state()
handle_state_set_global_brightness();
break;
case STATE_SHIFT_MODE:
handle_state_shift_mode();
// handle_state_shift_mode();
break;
case STATE_RANDOMIZE:
handle_state_randomize();
Expand Down Expand Up @@ -814,8 +814,9 @@ void Helios::handle_state_shift_mode()
void Helios::handle_state_randomize()
{
if (Button::onShortClick()) {
uint32_t seed = crc32((const uint8_t *)&pat.colorset(), COLORSET_SIZE);
Random ctx(seed);
// uint32_t seed = crc32((const uint8_t *)&pat.colorset(), COLORSET_SIZE);
// Random ctx(seed);
Random ctx(pat.colorset().crc32());
Colorset &cur_set = pat.colorset();
uint8_t num_cols = (ctx.next8() + 1) % NUM_COLOR_SLOTS;
cur_set.randomizeColors(ctx, num_cols);
Expand Down

0 comments on commit 9e5fad0

Please sign in to comment.