8-6 绘制正弦和余弦曲线
最编程
2024-04-22 10:22:53
...
在一幅图中同时绘制正弦曲线(红色实线)和余弦曲线(蓝色点画线),设x取值范围[0,16]。
运行结果
有点瑕疵
并且我发现python可以用中文命名,因此浅浅尝试了一波
import turtle
import math
屏幕 = turtle.Screen()
屏幕.bgcolor("white")
屏幕.title("Python Turtle - 坐标系、sin曲线和cos曲线")
画笔 = turtle.Turtle()
画笔.speed(0)
def 绘制坐标系():
画笔.penup()
画笔.goto(-200, 0)
画笔.pendown()
画笔.forward(400)
画笔.penup()
画笔.goto(0, -150)
画笔.pendown()
画笔.left(90)
画笔.forward(300)
画笔.penup()
画笔.goto(-200, 0)
画笔.pendown()
画笔.left(150)
画笔.forward(10)
画笔.penup()
画笔.goto(-200, 0)
画笔.pendown()
画笔.right(150)
画笔.forward(10)
画笔.penup()
画笔.goto(0, -150)
画笔.pendown()
画笔.left(60)
画笔.forward(10)
画笔.penup()
画笔.goto(0, -150)
画笔.pendown()
画笔.right(60)
画笔.forward(10)
# 绘制sin曲线
def 绘制sin曲线():
画笔.penup()
画笔.goto(-200, 0)
画笔.pendown()
画笔.color("red")
for x in range(-200, 201, 2):
y = 100 * math.sin(math.radians(x))
画笔.goto(x, y)
# 绘制cos曲线
def 绘制cos曲线():
画笔.penup()
画笔.goto(-200, 0)
画笔.pendown()
画笔.color("blue")
for x in range(-200, 201, 2):
y = 100 * math.cos(math.radians(x))
画笔.goto(x, y)
绘制坐标系()
绘制sin曲线()
绘制cos曲线()
画笔.hideturtle()
屏幕.mainloop()
上一篇: 要求绘制包含正弦和余弦曲线的图形
下一篇: 用 R 绘制正弦曲线