📌  相关文章
📜  Sin , Cos Graph 使用 python turtle. - Python 代码示例

📅  最后修改于: 2022-03-11 14:45:33.940000             🧑  作者: Mango

代码示例1
# Sin , Cos Graph using python turtle module
from math import pi, sin, cos
import turtle



sc = turtle.Screen()

t = turtle.Turtle()
t.pensize(1)
t.pencolor("gray")
t.speed(0)

def goto(x, y):
      t.up()
      t.goto(x, y)
      t.down()

def rep():
      for x in range(-330, 330, 20):
            goto(x, 0)
            t.dot(3)
            t.sety(360)
            t.sety(-360)
      for y in range(-330, 330, 20):
            goto(0, y)
            t.dot(3)
            t.setx(360)
            t.setx(-360)
      goto(0, 0)
      t.pencolor("red")
      t.dot(8)
      
rep()
goto(-360, 0)

# t.speed(10)

for x in range(-360, 360, 5):
      t.pensize(3)
      t.pencolor("blue")
      t.goto(x, sin(pi / 180 * x)*128)      # Replace Sin with Cos if necessary.
      t.dot(3)
      
sc.exitonclick()