A community dedicated to all things web development: both front-end and back-end. For more design-related questions, try /r/web_design.
More posts you may like
-
upvotes · comments
-
r/webdev
A community dedicated to all things web development: both front-end and back-end. For more design-related questions, try /r/web_design.
Members Online upvotes · comments
-
r/FPGA
A subreddit for programmable hardware, including topics such as: * FPGA * CPLD * Verilog * VHDL
Members Online upvotes · comments
-
upvotes · comments
-
r/webdev
A community dedicated to all things web development: both front-end and back-end. For more design-related questions, try /r/web_design.
Members Online upvotes · comments
-
r/ProgrammerHumor
For anything funny related to programming and software development.
Members Online upvotes · comments
-
r/godot
The official subreddit for the Godot Engine. Meet your fellow game developers as well as engine contributors, stay up to date on Godot news, and share your projects and resources with each other. Maintained by the Godot Foundation, the non-profit taking good care of the Godot project - consider donating to https://fund.godotengine.org/ to keep us going!
Members Online upvote · comments
-
r/Games
The goal of /r/Games is to provide a place for informative and interesting gaming content and discussions. Submissions should be for the purpose of informing or initiating a discussion, not just with the goal of entertaining viewers. Memes, comics, funny screenshots, arts-and-crafts, etc. will be removed.
Members Online upvotes · comments
-
upvotes · comments
-
r/webdev
A community dedicated to all things web development: both front-end and back-end. For more design-related questions, try /r/web_design.
Members Online upvotes · comments
-
r/webdev
A community dedicated to all things web development: both front-end and back-end. For more design-related questions, try /r/web_design.
Members Online upvotes · comments
-
r/webdev
A community dedicated to all things web development: both front-end and back-end. For more design-related questions, try /r/web_design.
Members Online upvotes · comments
-
r/webdev
A community dedicated to all things web development: both front-end and back-end. For more design-related questions, try /r/web_design.
Members Online upvotes · comments
-
r/godot
The official subreddit for the Godot Engine. Meet your fellow game developers as well as engine contributors, stay up to date on Godot news, and share your projects and resources with each other. Maintained by the Godot Foundation, the non-profit taking good care of the Godot project - consider donating to https://fund.godotengine.org/ to keep us going!
Members Online upvote · comments
-
r/webdev
A community dedicated to all things web development: both front-end and back-end. For more design-related questions, try /r/web_design.
Members Online upvotes · comments
-
r/blenderhelp
For help with Blender problems, also consider visiting https://blenderartists.org/c/support or https://blender.stackexchange.com/
Members Online upvote · comments
-
r/webdev
A community dedicated to all things web development: both front-end and back-end. For more design-related questions, try /r/web_design.
Members Online upvotes · comments
-
r/webdev
A community dedicated to all things web development: both front-end and back-end. For more design-related questions, try /r/web_design.
Members Online upvotes · comments
-
r/linuxquestions
A subreddit for asking question about Linux and all things pertaining to it.
Members Online upvotes · comments
-
r/webdev
A community dedicated to all things web development: both front-end and back-end. For more design-related questions, try /r/web_design.
Members Online upvotes · comments
-
r/webdev
A community dedicated to all things web development: both front-end and back-end. For more design-related questions, try /r/web_design.
Members Online upvotes · comments
-
upvotes · comments
-
r/webdev
A community dedicated to all things web development: both front-end and back-end. For more design-related questions, try /r/web_design.
Members Online upvotes · comments
-
r/webdev
A community dedicated to all things web development: both front-end and back-end. For more design-related questions, try /r/web_design.
Members Online upvotes · comments
-
r/webdev
A community dedicated to all things web development: both front-end and back-end. For more design-related questions, try /r/web_design.
Members Online upvotes · comments
Can someone explain this to me? How does it work?
It's a [quine](https://en.wikipedia.org/wiki/Quine_(computing)), a piece of code that gets no input and outputs its own source code. The excellent The Art of Code talk touches on it, and the whole talk is on its own level of awesomeness.
the game of life (everyone probably did that in college) bit alone has me hooked on the rest - great talk
It just highlights the parts of the code that show the time
Yeah, I can see that it’s highlighting some text to show the numbers. I guess I’m more curious about how that works vs. what’s happening.
The code is minified so I'm not 100% but from what I'm reading it has an interval that runs each second, it calls document.body.innerHTML to update the text, gets the current time, and highlights the letters based on their index. Positions of the letters that need to be highlighted are encoded in a short string, I suppose as binary probably (1/0 depending on if the letter should be highlighted for any number on the clock)
ig its just like telling which led should glow on an led display, just in text telling which characters should glow by identifying a variable print output for each time. Im just guessing tho i dont even know how to program a clock🥲
It looks a bit more confusing than it is, though the bit manipulation stuff is confusing. With some changes to formatting for clarity, I'll try to break it down.
This sets up an interval and declares a function, pretty common stuff. Next is where it begins writing to the document, as well as setting up a loop. The way it does that is a very bad practice, but that isn't really the point of the code.
This is a nested for loop, and does the coloring for the clock. There is a string literal referencing the function that gets a string of the function, and each letter gets iterated over, with a ternary operator to determine the color. Again, nothing too crazy so far. I'll break the next part down out of order for ease of understanding.
This is another ternary operation, though its sort of tricky to parse, but easier when broken down. Starting at
Date()
, it returns a string, which is then indexed. The hour is the 17th character of the date string, so the index is then 16 plus something. That something isx
, essentially the current text column. There are 8 sections of the clock, which is 64 characters wide, so a division by 8 and floor will return the correct character at the current column. Now onto the actual ternary section, it is just a comparison to the string "9". For all of the "numbers" this will evaluate to false, however,"9" < ":"
is true. This means that the value of i is either 3 times the current digit, or 30 in the case of a colon. It's important to note thati
here has the value of the ternary operation.This part is actually fairly easy to explain, sort of. The string in there is a concatenation of base 36 numbers. Each of these groups is 3 characters long, and are indexed by the value given by the previous section. This is essentially the "font" for the clock, kind of stored as a bitmap. For a sort of quick example:
That looks a lot like a zero there. That works for all the other groups as well. So how does that fit into the rest of the code?
So here are some variables that came up earlier,
c
being the choice for a character being on or off,y
being the current row. Without going into too much detail, this is using some bit shifting and masking to get the value from the previous section at the current column and row. This is needed because each row of text is done line by line, so the x and y values of sort need to be known. And that's about all there is to it. I'm far from an expert so I probably got some things wrong, but I think that's the general gist of things.I love the concept! maybe you should experiment with changing the font to make it more readble. But great work!
Made some tweaks. How's this? https://codebeautify.org/real-time-html-editor/y24f8f1f7
The code length is `% 5 > 0`... shoddy workpersonship... No, just kidding. It's pretty cool.
It's refreshing so fast that I couldn't even open the <pre> tag in the inspection tool...
Use the debugger to pause the script
Use the debugger pfft I'll stick with my console.log('here') thank you very much
Lol
Jaw-dropping. I really hope I get to something like this level of ability in my career.
This is incredible, great work!
Haha noice
That is beautiful!
WoW.
I'm staring at the code and I have no idea how it manages to do it...
This is the coolest
Comment removed by moderator
Dont advertise it on random posts
The pages don’t look very good on mobile. I’d work on the responsiveness on the chapter pages for example
Okay dude, noted the point, working on it.