Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- '''
- Created on Oct 26, 2011
- @author:
- '''
- from friend import Friend
- from turtle import *
- class Field(object):
- '''
- Contains a the dimensions of a plane and a list of friends inside the plane.
- Properties are read, calculated and drawn in separate steps.
- '''
- def __init__(self):
- '''
- Initialize all attributes
- '''
- # Nothing but imports are written above this line!
- def read_friends(self, file_name):
- '''
- Read the properties and friends list.
- '''
- '''
- # reading each line and putting each line as a string in a list
- myfilehandle1 = open(file_name, 'r')
- fnl = myfilehandle1.readlines()
- self.new_fnl = []
- for i in fnl:
- self.new_fnl.append(i[:-1])
- print(self.new_fnl)
- '''
- # extracting the field parameter values from file_name
- myfilehandle2 = open(file_name, 'r')
- field_values_s = myfilehandle2.readline()
- self.field_values = field_values_s.split()
- print(self.field_values)
- self.side_x = self.field_values[0]
- self.side_y = self.field_values[1]
- self.friends_in_circle = self.field_values[2]
- # extracting the friend values from file_name
- myfilehandle3 = open(file_name, 'r')
- friend_values_s = myfilehandle3.readlines()
- self.friend_values = []
- for i in friend_values_s:
- self.friend_values.append(i[:-1])
- for i in range(len(self.friend_values)):
- self.friend_values[i] = self.friend_values[i].split()
- del self.friend_values[0]
- print(self.friend_values)
- def calculate_friend_distances(self):
- '''
- Calculate the distances between all the friends.
- '''
- self.distance_friends = []
- self.distances_friends = []
- for i in range(len(self.friend_values)):
- for j in range(len(self.friend_values)):
- x1 = int(self.friend_values[i][1])
- x2 = int(self.friend_values[j][1])
- y1 = int(self.friend_values[i][2])
- y2 = int(self.friend_values[j][2])
- self.distance_friends += [(((x1-x2)**2)+((y1-y2)**2))**0.5]
- self.distances_friends.append(self.distance_friends)
- print(self.distances_friends)
- def calculate_friend_circles(self):
- '''
- Calculate the radius for each friend so that each circle contains
- the required amount of friends. The circle intersect the last friend.
- '''
- return
- def calculate_closest_friend(self):
- '''
- Determine the friend closest to all others. The total distance traveled
- by all friends is the smallest.
- '''
- return
- def init_draw(self):
- '''
- Initialize the screen and turtle.
- '''
- self.turtle = Turtle()
- self.wn = Screen()
- self.wn.title("Friends 'n stuff")
- def draw_box(self):
- '''
- Draw a box using the requests x and y sizes.
- '''
- self.turtle.goto(0, 0)
- self.turtle.penup()
- self.turtle.forward(int(self.side_x) / 2)
- self.turtle.pendown()
- self.turtle.left(90)
- self.turtle.forward(int(self.side_y) / 2)
- self.turtle.left(90)
- self.turtle.forward(int(self.side_x))
- self.turtle.left(90)
- self.turtle.forward(int(self.side_y))
- self.turtle.left(90)
- self.turtle.forward(int(self.side_x))
- self.turtle.left(90)
- self.turtle.forward(int(self.side_y) / 2)
- def draw_friends(self):
- '''
- Draw a dot on the location of each friend.
- '''
- '''
- for i in range(len(self.friend_values)):
- self.x = self.friend_values[i][1]
- self.y = self.friend_values[i][2]
- self.turtle.goto(self.x, self.y)
- self.turtle.dot(5, self.friend_values[i][3])
- '''
- def draw_friend_circles(self):
- '''
- Draw a circle around each friends location using the
- calculated radius.
- '''
- return
- def draw_closest_friend(self):
- '''
- Draw a black dot on the location of the closest friend.
- '''
- return
- def mainloop(self):
- '''
- Keep the screen visible.
- '''
- self.wn.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement