gallery/noise: Initial commit #88
Open
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.
Hi there,
I've thrown together this screensaver based loosely off the existing
starsscreensaver.A few comments: We reduce a couple of potentially unnecessary external calls by using built-in vars, with external-call-fallbacks like so:
This gets the state that the script was launched within, but does not work reliably with SIGWINCH. SIGWINCH should be rare anyway, we just eat the cost of a couple of
tputcalls.(Noting that
tputitself isn't 100% portable, but that only matters if you're running something like OpenBSD.)We also lean on
SRANDOMwhen it's available (bash 5.1+) and fall back toRANDOMwhen it's not. I doubt there's any practical or appreciable difference, but logically we're pulling from the system entropy pool rather thanbash's croaky old LCG RNG, so that should scale better. Hypothetically. Maybe.I initially had several selectable colour sets, but the addition of shading blocks enabled that to be compacted down. Now it has two sets: greyscale or greyscale with some red, green, blue and yellow codes thrown in.
I use a slightly debiased modulo approach to provide a fair random selection between the two colour sets. Here I just use
RANDOMbecauseSRANDOMis a sledgehammer for a one-off coin-toss.Tested on
bash4 and 5 on Linux. I don't have a Mac available to me, but I don't see anything that would upsetbash3.Thanks!