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.
- '''
- myfilehandle = open(file_name, 'r')
- # extracting the field parameter values from file_name
- field_values_s = myfilehandle.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
- friend_values_s = myfilehandle.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()
- print(self.friend_values)
- myfilehandle.close()
- def calculate_friend_distances(self):
- '''
- Calculate the distances between all the friends.
- '''
- self.distances_friends = []
- for i in range(len(self.friend_values)):
- distance_friends = []
- 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])
- distance_friends.append((((x1-x2)**2)+((y1-y2)**2))**0.5)
- self.distances_friends.append(distance_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.
- '''
- self.total_distances = []
- for i in self.distances_friends:
- total = 0
- som_temp_list = 0
- temp_list = []
- temp_list.append(i)
- for i in temp_list:
- som_temp_list += i
- print(som_temp_list)
- '''for j in temp_list:
- total += j
- self.total_distances.append(float(total))
- print(float(total))
- print(self.total_distances)'''
- 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.turtle.penup()
- x = int(self.friend_values[i][1])
- y = int(self.friend_values[i][2])
- self.turtle.goto(x, y)
- self.turtle.dot(5, str(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