usingMaths.com
Demonstrating and showing pupils and students one application of Mathematics.







<< PreviousNext >>

Code to Animate an Image Body through a Sine or Cosine Curve in Python



How to Simulate Sinusoidal Curves in Python

Periodic functions produce an infinite order of sinusoidal curves.
The sine function has the general form y = asinθ;
and the cosine function has the general form y = acosθ + c;
where θ is angle in radians and a is an arbitrary constant that heightens the curve.



Code to Animate a Graphic Object through a Periodic Curve in Python

To make a graphic (dot) travel by the equation of a sine / cosine function, continuously increment θ by some angle interval (in radians), and use the equation to get the corresponding y value; using any c that gives a satisfactory height.

Create a new file; File, New File.
Call it PeriodicFunction.py.
Type out the adjoining Python / Turtle code for animating an image body through the path of a sine / cosine curve.



Note: To get a cosine curve animation, just replace sin with cos.









<< PreviousNext >>