Skip to main content
Penumbra

Chapter 1: Tuples

Posted on

The first chapter of the book focuses on setting up a foundational “tuple” library for operations on vectors and points. I didn’t really expect there to be much to show for this other than working tests. But the chapter ended with a suggestion for creating a small program to experiment with a mini physics simulation that fires projectiles at various angles and velocities and have their trajectories effected by gravity and wind.

I decided to take this a step further and create a web component that would animate the projectile on a canvas. Here it is in action:

<projectile-cannon>

I attempted to represent the z axis by increasing/decreasing the size of the projectile. Something seems off with that though.

GitHub Copilot was helpful when writing the tuple tests. I could take the Gherkin test from the book, put it in a comment, and Copilot would generate the test code using the Gherkin-inspired test suite functions I wrote.

One thing that pained me as I wrote the implementation of the Tuple methods was knowing how inefficient they will be running in a JavaScript runtime. Vector math is the usual use case for SIMD instructions, but presumably JavaScript engines are not detecting that these operations could be compiled to SIMD instructions. I did a bit of forward research though and discovered that WebAssembly has SIMD support! At some point I plan to look at reimplementing Penumbra in AssemblyScript — but I first want a plain JavaScript baseline to compare against.

Onward to chapter 2!