blob: 851220823f06635ab642c1767a6a07a1b435be6b (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
|
---
title: 'Matrix Rain: 2025 refactor'
date: 2025-12-21
layout: post
project: true
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
separate array when it should've been packed with RGB; Code was harder to read
than it needed to be.
<video style="max-width:100%;" controls="" poster="poster.png">
<source src="matrix.mp4" type="video/mp4">
</video>
Moved phosphor decay into the 4th byte of the RGB union--should’ve done this
in 2022. What was I thinking.
Keeping the RGB union despite portability concerns. All my systems are
little-endian and the code is cleaner this way.
Fixed Unicode by introducing a charset array. UNICODE(min, max) packs Unicode
ranges into uint64--low four bytes for start, high four bytes for end.
insert_code() unpacks a random block and picks a character from it:
```
static uint64_t glyphs[] = {
UNICODE(0x0021, 0x007E), /* ASCII */
UNICODE(0xFF65, 0xFF9F), /* Half-width Katakana */
};
```
Full-width Katakana breaks column alignment. Stick to half-width
(U+FF61-U+FF9F) range. Compile with -DNOKANA to disable Katakana altogether.
blend() simulates phosphor decay by eroding RGB channels toward
background color:
```
static inline void blend(matrix *mat, size_t row, size_t col)
{
unsigned char *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;
}
```
That's still good. Leaving it alone.
Tossed license and automake cruft. Just `cc -O3 main.c -o matrix` now. Don't
need the ceremony.
Runs at 2-3% CPU on OpenBSD (T490). No regressions. Fans are quiet.
Commit:
[03f8d87](https://git.asciimx.com/matrix-digital-rain/commit/?id=03f8d87ba7c2e46bd3f3cc4c772fb3a2ac740c92)
|