# Coding Stories: Creative Calculations

When I was 17 years old I fell in love with Physics. School was not always an easy place for my teenage self. I was a slow reader and my diagnosis of attention deficit disorder came with frequent distractions in the classroom. But along came this body of extraordinary ideas within which my learning challenges seemingly disappeared. I immediately knew that Physics was the subject for me.

Over the past 30 years I have studied Physics, taught Physics and engaged in many debates about Physics. Lately I have been looking for new ways to explore creative expression on the computer. I love the way computers can display moving forms on the screen bringing art to life. As art is a powerful way to evoke emotions in others, I wonder if computer art can convey the emotions I experienced when I first fell in love with Physics. I suppose the question I am asking is: Can my experience of the beauty of Physics be adequately expressed through a computer screen?

One of the most elegant examples of motion, used by Galileo to make numerous discoveries, is the pendulum. According to Wikipedia, pendulums can be traced back to first century China where one was used to determine the direction of an earthquake. In Galileo’s time pendulums served as accurate time keeping devices leveraged in various branches of science and technology. The motion of a pendulum is called periodic because it is a cycle that repeats. In fact the word period is a precise scientific term that describes the duration of the pendulum’s cycle. Interestingly repetition and rhythm are also central to the artistic process in music, dance, painting, and photography to name a few examples. The swing of a pendulum is so captivating that it has become synonymous with the practice of hypnosis and so I am hopeful that it will create an engaging context for this story.

If you tie a weight to a string and tie that string to a fixed pivot then you can experience a pendulum for yourself. The simplicity of experiencing Physics phenomena is another feature that drew me to the field.

However, in this case I want to create a computer simulation of a pendulum so I will need to first develop an understanding of how it works. My hope is that figuring out how to accurately simulate the motion of a pendulum will enhance the aesthetic experience perhaps comparable to the way you enjoy a meal you cooked yourself. I guess we shall see.

Almost the entirety of the moving world with the exception of the very small and incredibly fast can be characterized by one simple formula called Newton’s second law of motion.

In the case of the pendulum we will be focusing on the motion of the hanging weight which is technically called the bob. The force of gravity which ultimately determines its motion luckily has a constant acceleration on the surface of the Earth given by

However, there is one added complexity. The arm (the length of string attaching the bob to the pivot) is in tension and is putting an additional force on the bob. The sum of these two vector forces is what creates the characteristic curved swing of motion that it exhibits. There are a number of ways to represent this model mathematically, but I think the most elegant might be expressing the state of the pendulum in terms of the angle between a vertical line and the pendulum arm. I will use the symbol theta for this angle. Similarly the velocity of the pendulum can be expressed as angular velocity (omega) and the acceleration as angular acceleration (alpha). In this way the pendulum is confined to its circular path and is described by one parameter.

The tension on the arm of the pendulum has the inverse magnitude of the gravitational component parallel to the arm causing the two to cancel out. Therefore the resultant force on the pendulum bob is the perpendicular component of the gravitational force. We can calculate this component using the sine function.

Now that we have the angular acceleration we can convert this into a differential equation for the angular velocity. However, solving differential equations can be a challenge. This is where the computer can be particularly helpful. Instead of solving the differential we will simply update the values over time step by step. First we can define a small time step dt. During that step the angular velocity will change by the value of alpha multiplied by dt. We can express that as follows using the greek letter omega for angular velocity:

Now we have all the procedures that we need to determine the angle of the pendulum over time. All that is left is to draw the pendulum at the given angle theta and then animate it.

I added some sliders and buttons so that you can play with the parameters. This results in a fairly standard pendulum simulation that you might find used in a high school Physics class. To be honest with you I am pretty happy with this simulation as it is. But I want to take the idea a little further by exploring the artistic side of science. Beyond demonstrating the properties of periodic motion I want this simulation to express my love of Physics. So I jazzed up the pendulum by creating some shading in the bob using concentric circles and adjusting the hue, saturation and size of the bob over time. You can see this by clicking the “Creative” button.

Now this is starting to get fun. Note that the changing size of the bob might appear to violate normal Physics. And to be honest it does, but keep in mind that the mass or size of the bob is not in the equation so it is not actually a factor in my model. To enhance the artistic experience I decided to populate the screen with multiple pendulums. If you have studied pendulums in a Physics course you might remember that the length of the pendulum is an important factor in determining the period. So to explore that idea I created 25 pendulums each with the same starting angle (amplitude) and different lengths.

Making pendulum art is an open ended experience. I played for a long time changing various parameters, seeing what happened, trying to decide which results were visually appealing and then further adjusting the parameters. I arrived at varying the amplitude and length of each pendulum to create an interesting pattern of motions over time. I really like the result shown below. What I found interesting was that my knowledge of Physics was helpful in figuring out what I might want to try in the simulation. Conversely, the more I explored different configurations the more I thought about the Physics of the pendulum and developed better intuition for how it would behave. I wanted to create a piece that conveyed disorder while also expressing the underlying pattern that defines a pendulum. I would argue that pursuing this intersection between science and the arts is not only enjoyable but it leads to new insights not available when pursuing arts or science separately. In fact perhaps the reason I was at first skeptical about conveying my love for Physics through art was because the arts are so often separated from STEM education and professional practice in many STEM fields. I wonder how much richer the Arts and STEM could be by teaming up and finding more intersections between them as I have attempted to do here.