sinus.py

Created by elodie-gamot

Created on November 19, 2021

720 Bytes

Tracer la fonction sinus avec Turtle. La fonction graph() trace la fonction sinus(x) en radians entre -16 et 16. La fonction graph2() trace la fonction sinus(x) en degrés entre -160 et 160.


from turtle import *
from math import *

def f(x):
  return sin(x)
  
def graph():
  droite_graduee()
  penup()
  goto(-160,f(-16)*50)
  pendown()
  for i in range(-160,160,1):
    goto(i,f(i/10)*50)

def f_degres(x):
  return sin(x*pi/180)
  
def graph2():
  droite_graduee()
  penup()
  goto(-160,f_degres(-160)*50)
  pendown()
  for i in range(-160,160,1):
    goto(i,f_degres(i)*50)
    
def droite_graduee():
  penup()
  x=-160
  goto(x,0)
  pendown()
  while x<160:
    setheading(0)
    forward(10)
    left(90)
    forward(3)
    backward(3)
    x+=10
  penup()
  y=-100
  goto(0,y)
  pendown()
  while y<110:
    setheading(90)
    forward(50)
    right(90)
    forward(3)
    backward(3)
    y+=50

During your visit to our site, NumWorks needs to install "cookies" or use other technologies to collect data about you in order to:

With the exception of Cookies essential to the operation of the site, NumWorks leaves you the choice: you can accept Cookies for audience measurement by clicking on the "Accept and continue" button, or refuse these Cookies by clicking on the "Continue without accepting" button or by continuing your browsing. You can update your choice at any time by clicking on the link "Manage my cookies" at the bottom of the page. For more information, please consult our <a href="https://www.numworks.com/legal/cookies-policy/">cookies policy</a>.