python定义多点坐标_绘制折线_计算起始点和终点

import turtle
import math

#定义多个点坐标
x1,y1 = 100,100
x2,y2 = 100,-100
x3,y3 = -100,-100
x4,y4 = -100,100

#先绘制x轴和y轴,并赋予颜色
turtle.color("red")
turtle.write("(0,0)")
turtle.forward(300)
turtle.write(">x")
turtle.backward(600)
turtle.penup()
turtle.goto(0,-300)
turtle.pendown()
turtle.goto(0,300)
turtle.write("^y")
turtle.color("black")
#绘制折线

turtle.penup()
turtle.goto(x1,y1)
turtle.pendown()
turtle.write("("+str(x1)+","+str(y1)+")"+str('distance=')+str(math.sqrt(x4**2+y4**2)))
turtle.goto(x2,y2)
turtle.write("("+str(x2)+","+str(y2)+")")
turtle.goto(x3,y3)
turtle.write("("+str(x3)+","+str(y3)+")")
turtle.goto(x4,y4)
turtle.write("("+str(x4)+","+str(y4)+")")

#增补和x轴和y轴交点的坐标
turtle.penup()
turtle.goto(-100,0)
turtle.write("(-100,0)")
turtle.goto(0,100)
turtle.write("(0,100)")
turtle.goto(100,0)
turtle.write("(100,0)")
turtle.goto(0,-100)
turtle.write("(0,-100)")
turtle.goto(300,0)

 

结果:

posted @ 2021-04-12 13:34  CiscoLee  阅读(895)  评论(0编辑  收藏  举报