源码
# 开发者:a_blue_fat
# 日期:2024/8/14
# 时间:19:00
# 文件名称 三角函数画图
# 开发者 a_blue_fat
# 日期2024年8月9日
import math
import turtle as t
from 三角函数得数 import cos, sin, tan
t.setup(1000, 800, 0, 0)
#将画画点移动到指定位置写入需要标记数字
def write_num_x_y(x, y, num):
t.penup()
t.goto(x, y)
t.write(num, align="right", font=("楷体", 12, "bold"))
# 画标记位置对应值的线条
def write_line(x,y):
t.pendown()
t.goto(x, y)
t.penup()
def write_line_curve(x, y):
if y>-300+33+203:
print("w")
else:
if y>= -333:
t.pendown()
t.goto(x, y)
t.penup()
#写入对应数字
# t.write("一朵小花\n", align="right", font=("楷体", 16, "bold"))
if __name__ == '__main__':
# 初始标记纵坐标的值
y_setnum = 1000
# 初始标记横坐标的值
x_setnum = 0
#开始标记的初始位置
first_y = -300
first_x = -400
# 循环输入纵坐标
first_y += 33
while True:
first_y += 66
write_num_x_y(first_x, first_y, f"{y_setnum/1000}")
# 画标记线
t.goto(first_x ,first_y)
write_line(first_x+10, first_y)
y_setnum += 25
# 初始化标记初始位置的变量
if y_setnum > 1175:
first_y = -300
break
# 循环输入横坐标
first_x += 20
while True:
first_x += 100
x_setnum += 1
write_num_x_y(first_x, first_y, f"{x_setnum}π")
# 画标记线
t.goto(first_x-10, first_y+20)
write_line(first_x-10,first_y+30)
# 初始化标记初始位置的变量
if x_setnum > 7:
first_x = -300
break
# 定义横纵坐标线初始位置变量
mark_line_x = first_x-90
mark_line_y = first_y+33
# 输入横纵坐标线
t.goto(mark_line_x, mark_line_y)
write_line(mark_line_x, 300)
t.goto(mark_line_x,mark_line_y)
write_line(410, mark_line_y)
#画曲线
#设置写入颜色
t.color("red")
# 设置曲线画入初始位置
curve_first_x = mark_line_x
curve_first_y = mark_line_y
# 设置x轴反向初始值
in_x = 0
while True:
#获取cosx对应的值
# in_y = cos(in_x)
# #获取sinx对应的值
# in_y = sin(in_x)
#获取tanx对应的值
in_y = tan(in_x)
# 获取对应画到位置的值
if in_x % 20 == 0 and in_x != 0:
#开始画线
write_line(curve_first_x+in_x*10, curve_first_y+in_y)
t.goto(curve_first_x+in_x*10, curve_first_y + in_y)
elif in_x == 0:
t.goto(curve_first_x+in_x*10, curve_first_y + in_y)
else:
#开始画线
write_line_curve(curve_first_x+in_x*10, curve_first_y+in_y)
print(in_y)
# 画到最大值停止绘画
in_x += 1
if in_x > 80:
break
print(cos(float(9 % 20/10)*math.pi)*66)
t.done()
pass
if __name__ == '__main__':
pass
实现画出边界线的代码
# 定义横纵坐标线初始位置变量
mark_line_x = first_x-90
mark_line_y = first_y+33
# 输入横纵坐标线
t.goto(mark_line_x, mark_line_y)
write_line(mark_line_x, 300)
t.goto(mark_line_x,mark_line_y)
write_line(410, mark_line_y)
实现画出标记不同坐标的符号值的代码
# 循环输入纵坐标
first_y += 33
while True:
first_y += 66
write_num_x_y(first_x, first_y, f"{y_setnum/1000}")
# 画标记线
t.goto(first_x ,first_y)
write_line(first_x+10, first_y)
y_setnum += 25
# 初始化标记初始位置的变量
if y_setnum > 1175:
first_y = -300
break
# 循环输入横坐标
first_x += 20
while True:
first_x += 100
x_setnum += 1
write_num_x_y(first_x, first_y, f"{x_setnum}π")
# 画标记线
t.goto(first_x-10, first_y+20)
write_line(first_x-10,first_y+30)
# 初始化标记初始位置的变量
if x_setnum > 7:
first_x = -300
break
画出曲线的代码
#画曲线
#设置写入颜色
t.color("red")
# 设置曲线画入初始位置
curve_first_x = mark_line_x
curve_first_y = mark_line_y
# 设置x轴反向初始值
in_x = 0
while True:
#获取cosx对应的值
# in_y = cos(in_x)
# #获取sinx对应的值
# in_y = sin(in_x)
#获取tanx对应的值
in_y = tan(in_x)
# 获取对应画到位置的值
if in_x % 20 == 0 and in_x != 0:
#开始画线
write_line(curve_first_x+in_x*10, curve_first_y+in_y)
t.goto(curve_first_x+in_x*10, curve_first_y + in_y)
elif in_x == 0:
t.goto(curve_first_x+in_x*10, curve_first_y + in_y)
else:
#开始画线
write_line_curve(curve_first_x+in_x*10, curve_first_y+in_y)
print(in_y)
# 画到最大值停止绘画
in_x += 1
if in_x > 80:
break
标签:goto,三角函数,python,curve,mark,write,tanx,line,first
From: https://blog.csdn.net/2301_80120329/article/details/141827876