Recently I realized that trying out physics and math projects is a really great and gratifying way to learn programming--and sometimes a lot more simple than it seems! Here are a few of my favorite projects from this summer, roughly in chronological order.
All three of these work using the wave equation, which says that the second derivative of the wave height with respect to time is proportional to the second derivative of wave height with respect to position--or, in other words, the acceleration of the wave at a particular point is proportional to the waveform's concavity at that point. In this example, the concavity at a given point is calculated using finite differences, i.e.
One interesting these programs show is that the wave equation implies a constant wave speed (in air, this is the speed of sound, and in electromagnetism, this is the speed of light).
This is just a fun project that uses a set of cloned blur images with randomized velocities to generate smoke. Different versions can be made to make this look more like a flame.
This Markov Chain generator uses a brute force algorithm where, after any set of two words, the program looks for any other instance of those two words, picks one at random, and then takes the next word after that particular instance. Then, the program repeats this process with the new next set of two words.
The RSA encryption example just demonstrates how two exponentiations can invert each other if they multiply to something
The code below shows a basic implementation for importing the Word2Vec library into WoofJS for use in any kinds of games. Note that the cosine similarity can be calculated by dotting two word vectors and then dividing by the product of their magnitudes. More information in the code. Library used.
This program applies force proportional to
Note: A non-linear version of these chains of springs, i.e. where the force is not linearly defined on length, seems to be a topic of modern research. A fun project could be simulating a spring with a non-linear force function yourself.
This program simulates the orbits of satellites, given the Earth and the Sun as gravitational sources. A few potential observations: (1) The nature is generally chaotic, and orbits with similar starting positions can end up far away from each other, (2) You can sometimes see parabolic orbits around the sun, especially when the Earth is far away, and (3) you can that the oldest orbits sometimes get caught around Lagrange Points (demo), especially L4 and L5.
Here are a few websites with additional projects I really liked: