54

Show HN: Fall asleep by watching JavaScript load

Not criticism, just explaining a problem I noticed and would make a fun exercise in CSS, or JS: When a letter appears at the end of the line, the reflow (to make sure the whole text is centered) is not smooth, of course it isn't because the text is now n+1 characters wide and the rendering engine has probably been instructed to center it without any fancy delays. I wonder how to achieve a smooth "growth" of line.

I suppose one could render the text off-screen or in an invisible DIV, measure how many letters it has on the target display, find the time to render the line (if the text shows at 2 chars/sec, 20 chars takes 10 seconds to render), measure how wide the element is with the 20 chars, and then make it a DIV where the text within it is left-justified, and the DIV's left margin shrinks at a constant rate per animation frame.

7 hours agonetsharc

Oh yes, absolutely. It bothers me as well, and it strains the eyes, but you know... for such a toy project I half vibe-coded in an hour or so I didn’t bother too much. I agree it should be improved!

It could definitely be a fun exercise. Also maybe just rendering all the text in the same color as the background and then changing the colors of the characters one by one could be an interesting option (just thought about it), but I think yours would render better.

As a side note, I have to say that posting something as simple as this, where you can’t really get too attached to the project and can read feedback in a truly neutral way - instead of just pretending - is so refreshing...

Thanks for your comment!

6 hours agosarusso

I came up with this one night when I couldn’t fall asleep and was looking (waiting) for some data analysis results on a web platform, noticing that the spinner was actually making me sleepy.

I guess that when the brain is engaged in an activity, and that activity becomes boring, it creates good conditions for falling asleep.

9 hours agosarusso

> The time the loader spins, as well as the speed at which the text appears, increases as you go through the story, so that you ideally never reach the end (unless you really, really want to).

Did you mean to say that the "speed at which the text appears" decreases, or am I misunderstanding?

7 hours agostronglikedan

It's tricky. Because it's both. The speed at which the text appears decreases, but the time the loader spins increases. OP should have broken these into two separate thoughts, but chose to combine them and words got wonky.

7 hours agoJeremy1026

Exactly, I made a mistake when writing it down. Thanks to the original commenter for catching it and for your suggestion!

I’ve now updated it to: "As you go through the story, the time the loader spins increases while the speed at which the text appears decreases"

6 hours agosarusso

At what point does it start chanting "when you hear a bell, you'll think you're a duck."

7 hours agoJeremy1026

Feel free to send a PR! But let's parametrize the animal :)

6 hours agosarusso

Please make the background fully black. I am trying to bore to sleep and the background is bothering me a bit in the dark room. Also, add a full screen button so that I don't see anything on my phone at all except the words appearing slowly. May be even remove the next button and go to next part on touch. Also may be the words should appear slower too.

6 hours agosmusamashah

What's the Service Worker for? It doesn't appear to do anything.

6 hours agoameliaquining

The skeleton provided by ChatGPT to get the page to load fullscreen as a PWA included it, so I just kept it. “Maybe in future”... But it’s unnecessary, I should have removed it.

6 hours agosarusso

I can’t think of a more terrible way to fall asleep.

3 hours agoVladVladikoff

Goodbye sound machine!

2 hours agoeffnorwood

Excellent noticing.

7 hours agosandinmyjoints

This is so dumb, I love it

8 hours agozebreus

And so boring

3 hours agoPerz1val

Twisted and great.

8 hours agocoldcity_again
[deleted]
6 hours ago

[dead]