Live data from Hacker News

Annotated code: Circles bouncing off lines

annotated-code.maryrosecook.com

11–20 of 70 posts

Re: Annotated code: Circles bouncing off lines

#11
post #9

so tick calls requestAnimationFrame that calls tick that... Doesn't it create an ever growing stack? Isn't there a way to do it with a while loop?

requestAnimationFrame just queues up the callback for later, it doesn't actually call into it. There's no stack growth.

Re: Annotated code: Circles bouncing off lines

#13
post #3

Very cool. Interesting bit: The outcomes of the falling balls seem to differ every time, which corroborates the fact that any minor change in initial state results in vastly different outcomes. Edit: Or am I just imagining it?

~~The simulation clock is based on the actual frame rate achieved via requestAnimationFrame().~~ Edit: Actually, it looks like the physics portion takes constant (but implicit) time steps each frame, but the time that a circle enters the simulation is based on the actual frame rate, which means when a given circle appears, the lines could be in a different location from previous runs.

Thank you.

Re: Annotated code: Circles bouncing off lines

#14
post #5

Trying to keep the narrative of explanation in the same linear order as the code makes for a surprisingly difficult to understand item. Would be neat to see more "traditional" literate programming techniques applied here. All of that said, really cool, and seriously thank you for sharing!!

I wonder if the weaving in literate code is one of the things that could only have been invented to deal with Pascal. It is useful to be able to rearrange the presentation even in JavaScript, but I doubt it would be enough of a pain point for people to invent weaving in an alternate history were literate programming was born on more flexible languages.

Re: Annotated code: Circles bouncing off lines

#19
post #6

Neat! Is the code annotation page a library?

The manual function signatures are a bit annoying. In particular, why don't the author's comments include the parameters? I wonder if docco has an extension to create these automatically. I much prefer the docstrings, and the new type annotations in python, which make this much nicer.
Post reply on HN