Skip to content

Conversation

@bushrat011899
Copy link
Contributor

@bushrat011899 bushrat011899 commented Feb 28, 2024

Objective

Solution

  • Moved the existing color_from_entity internals into Hsla::sequence_dispersed which generates a randomly distributed but deterministic color sequence based.
  • Replicated the method for Lcha and Oklcha as well.

Examples

Getting a few colours for a quick palette

let palette = Hsla::sequence_dispersed().take(5).collect::<Vec<_>>();
/*[
    Hsla::hsl(0.0, 1., 0.5),
    Hsla::hsl(222.49225, 1., 0.5),
    Hsla::hsl(84.984474, 1., 0.5),
    Hsla::hsl(307.4767, 1., 0.5),
    Hsla::hsl(169.96895, 1., 0.5),
]*/

Getting a colour from an Entity

let color = Oklcha::sequence_dispersed().nth(entity.index() as u32).unwrap();

Notes

This was previously a private function exclusively for Entity types. I've decided it should instead be public and operate on a u32 directly, since this function may have broader uses for debugging purposes.

Generates deterministic but randomly distributed colors
@alice-i-cecile alice-i-cecile added C-Feature A new feature, making something new possible A-Rendering Drawing game state to the screen labels Feb 28, 2024
Co-authored-by: Alice Cecile <alice.i.cecile@gmail.com>
bushrat011899 and others added 3 commits February 28, 2024 12:42
…rator

Included link to relevant Wikipedia article for described effect. Implementation reference left as a comment inside the function.

Co-Authored-By: Alice Cecile <alice.i.cecile@gmail.com>
@bushrat011899 bushrat011899 changed the title bevy_color: Add Hsla::from_index and Lcha::from_index methods bevy_color: Add sequence_dispersed to Hsla, Lcha, Oklcha Feb 28, 2024
Copy link
Contributor

@pablo-lua pablo-lua left a comment

Choose a reason for hiding this comment

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

I think this can be simplified in some kind of trait in the future, but I'm not sure if this is a good idea. But for now, all good.

@alice-i-cecile alice-i-cecile added the S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it label Feb 28, 2024
@alice-i-cecile alice-i-cecile added this pull request to the merge queue Feb 28, 2024
Merged via the queue into bevyengine:main with commit 043041f Feb 28, 2024
@BD103 BD103 added the A-Color Color spaces and color math label May 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-Color Color spaces and color math A-Rendering Drawing game state to the screen C-Feature A new feature, making something new possible S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add a color_from_index randomized color palette generator

5 participants