1. 程式人生 > 其它 >Python_Turtle繪製正弦函式(採用函式描點法繪製)(turtle實現)

Python_Turtle繪製正弦函式(採用函式描點法繪製)(turtle實現)

目錄
【注1】採用函式描點法繪製圖像,最後一篇。要實現其他的函式影象使用turtle海龜庫繪製,在程式碼中替換成相應的函式表示式即可。
【注2】採用點動成線的原理繪製,密集的描點即可!

1.SinDot.py

import turtle
import math
turtle.speed(0)
turtle.delay(0)
turtle.tracer(False)
i=-150
while(i<=150):
    i=i+0.1
    turtle.penup()
    y = 60*math.sin(0.06*i+0.5)+20
    turtle.goto(i,y)
    turtle.pendown()
    turtle.dot(4)
turtle.penup()
turtle.goto(0,0)
turtle.pendown()
turtle.seth(90)
turtle.fd(230)
turtle.seth(-70)
turtle.fd(15)
turtle.penup()
turtle.goto(0,230)
turtle.pendown()
turtle.seth(-110)
turtle.fd(15)
turtle.penup()
turtle.goto(0,0)
turtle.pendown()
turtle.seth(-90)
turtle.fd(90)
turtle.penup()
turtle.goto(0,0)
turtle.pendown()
turtle.seth(0)
turtle.fd(150)
turtle.seth(-160)
turtle.fd(15)
turtle.penup()
turtle.goto(150,0)
turtle.pendown()
turtle.seth(160)
turtle.fd(15)
turtle.penup()
turtle.goto(0,0)
turtle.pendown()
turtle.seth(-180)
turtle.fd(150)
turtle.penup()
turtle.goto(0,-120)
turtle.write("正弦函式方程影象:y = 60*math.sin(0.06*i+0.5)+20",True,align="center")
turtle.goto(0,-300)
turtle.done()

2.結果示例