Heard Simon give his Russian grandparents a lecture in the playroom, via FaceTime. When I came in, this is what I saw on the whiteboard. Simon proudly said he figured out how to calculate the arctangent. Why, what do you talk to your Grandmom about?
Tag: sin cos tan
Perlin Noise Combined with Sine Wave Translation into Processing
Simon translated Daniel Shiffman’s Graphing 1D Perlin Noise tutorial into Processing (Java). The project involved combining perlin noise and sine wave:
He also attempted to translate Perlin Noise Flow Field into Processing:
Polar to Cartesian converter (Simon’s own code)
Simon built a Polar to Cartesian converter (Simon’s own code). You can enter the radius in pixels and the angle in degrees, click “convert” and you get the coordinates in x and y and a circle appears n that spot.
You are welcome to play with Simon’s converter online in CodePen at: https://codepen.io/simontiger/pen/MmdodP
Simon is also planning to make a similar converter for Spherical to Cartesian (where you would enter radius, latitude and longitude and convert those into x,y,z).
Here Simon explains the formulas to convert between Polar and Cartesian coordinates:
Steering Behaviors: flow field, dot product, scalar projection
Simon’s big project the last couple of days was about making a steering behaviors database, complete with a navigation menu (in Cloud9):
He managed to finish the first two examples – “Seek and Flee” and “Pursuit and Evasion” – and worked on the Flow Field Following and Path Following.
As recommended by Daniel Shiffman, Simon largely relied on the paper called Steering Behaviors For Autonomous Characters (written by Craig W. Reynolds from Sony). As Simon told me, he tried to guess the code to make the static drawings in the paper come to life. For instance, for the “Seek and Flee” example, Simon animated this drawing:
Simon also made a “Seek” example in the language called Lua (from the Codea app):
The second example was about Pursuit and Evasion:
Simon also explained to me how Flow Field Following worked:
Another steering behavior he scrutinized was Path Following. For Path Following, he first had to learn what the “dot product” was. In math, the dot product or scalar product is an algebraic operation that takes two equallength sequences of numbers (usually coordinate vectors) and returns a single number.
The way Simon learns is usually by studying (deconstructing) and memorizing the formulas (even if he doesn’t fully understand them in the beginning). After he comes back to the formula later on he seems to have grasped the meaning of it. I often observe him actually apply different formulas in real life. When it comes to the “dot product”, Simon is in the beginning of the learning curve:
The formula for scalar projection is:
or the way Simon put it:
Pinball Dilemma. Simon’s own code.
Simon heard the word “pinball” and looked it up on Google (never played it himself). He then decided to write a pinball program in Processing (Java), but soon encountered a mathematical dilemma: the flippers at the bottom of the canvas (their role is to protect the ball from falling) didn’t stop rotating the way Simon wanted. This slowly unfolded into a real drama.
Here Simon explains the problem:
As his math tutor came to give Simon his regular math lesson, Simon turned to him for help and they thought to have solved the problem by applying cosine and setting it to 1. But after the teacher left Simon realized that the angular velocity of the flipper was too high for the cosine to reach 1, which would mean the flipper wouldn’t stop. Unless approximate values could be programmed, which Simon said he doubted. Simon was crying hard. We just sat there hugging after we recorded this:
Then Simon tried writing an approximate function.
I’m not sure he will come back to this unfinished project. It is all part of his learning experience and learning to apply math/ physics though.
Approximate cosine:
Approximate Function and 1D distance function:
Pendulum Force
This is a beautiful “lecture” that Simon in his pajamas, chocolate paste adorning is face, game me Friday morning. He spoke about pendulum force, a force he was about to apply in a coding project.
The other videos form the very beginning of the lecture, with Simon plays with sine and cosine and explains why location, velocity and acceleration can be vectors and can be angles:
And this is the code where pendulum force is used. It’s an example from The Nature of Code book by Daniel Shiffman, from Chapter 3 on Oscillation:
Translating examples from The Nature of Code into Lua (Codea)
This morning Simon attempted to make a more difficult translation in the Codea app of an example from Daniel Shiffman’s book The Nature of Code (Java) into Lua. It concerned the Gravitational Attraction example from Chapter 2 of the book, Forces. Simon is happy with Codea because “It’s really readable!”, “You don’t need semicolons and parenthesis!” and all logic operators are actually typed in words (“and”, “or”, “not”).
Unfortunately, the function Simon introduced as substitute for mouse pressed release on the touch screen didn’t seem to work:
Simon did successfully translate the simple harmonic motion example from Chapter 3, Oscillation: “I use trigonometry!”
For this example, he had to look up a complex formula for mapping a range to another range on the internet b1 + (s – a1)*(b2 – b1)/(a2a1) “because map function doesn’t exist in Codea, so I wrote that function”.
Swapping the axes:
Polar Roses in JavaScript
Simon created an engine that uses trigonometrical (polar coordinates) formulas to produce beautiful roses. He reproduced the code originally created by Daniel Shiffman from memory and searched for the formulas on Wikipedia.
You can play with this project here (click on the play button to run): https://alpha.editor.p5js.org/simontiger/sketches/HkU9i2h1b
Oscillation and Drag Force: Spring Project.
Today Simon was watching Daniel Shiffman’s tutorials to learn about drag force and how to apply it when building a spring simulation in p5.js. Simon wrote the formula for drag force in Microfost Word and looked up all the variables:
While building a spring in p5.js, Simon talks about the 3 laws of Isaac Newton:
The project is based upon Daniel Shiffman’s book The Nature of Code, specifically Chapter 3 (Oscillation). Simon spent the rest of the evening studying “simple harmonic motion”, periods and amplitudes. Here is an excerpt from Daniel Shiffman’s book:
y = sine(x)
You’ll notice that the output of the sine function is a smooth curve alternating between –1 and 1. This type of a behavior is known as oscillation, a periodic movement between two points. Plucking a guitar string, swinging a pendulum, bouncing on a pogo stick—these are all examples of oscillating motion.
This is what is known as simple harmonic motion (or, to be fancier, “the periodic sinusoidal oscillation of an object”). It’s going to be a simple program to write, but before we get into the code, let’s familiarize ourselves with some of the terminology of oscillation (and waves).
Simple harmonic motion can be expressed as any location (in our case, the x location) as a function of time, with the following two elements:

Amplitude: The distance from the center of motion to either extreme

Period: The amount of time it takes for one complete cycle of motion
Looking at the graph of sine, we can see that the amplitude is 1 and the period is TWO_PI; the output of sine never rises above 1 or below 1; and every TWO_PI radians (or 360 degrees) the wave pattern repeats.
Math > Back to Brilliant.org to train Trigonometry
Since Simon has been using so much trigonometry in his programming lately, we decided to review some SOHCAHTOA during his regular math classes and did some Brilliant.org quizzes:
Simon also enjoyed building some trigonometric graphs: