Live data from Hacker News

Annotated code: Circles bouncing off lines

annotated-code.maryrosecook.com

1–10 of 70 posts

Re: Annotated code: Circles bouncing off lines

#4
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.

Re: Annotated code: Circles bouncing off lines

#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!!

Re: Annotated code: Circles bouncing off lines

#8
post #6

Neat! Is the code annotation page a library?

I believe the OP is using Docco.js (which has been ported to many languages, e.g. Rocco for Ruby, Shocco for Shell, Pycco for Python, Gocco for Go, etc.)

http://jashkenas.github.io/docco/

There's different ways to configure the output and layout...the Docco homepage uses a single-column format, whereas the OP uses the double-column format.

Re: Annotated code: Circles bouncing off lines

#10
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?

It doesn't create an ever-growing stack.

tick calls requestAnimationFrame, tick returns, the browser waits for the next frame and calls tick...

Post reply on HN