美文网首页
# c04ex08.pyw

# c04ex08.pyw

作者: 特丽斯纳普 | 来源:发表于2018-03-29 16:39 被阅读0次

c04ex08.pyw

Line segment info.

import math

from graphics import *

def main():
win = GraphWin("Line Segment Info", 400, 400)
win.setCoords(-10,-10,10,10)

msg = Text(Point(0,-9.5), "Click on endpoints of a line segment.")
msg.draw(win)

p1 = win.getMouse()
p1.draw(win)

p2 = win.getMouse()
p2.draw(win)

line = Line(p1,p2)
line.draw(win)

mark = Circle(line.getCenter(),0.15)
mark.setFill("cyan")
mark.draw(win)

dx = p2.getX() - p1.getX()
dy = p2.getY() - p1.getY()
slope = float(dy)/dx
length = math.sqrt(dx*dx + dy*dy)

msg.setText("Length: "+str(round(length,2))+"   Slope: "+ str(round(slope,2)))
win.getMouse()
win.close()

main()

相关文章

  • # c04ex08.pyw

    c04ex08.pyw Line segment info. import math from graphics ...

网友评论

      本文标题:# c04ex08.pyw

      本文链接:https://www.haomeiwen.com/subject/wjtvcftx.html