Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- >>> import math
- >>> from Tkinter import *
- >>> import time
- >>> class Point: ##Class Point is defined so that point may be used
- def __init__(self, x=0.0, y=0.0):
- self.x = x
- self.y = y
- def calDis(self,p):
- return math.sqrt((p.x-self.x)**2+(p.y-self.y)**2)
- >>> class Polyline:
- def __init__(self, points = []):
- self.points = points
- def getLength(self):
- length = 0.0
- for i in range(len(self.points)-1):
- length += math.sqrt((self.points[i].x-self.points[i+1].x)**2+(self.points[i].y-self.points[i+1].y)**2)
- if length > 200: ##To create the red square
- root = Tk()
- can = Canvas(root, width = 600, height = 600)
- can.pack()
- can.create_rectangle(200,166,400,332, fill="red")
- can.create_text(300,249, text=" Polyline Length\n is more than 200")
- for x in range(0,400):
- can.move(1,5,0)
- can.move(2,5,0)
- root.update()
- time.sleep(0.02)
- root.mainloop()
- return length
- if length < 200: ##To create the blue square
- root = Tk()
- can = Canvas(root, width = 600, height = 600)
- can.pack()
- can.create_rectangle(200,166,400,332, fill="blue")
- can.create_text(300,249, text=" Polyline Length\n is less than 200")
- root.mainloop()
- return length
- >>> p1 = Point(789,654)
- >>> p2 = Point(564,574)
- >>> pointList = [p1,p2]
- >>> polyline = Polyline(pointList)
- >>> print polyline.getLength()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement