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

科技回声

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

GitHubTwitter

首页

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

资源链接

HackerNews API原版 HackerNewsNext.js

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

Qlock – A JavaScript Quine Clock

195 点作者 ayoreis大约 1 年前

9 条评论

cyco130大约 1 年前
I once used the word &quot;quine&quot; in Scrabble. We had a house rule that allowed all English words on English Wiktionary if you could give a more or less correct definition. I gave the computer science definition but it turns out it had a more interesting meaning that immediately caught on in that particular friend group: &quot;To deny the existence or significance of something obviously real or important&quot;.<p>[1] <a href="https:&#x2F;&#x2F;en.wiktionary.org&#x2F;wiki&#x2F;quine#Verb" rel="nofollow">https:&#x2F;&#x2F;en.wiktionary.org&#x2F;wiki&#x2F;quine#Verb</a>
评论 #40519981 未加载
debo_大约 1 年前
In my third year of university, we had a professor give us an assignment where writing a quine was the final exercise.<p>For 3 hours, I was cursing his name. Then I got it and I loved him for it. It was such a great feeling!<p>A quine was something I never would have come up with on my own, and transitioning from &quot;that must be impossible&quot; to &quot;oh, ok it&#x27;s just ugly&quot; (I did it in Perl iirc) to seeing some elegant ones from classmates was terrific experience.
wonger_大约 1 年前
The author has a bunch of other neat projects like: <a href="https:&#x2F;&#x2F;aem1k.com&#x2F;world&#x2F;" rel="nofollow">https:&#x2F;&#x2F;aem1k.com&#x2F;world&#x2F;</a><p>And he explains some of the code golfing in this talk: <a href="https:&#x2F;&#x2F;m.youtube.com&#x2F;watch?v=RTxtiLp1C8Y" rel="nofollow">https:&#x2F;&#x2F;m.youtube.com&#x2F;watch?v=RTxtiLp1C8Y</a>
评论 #40519710 未加载
评论 #40516839 未加载
schneems大约 1 年前
One of my fave Quine talks <a href="https:&#x2F;&#x2F;m.youtube.com&#x2F;watch?v=IgF75PjxHHA" rel="nofollow">https:&#x2F;&#x2F;m.youtube.com&#x2F;watch?v=IgF75PjxHHA</a><p>And he made a Quine for the conf <a href="https:&#x2F;&#x2F;m.youtube.com&#x2F;watch?v=4DfhAK8xVWI" rel="nofollow">https:&#x2F;&#x2F;m.youtube.com&#x2F;watch?v=4DfhAK8xVWI</a>
jdthedisciple大约 1 年前
How does one even go about implementing quines like this?<p>Is there a certain iterative kind of method that people use to achieve these?
lukeschaefer大约 1 年前
Since I&#x27;m bored - here&#x27;s a quick run down of how this works, split into chunks.<p>#1 - Function Wrapper:<p><pre><code> (r = n =&gt; setInterval(t =&gt; { ... }, 100))() </code></pre> Here a number of things are done:<p>- set `r` to the function that runs the whole quine.<p>- when r is called (inline immediately at the end) it sets an interval to call the body every 100ms.<p>- `n` is unused, and is there for spacing instead of using `()` to indicate no params.<p>#2 - Row Looper:<p><pre><code> for (j = o = &quot;\n&quot;, y = 5; y--; document.body[&#x27;innerHTML&#x27;] = &quot;&lt;pre&gt;&amp;lt&quot; + (S = &quot;script&gt;\n&quot;) + o + &quot;\n\n&amp;lt&#x2F;&quot; + S) </code></pre> - create a loop that will occur 5 times (one for each row of the output).<p>- initialize some variables `j` and `o` to newlines. `o` will contain our rendered output, `j` will soon become an incrementor.<p>- after each loop, put the contents of &#x27;o&#x27; between two strings of &quot;&lt;script&gt;&quot;.<p>- the `S = &quot;script&gt;\n&quot;` portion helps with spacing and S is no longer needed after this line.<p>#3 - Column Looper:<p><pre><code> for (x = -001; x++ &lt; 63; o += `(r=${r})()`[j++].fontcolor(c ? &#x27;#FF0&#x27; : &quot;#444&quot;)) </code></pre> - loop through the 64 columns, incrementing x and j.<p>- x keeps track of the column, j keeps track of the character within the Function `r`.<p>- each loop, `o` adds a letter from `r`. (In Javascript, functions can be converted to strings which contain their source).<p>- Also add the `)()` to the end of `r`, which the implicit Function.toString() will not have.<p>- Set the fontcolor on that string based on `c` - String.fontcolor() is an old deprecated method which wraps your string in a `&lt;font&gt;` tag.<p>#4 - Renderer:<p><pre><code> c = x &#x2F; 2 % 4 &lt; 3 &amp;&amp; [31599, 19812, 14479, 31207, 23524, 29411, 29679, 30866, 31727, 31719, 1040][(D = Date()[16 + (x &#x2F; 8 | 0)]) &lt; 10 ? D : 10] &amp; 1 &lt;&lt; (x &#x2F; 2 | 0) % 4 + 3 * y </code></pre> - The array of numbers is essentially a font, defining the numbers 0..9 and lastly &quot;:&quot;<p>- We pick which character of this font to render based on a Substring of Date(). Either a number, or &quot;:&quot;.<p>- Date()[16] is where the Time string starts, and chars are rendered 8 blocks wide.<p>- With the beginning `x &#x2F; 2 % 4 &lt; 3` we render 2 spaces of dark characters between numbers.<p>- At the end, render our `font` with the x and y coords<p>- x is divided by two, so all pixels in this font are two characters wide.<p>- font glyphs are 3x5, and thus defined as 15 bits.<p>- for example, the glyph for &#x27;0&#x27; is:<p><pre><code> 111 101 101 101 111 - which results in 0b111101101101111 and therefor 31599 - To render these characters, we bit shift (&lt;&lt;) the number by the row &amp; col*width and see what value is in the `1` place. </code></pre> #5 - Coming together<p>Now just travel the last few steps back up the chain again, and you can see how these characters are placed in `o` - and if `c` is true (we hit a character) it is rendered yellow. `o` is put between a &quot;&lt;script&gt;&quot; and that resulting string is put in document.innerHTML every 100 milliseconds.
moritzwarhier大约 1 年前
This is mind-blowing to me, how the shapes of the digits are encoded in the ten numbers, the sheer brevity of that script.<p>Wow
评论 #40513061 未加载
d3w3y大约 1 年前
I have no clue what a Quine clock is, but I think it would be easier to read if the diagonal stroke on the front of the 1s only extended to the second row of characters from the top, instead of the third.<p>I noticed this because it was just 11:11 in my time zone &gt;:)
评论 #40512879 未加载
评论 #40513313 未加载
Waterluvian大约 1 年前
If I want to roll it by hand and not use a minifier, is there a code golf dictionary of patterns for javascript?
评论 #40512594 未加载
评论 #40512951 未加载