Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update HColorPool to optionally avoid repeats when calling getColor() #168

Open
wants to merge 2 commits into
base: lib_staging
Choose a base branch
from

Conversation

octobeard
Copy link

@octobeard octobeard commented Jul 20, 2020

One of the things that has initially bothered me when utilizing the HColorPool class has been the inability to make sure small pool counts don't continually repeat the same colors in HShapes with similar amounts of children. When using shapes with adjacent children (see example images below) quite often those children will share the same color. By instead of randomly sourcing an index and grabbing a color, this PR updates the HColorPool class to also store an additional list of colors, randomize them once, and then subsequently pull them off the head of the array every time getColor() is called when the flag to repeat colors is set to false. A slight change to HShape's randomColors makes sure to reset the stack every time it is called so that the color pool doesn't accidentally repeat colors in the pool by starting the randomization with a stack that doesn't match the size of the pool. As you can see in the generated images, the effect is subtle, but very satisfying depending on application.

usage:

	colorPool = new HColorPool(#F7F7F7, #0095A8, #FF3300, #FF6600).repeatColors(false);

I generated the javadocs for this PR with open jdk 14 and it appears to have changed quite a bit here, and while I kinda appreciate the different UI a bit, I had to do some manual tweaks to get it working, which I have not included in the PR. What version of Java are you using to build the project? While compilation and sketchbook updating is seamless, generating the javadocs wasn't and I have a feeling it's my environment.

Repeats:
repeats
No repeats:
no-repeats

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.

1 participant