Newton’s Gravity as Coded by an 11yo Student

Sometimes what the students do at our school amazes me, but one app has always stuck out in my mind.  We have a 13yo student who I’ll call LN, who’s been with us since we opened.  When he was 11, he created this incredible app he calls Gravity Crash.  LN is a big fan of physics, and it happened that his Code Coach was too – and so some pretty amazing coding ensued.

LN’s game looks and plays like a standard billiards game (which in itself is already quite hard to code in Python).  But instead of hitting the cue ball, you create what he called “gravitational anomalies” (I guess he was a Start Trek TNG fan too!) that sucks the cue ball towards it (and orbits it, if placed correctly), using newtonian physics formulas.  What?!

Take a look here, and be sure to widen the game screen so you can see the entire billiard table.  You can also open Gravity Crash in a new window.

 Newton's Law of Universal Gravitation
Newton’s Law of Universal Gravitation


So I want to point out that, even as a coder of 20 years, some of this would be mind-boggling for myself to write.  If you’re not a coder, just scroll through the code and you’ll be blown away.  If you’re a coder, check out how he handles collisions starting on line 171 (yep, granted, he needed some help on the vector and collision math!).  And if you’re a physicist, check out line 234, my favorite.  Break down the component parts, and [gasp!!], you have Newton’s Law of Universal Gravitation.  Let me sum that up for you, an 11 yo coded a pretty complex game in Python, and then decided to use Newtonian formulas to simulate gravity.   Niiiiiiice.

Now mind you, in our model, we have a Code Coach, directly mentoring our students – so building the app wasn’t completely unaided.  Moving the balls, collisions, even just setting up the triangle, requires some really good math knowledge.   But LN, again, an 11yo, understands how most of the code works, and coded a large part of it.  Think about how much coding AND math experience he gained coding this app.  Mind.  Blown.


Categorized as Coder Blog

By Hansel

Hansel is the Founder & CEO of theCoderSchool and has been at the heart of it ever since its inception in 2013.