Update HColorPool to optionally avoid repeats when calling getColor() #168
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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:
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:
No repeats: