Skip to content

[Feature] Allow optional seeding from getColor#9

Merged
tristen merged 5 commits intopublisher-productionfrom
get-color-seeded-option
Sep 3, 2025
Merged

[Feature] Allow optional seeding from getColor#9
tristen merged 5 commits intopublisher-productionfrom
get-color-seeded-option

Conversation

@tristen
Copy link
Member

@tristen tristen commented Sep 3, 2025

Looks like this:

Screenshot 2025-09-03 at 1 56 21 PM

Comment on lines +76 to +82
_mapIndexToHue(index) {
// A hybrid approach to color distance checking in _getSequentialColor but
// for `_getDeterministicColor`. Attempts to “spread” hash values evenly to
// reduce the same hues appearing next to one another.
const golden = 0.61803398875;
return Math.round(((index * golden) % 1) * this.HUE_MAX);
}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AI proposed this idea as a cheap way to spread hues more distributed across the palette as fetching a deterministic value and comparing it using color difference would require knowing the whole list of values ahead of time.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's actually not a bad approach, and picked an irrational number too, so it never repeats, which is cool. I'd maybe use a constant like Math.E though, so that we don't have magic numbers in the code that have low precision or need an explanation

@tristen tristen added the ai AI coding agents co-authored the code label Sep 3, 2025
Copy link
Contributor

@AlexanderBelokon AlexanderBelokon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks great to me, both the API change, and the implementation 👍 Very elegant ✨

@tristen tristen removed the ai AI coding agents co-authored the code label Sep 3, 2025
@tristen tristen merged commit 27205b8 into publisher-production Sep 3, 2025
6 checks passed
@tristen tristen deleted the get-color-seeded-option branch September 3, 2025 19:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants