Extending Block-based Programming with Physics!

Aug 15, 2023·
Thomas W. Price
Thomas W. Price
· 2 min read

Snap! is a block-based programming language that lets students create expressive apps and simulations easily. This is especially powerful for non-Computer-Science majors, like those in my introductory course, who may want to apply programming to solve problems in their own domains.

I built this extension to Snap! to allow students to make accurate physics simulations and physics-based games. Making more advanced products can motivate students to learn programming, while also building an intuitive understanding of physics.

Science Simulations

For example, a simple program can help students understand how the orbit of a planet is affected by its starting speed.

If you want to see the code for any linked demo, press the button to exit full screen mode.

The code itself is straightforward to read and edit.

By modifying 2 lines of code, students can experiment with escape velocity to build an intuitive understanding of it.

Open-ended Exploration

The physics engine, based on matter.js, is quite flexible, and allows students to create open-ended simulations. The extension takes care of the hard parts, like creating bounding boxes, so students can focus on their code.

Physics-based Games

In my introductory programming class, students make an open-ended project that connects to their interests and addresses a problem they see in the world. Many create games, including fun and serious games. By leveraging physics, students can create more powerful games, like what they see on their phones and in their browsers.

My extension also adds camera controls and the ability to save and load levels, which allows Snap! to make far more advanced games than would otherwise be possible – like this this Angry Birds inspired app!