[Python] 纯文本查看 复制代码 import turtle
turtle.title('坐标轴-金浩轩')
def draw_cs():
turtle.tracer(False)
# 设置画笔
turtle.speed(0)
turtle.pensize(1)
turtle.pencolor('gray')
# 画x轴
turtle.penup()
turtle.goto(-400, 0)
turtle.pendown()
turtle.goto(400, 0)
# 画x轴的箭头
turtle.penup()
turtle.goto(395, 5)
turtle.pendown()
turtle.goto(400, 0)
turtle.goto(395, -5)
# 画x轴的点
for i in range(-400, 400, 50):
# 画点
turtle.penup()
turtle.goto(i, 10)
turtle.pendown()
turtle.goto(i, 0)
# 画字
turtle.penup()
if i == 0: # 对0的处理
turtle.goto(i - 10, -25)
turtle.write(i, align='center')
else:
turtle.goto(i, -25)
turtle.write(i, align='center')
turtle.pendown()
# 画x轴的X
turtle.penup()
turtle.goto(390, -30)
turtle.pendown()
turtle.write('x', font=("Arial", 16))
# 画y轴
turtle.penup()
turtle.goto(0, -400)
turtle.pendown()
turtle.goto(0, 400)
# 画y轴的箭头
turtle.penup()
turtle.goto(-5, 395)
turtle.pendown()
turtle.goto(0, 400)
turtle.goto(5, 395)
# 画y轴的点
for i in range(-400, 400, 50):
# 画点
turtle.penup()
turtle.goto(10, i)
turtle.pendown()
turtle.goto(0, i)
# 画字
turtle.penup()
if i == 0: # 对0的处理
pass
else:
turtle.goto(-25, i - 5)
turtle.write(i, align='center')
turtle.pendown()
# 画y轴的y
turtle.penup()
turtle.goto(-30, 380)
turtle.pendown()
turtle.write('y', font=("Arial", 16))
# 恢复初始位置
turtle.penup()
turtle.goto(0, 0)
turtle.pendown()
turtle.pensize(3)
turtle.tracer(True)
turtle.update()
draw_cs()
turtle.mainloop()
|