zoukankan      html  css  js  c++  java
  • 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)

    结果:

  • 相关阅读:
    《Linux就该这么学》第十二课
    《Linux就该这么学》第十一课
    《Linux就该这么学》第十课
    《Linux就该这么学》第九课
    《Linux就该这么学》第八课
    模板层
    路由层
    git的使用
    属性选择器
    高级选择器
  • 原文地址:https://www.cnblogs.com/ciscolee/p/14647587.html
Copyright © 2011-2022 走看看