TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

The Matrix in JavaScript in less than 600 bytes

319 点作者 doublextremevil大约 12 年前

23 条评论

atamyrat大约 12 年前
The closest environment I got to work with Matrix-like UI but real experience was:<p>There is board I'm developing on with serial port, and kernel debug prints so much garbage it literally fills the entire screen in less than couple of seconds. It was because of faulty/broken hardware and there is busy loop that keeps retrying to access the device.<p>I could enter shell commands but I/O lines get mixed in between the verbose kernel debug lines. After some time my eyes synced to the screen scroll rate and I could follow the output from bottom to top to read it (repeatedly run command until I could catch the output correctly).<p>For the moment, I saw "blonde" in fast scrolling random code :) Anyone else had to work like this?
评论 #5391045 未加载
评论 #5391622 未加载
ChrisNorstrom大约 12 年前
You're 99% there. The leading characters need to be white, with the tailing characters being green.<p><a href="http://www.youtube.com/watch?v=Or2m7rYHb_Q" rel="nofollow">http://www.youtube.com/watch?v=Or2m7rYHb_Q</a>
评论 #5388791 未加载
评论 #5388797 未加载
评论 #5388672 未加载
评论 #5388753 未加载
评论 #5388734 未加载
评论 #5390918 未加载
seanalltogether大约 12 年前
here it is at 324 bytes, since your going to end up with scrollbars no matter what, you might as well not worry about document size<p><pre><code> &#60;canvas id=q width=3000 height=3000 style=margin:-10&#62;&#60;script&#62;for(m=Math.random,p=[],i=0;i&#60;256;p[i++]=1);setInterval('9Style="rgba(0,0,0,.05)"9Rect(0,0,3000,3000)9Style="#0F0";p.map(function(v,i){9Text(String.fromCharCode(3e4+m()*33),i*10,v);p[i]=v&#62;758+m()*1e4?0:v+10})'.split(9).join(';q.getContext("2d").fill'),33)&#60;/script&#62; </code></pre> edit... and at 319<p><pre><code> &#60;canvas id=q style=margin:-10&#62;&#60;script&#62;for(q.width=q.height=b=3000,m=Math.random,p=[],i=0;i&#60;256;p[i++]=1);setInterval('9Style="rgba(0,0,0,.05)"9Rect(0,0,b,b)9Style="#0F0";p.map(function(v,i){9Text(String.fromCharCode(3e4+m()*33),i*10,v);p[i]=v&#62;758+m()*1e4?0:v+10})'.split(9).join(';q.getContext("2d").fill'),33)&#60;/script&#62;</code></pre>
评论 #5388667 未加载
评论 #5390829 未加载
评论 #5393304 未加载
Monkeyget大约 12 年前
I took the liberty do de-obfuscate the code : <a href="http://jsfiddle.net/tburette/w6npr/5/" rel="nofollow">http://jsfiddle.net/tburette/w6npr/5/</a>
评论 #5388600 未加载
ronilan大约 12 年前
"Headlong motion through walls of emerald green, milky jade, the sensation of speed beyond anything he'd known before in cyberspace... The Tessier-Ashpool ice shattered, peeling away from the Chinese program's thrust, a worrying impression of solid fluidity, as though the shards of a broken mirror bent and elongated as they fell --"<p><a href="http://project.cyberpunk.ru/lib/neuromancer/" rel="nofollow">http://project.cyberpunk.ru/lib/neuromancer/</a> (1984)
评论 #5389431 未加载
gebe大约 12 年前
There has been some interesting discussion and code golfing on this piece over at Reddit that may be a worthwhile read for some:<p><a href="http://www.reddit.com/r/programming/comments/1ag0c3/someone_posted_an_htmljavascript_implementation/" rel="nofollow">http://www.reddit.com/r/programming/comments/1ag0c3/someone_...</a>
评论 #5388725 未加载
lotyrin大约 12 年前
Why kanji instead of mirrored katakana?
jasonkostempski大约 12 年前
If The Architect hadn't thought he was smarter than JSLint, they wouldn't have ended up with that pesky anomaly.
thom大约 12 年前
Attempted to upload my consciousness to this but it just crashed Chrome. Github issues link pls.
评论 #5389330 未加载
andrewcanis大约 12 年前
If anyone is curious how the code actually works, I've commented up a version below:<p><pre><code> &#60;script type="text/javascript"&#62; function matrix() { // initialize variables for (s = window.screen, w = q.width = s.width, // on my monitor: 1920 h = q.height = s.height, // on my monitor: 1200 m = Math.random, // random number from 0-1 p = [], i = 0; // i ranges from 0 to 255, one element for each character horizontally // this is enough characters to fill the entire screen horizontally // canvas won't let you draw off the screen - so I could set this to 1000 i &#60; 256; // initialize p (the y coordinate of each character) to start at 1 p[i++] = 1); setInterval( // every time we call this function we draw the entire screen a very faint black (with a high transparency of 0.05) // this means every 33 milliseconds the screen is getting slightly darker // this also acts to darken and fade the green characters - when they are first printed they are dark green, then they slowly fade to black function() { // draw black (0,0,0) with alpha (transparency) value 0.05 q.getContext('2d').fillStyle='rgba(0,0,0,0.05)'; // fill the entire screen q.getContext('2d').fillRect(0,0,w,h); // #0f0 is a short form for color green (#00FF00) q.getContext('2d').fillStyle='#0F0'; p.map( // this function will be called 256 times - once for each element of array p, function(v,i){ // map over the array p // v is the value in the array p, which represents the y-coordinate of the text going down // i is the index of the array p, which represents the x coordinate // start from unicode char code 30,000 (0x7530) then add a random number from 0-33 // from wikipedia: http://en.wikipedia.org/wiki/List_of_CJK_Unified_Ideographs,_part_2_of_4 // U+753x 田 由 甲 申 甴 电 甶 男 甸 甹 町 画 甼 甽 甾 甿 // U+754x 畀 畁 畂 畃 畄 畅 畆 畇 畈 畉 畊 畋 界 畍 畎 畏 // U+755x 畐 randomNum = m()*33; // note how the asian characters are slightly different shades // of green, this depends on their line thickness etc, and doesn't // really happen for english characters randomAsianChar = String.fromCharCode(30000 + randomNum); q.getContext('2d').fillText( randomAsianChar, i*10, // x coordinate - each character is 10 x 10 v // y coordinate ); // draw at least 758 characters down before reseting to the start minimumHeight=758 num = minimumHeight+m()*10000; p[i] = (v&#62;num) ? 0 : v+10 // increment the y coordinate by one character (10 pixels), reset when y-coord gets too big }) }, 33) // call every 33 milliseconds } &#60;/script&#62; &#60;body style=margin:0 onload="matrix()"&#62;&#60;canvas id=q&#62;</code></pre>
martin_大约 12 年前
Looks like you improved upon the one I posted yesterday <a href="https://news.ycombinator.com/item?id=5387553" rel="nofollow">https://news.ycombinator.com/item?id=5387553</a> - but it works much better in canvas for sure!
apunic大约 12 年前
When my eyes follow the raindrops it's impossible to see the Chinese characters. I have really to force myself to stare at one spot to see the characters. Interesting phenomena.
评论 #5388582 未加载
Xanza大约 12 年前
This can be rendered directly into Chrome by:<p><pre><code> data:text/html, &#60;canvas id=q style=margin:-10&#62;&#60;script&#62;for(q.width=q.height=b=3000,m=Math.random,p=[],i=0;i&#60;256;p[i++]=1);setInterval('9Style="rgba(0,0,0,.05)"9Rect(0,0,b,b)9Style="#0F0";p.map(function(v,i){9Text(String.fromCharCode(3e4+m()*33),i*10,v);p[i]=v&#62;758+m()*1e4?0:v+10})'.split(9).join(';q.getContext("2d").fill'),33)&#60;/script&#62;</code></pre>
评论 #5392471 未加载
Aardwolf大约 12 年前
I think it are the wrong type of characters. The Asian characters in the Matrix are less complex than those (Wikipedia says "half-width kana").
brianpgordon大约 12 年前
Wow, what a coincidence. I just made one two weeks ago. Mine is way over 600 bytes though.<p>Requires Chrome:<p><a href="http://htmlpreview.github.com/?http://github.com/briangordon/xmatrixjs/blob/ed650310d1846e35cfcbeef47d09eb77c42536dd/xmatrix.html" rel="nofollow">http://htmlpreview.github.com/?http://github.com/briangordon...</a>
评论 #5390557 未加载
评论 #5392188 未加载
kostya-kow大约 12 年前
<a href="https://github.com/KostyaKow/shell_matrix" rel="nofollow">https://github.com/KostyaKow/shell_matrix</a><p>Bash version
评论 #5389151 未加载
baking大约 12 年前
<a href="http://timelessname.com/sandbox/matrix_orig.html" rel="nofollow">http://timelessname.com/sandbox/matrix_orig.html</a> is the only version that works for me. I don't have time right now to figure out why that is.
bluesmoon大约 12 年前
This is what a webcam packet dump looks like on a black console with green text: <a href="http://bluesmoon.livejournal.com/32581.html" rel="nofollow">http://bluesmoon.livejournal.com/32581.html</a>
TommyDANGerous大约 12 年前
That is cool, wish I could make it my background.
Sallsa675大约 12 年前
What's cool about 600b is you can use it for your browser start page. I'd like to see the picky stuff implemented. :)
mikecane大约 12 年前
XP SP2, Firefox 19.0.2 and all I get is a screen that quickly fades to black and then ... nothing.
评论 #5389121 未加载
leeoniya大约 12 年前
obligatory <a href="http://hackertyper.com/" rel="nofollow">http://hackertyper.com/</a>
alexvr大约 12 年前
Makes one heck of a screen saver