diff options
Diffstat (limited to '_log/matrix-digital-rain.md')
| -rw-r--r-- | _log/matrix-digital-rain.md | 39 |
1 files changed, 35 insertions, 4 deletions
diff --git a/_log/matrix-digital-rain.md b/_log/matrix-digital-rain.md index 78fe623..2edc7e7 100644 --- a/_log/matrix-digital-rain.md +++ b/_log/matrix-digital-rain.md @@ -7,7 +7,7 @@ thumbnail: thumb_sm.png --- The 2022 version worked but had some loose ends. Unicode support was -inflexible--couldn't mix ASCII with Katakana; Phosphor decay was stored in a +incomplete--couldn't mix ASCII with Katakana; Phosphor decay was stored in a separate array when it should've been packed with RGB; Code was harder to read than it needed to be. @@ -39,17 +39,48 @@ static inline void insert_code(matrix *mat, uint64_t blk; uint32_t min, max; - blk = glyphs[(rand() % glyphlen)]; + blk = glyphs[(xor() % glyphlen)]; min = (uint32_t)blk; max = (uint32_t)(blk >> 32); - mat->code[index(mat, row, col)] = rand() % (max - min) + min; + mat->code[index(mat, row, col)] = xor() % (max - min) + min; } ``` Full-width Katakana breaks column alignment. Stick to half-width (U+FF61-U+FF9F) range. Compile with -DNOKANA to disable Katakana altogether. -blend() is still good. Leaving it alone. +blend() for screen decay is still good: + +``` +static inline void blend(matrix *mat, + size_t row, size_t col) +{ + unsigned char *color; + + color = mat->rgb[index(mat, row, col)].color; + color[R] = color[R] - (color[R] - RGB_BG_RED) / DECAY_MPLIER; + color[G] = color[G] - (color[G] - RGB_BG_GRN) / DECAY_MPLIER; + color[B] = color[B] - (color[B] - RGB_BG_BLU) / DECAY_MPLIER; +} +``` + +Left it alone. + +Optimized RNG--xorshift instead of rand(): + +``` +static inline uint32_t xor(void) +{ + /* Xorshift RNGs, George Marsaglia, Florida State University. */ + static uint32_t y = 2463534242; + + y ^= (y << 13); + y = (y >> 17); + return (y ^= (y << 5)); +} +``` + +NOTE: Non-linear variations (xorshitr+) for more speed. Tossed license and automake cruft. Just `cc -O3 main.c -o matrix` now. Don't need the ceremony. |
