diff options
| author | Sadeep Madurange <sadeep@asciimx.com> | 2026-01-09 17:10:13 +0800 |
|---|---|---|
| committer | Sadeep Madurange <sadeep@asciimx.com> | 2026-01-09 17:10:13 +0800 |
| commit | a02d34ac1afa2eedcce5ce4eba5d3a6cdfdd8ec4 (patch) | |
| tree | 63fa221bfc1545da32edd0f08129bf515c0a0112 | |
| parent | 2a36b7b95de83e50faeb256a5ef011fb518efe5c (diff) | |
| download | www-a02d34ac1afa2eedcce5ce4eba5d3a6cdfdd8ec4.tar.gz | |
Add blend() and xor() to matrix post.
| -rw-r--r-- | _log/matrix-digital-rain.md | 33 |
1 files changed, 32 insertions, 1 deletions
diff --git a/_log/matrix-digital-rain.md b/_log/matrix-digital-rain.md index 78fe623..af3cff6 100644 --- a/_log/matrix-digital-rain.md +++ b/_log/matrix-digital-rain.md @@ -49,7 +49,38 @@ static inline void insert_code(matrix *mat, 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, The 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. |
