Loading...
What's this?
This page contains a Javascript/HTML reimplementation of NBody, a classic Java programming assignment from COS 126 (Princeton's flagship intro CS course). The original assignment tasks the student with writing a Java program to simulate the motion of N bodies in the plane, mutually affected by gravitational forces (an example of N-body simulation), and animate the results using instructor-provided APIs.
The assignment itself is quite simple, containing a handful of nested for-loops for performing physics calculations and roughly 100 total lines of Java code. Its notoriety arises from the fact that students were expected to churn it out within the third week of the course, with many students having zero prior coding experience. Thus, for perhaps the majority of Princeton undergraduates, the joy upon successfully managing to render a solar system that does NOT flicker, drift away, or throw a myriad of errors to the console, all to the tune of an appropriately crude MIDI rendition of "Also sprach Zarathustra," has strangely become a defining moment of their undergraduate experience.
Source code on GitHub. If you are currently enrolled in COS 126 and want to copy my code, a friendly reminder that academic integrity is a thing. That said, if you can refactor Javascript/HTML into the course's Java environment, you are more than capable of - and would likely save time by - simply doing the assignment yourself.