Advertisement
Guest User

Untitled

a guest
Jun 21st, 2018
150
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.79 KB | None | 0 0
  1. >>> import math
  2. >>> from Tkinter import *
  3. >>> import time
  4. >>> class Point: ##Class Point is defined so that point may be used
  5.     def __init__(self, x=0.0, y=0.0):
  6.         self.x = x
  7.         self.y = y
  8.     def calDis(self,p):
  9.         return math.sqrt((p.x-self.x)**2+(p.y-self.y)**2)
  10.  
  11.    
  12. >>> class Polyline:
  13.     def __init__(self, points = []):
  14.         self.points = points
  15.     def getLength(self):
  16.         length = 0.0
  17.         for i in range(len(self.points)-1):
  18.             length += math.sqrt((self.points[i].x-self.points[i+1].x)**2+(self.points[i].y-self.points[i+1].y)**2)
  19.             if length > 200: ##To create the red square
  20.                 root = Tk()
  21.                 can = Canvas(root, width = 600, height = 600)
  22.                 can.pack()
  23.                 can.create_rectangle(200,166,400,332, fill="red")
  24.                 can.create_text(300,249, text=" Polyline Length\n is more than 200")
  25.                 for x in range(0,400):
  26.                                         can.move(1,5,0)
  27.                                         can.move(2,5,0)
  28.                                         root.update()
  29.                                         time.sleep(0.02)
  30.                                 root.mainloop()
  31.                 return length
  32.             if length < 200: ##To create the blue square
  33.                 root = Tk()
  34.                 can = Canvas(root, width = 600, height = 600)
  35.                 can.pack()
  36.                 can.create_rectangle(200,166,400,332, fill="blue")
  37.                 can.create_text(300,249, text=" Polyline Length\n is less than 200")
  38.                 root.mainloop()
  39.                 return length
  40.  
  41.            
  42. >>> p1 = Point(789,654)
  43. >>> p2 = Point(564,574)
  44. >>> pointList = [p1,p2]
  45. >>> polyline = Polyline(pointList)
  46. >>> print polyline.getLength()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement