Python to Draw a Sine wave using Turtle with Full Source Code For Beginners

  • This script draws a sine wave using the built-in Python library Turtle.
  • The image below demonstrates the equation of a sine wave. 

Run the Script:

  1. Open a terminal
  2. Navigate to the “Sine_Wave” directory containing this python file using the command prompt.


python sine_wave.pyCode language: CSS (css)

Source Code:

from turtle import *
from math import *

A = 50      # Amplitude
B = 100     # WaveLength
C = 0       # Horizontal Shift
D = 0       # Vertical Shift

# As x increases y increases and decreases as it is evaluated.
for x in range(-200, 200):
    # Sine Wave Equation
    y = A * sin((2 * pi / B) * (x + C)) + D
    goto(x, y)

mainloop()Code language: PHP (php)


Leave a Comment