summaryrefslogtreecommitdiffstats
path: root/_site/log/matrix-digital-rain/index.html
blob: a57023011eb203de1cc8369e8e7101156006a960 (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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <title>Matrix Rain: 2025 refactor</title>

    <head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title>Matrix Rain: 2025 refactor</title>
  <link rel="stylesheet" href="/assets/css/main.css">
  <link rel="stylesheet" href="/assets/css/skeleton.css">
</head>



  </head>
  <body>

    <div id="nav-container" class="container">
  <ul id="navlist" class="left">
    
    <li >
      <a href="/" class="link-decor-none">hme</a>
    </li>
    <li class="active">
      <a href="/log/" class="link-decor-none">log</a>
    </li>
    <li >
      <a href="/projects/" class="link-decor-none">poc</a>
    </li>
    <li >
      <a href="/about/" class="link-decor-none">abt</a>
    </li>
    <li>
      <a href="/cgi-bin/find.cgi" class="link-decor-none">sws</a>
    </li>
    <li>
      <a href="/feed.xml" class="link-decor-none">rss</a>
    </li>
  </ul>
</div>



    <main>
      <div class="container">
        <div class="container-2">
          <h2 class="center" id="title">MATRIX RAIN: 2025 REFACTOR</h2>
          <h6 class="center">21 DECEMBER 2025</h5>
          <br>
          <div class="twocol justify"><p>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.</p>

<video style="max-width:100%;" controls="" poster="poster.png">
  <source src="matrix.mp4" type="video/mp4" />
</video>

<p>Moved phosphor decay into the 4th byte of the RGB union–should’ve done this 
in 2022; What was I thinking.</p>

<p>Keeping the RGB union despite portability concerns. All my systems are
little-endian and the code is cleaner this way.</p>

<p>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:</p>

<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>#define UNICODE(min, max)  (((uint64_t)max &lt;&lt; 32) | min)

static uint64_t glyphs[] = {
    UNICODE(0x0021, 0x007E), /* ASCII */
    UNICODE(0xFF65, 0xFF9F), /* Half-width Katakana */
};

static inline void insert_code(matrix *mat,
    size_t row, size_t col) 
{
    uint64_t blk;
    uint32_t min, max;

    blk = glyphs[(rand() % glyphlen)];
    min = (uint32_t)blk;
    max = (uint32_t)(blk &gt;&gt; 32);
    mat-&gt;code[index(mat, row, col)] = rand() % (max - min) + min;
}
</code></pre></div></div>

<p>Full-width Katakana breaks column alignment. Stick to half-width
(U+FF61-U+FF9F) range. Compile with -DNOKANA to disable Katakana altogether.</p>

<p>blend() is still good. Leaving it alone.</p>

<p>Tossed license and automake cruft. Just <code class="language-plaintext highlighter-rouge">cc -O3 main.c -o matrix</code> now. Don’t
need the ceremony.</p>

<p>Runs at 2-3% CPU on OpenBSD (T490). No regressions. Fans are quiet.</p>

<p>Commit:
<a href="https://git.asciimx.com/matrix-digital-rain/commit/main.c?id=69a888a5b0bc4ef4bce4f86c1556a06f0f131fda">69a888a</a></p>
</div>
          <p class="post-author right">by W. D. Sadeep Madurange</p>
        </div>
      </div>
    </main>

    <div class="footer">
  <div class="container">
    <div class="twelve columns right container-2">
      <p id="footer-text">&copy; ASCIIMX - 2025</p>
    </div>
  </div>
</div>


  </body>
</html>