def change_orientation(self,new_orientation): ###rotate entire hex field so that orientation of source hex points in direction of new_orientation ### if not((new_orientation >= 0) and (new_orientation <= 360)): raise badOrientation if self.roots == []: self.find_roots() delta_orientation = (new_orientation - self.source_hex.orientation)%360 # go through all the hexagons at each level of the tree and update their locations. for temp_root_hex in self.roots: for temp_key,temp1_hex in temp_root_hex.hexagon_dictionary.items(): #make a line from the center of the hex field to our current hexagon temp_line = world.line(self.source_hex.location,temp1_hex.location) # rotate said line about the center of the hex field temp_line = temp_line.rotate_line(temp_line,delta_orientation) # make end of the line the new location for our current hexagon temp1_hex.location = temp_line.p2 # change the orientation for our current hexagon temp1_hex.orientation = (temp1_hex.orientation + delta_orientation) % 360 # update the locations for the convex hull for i in range(0,len(self.convex_hull)): #make a line from the center of the hex field to our current convex hull temp_line = world.line(self.source_hex.location,self.convex_hull[i]) # rotate said line about the center of the hex field temp_line = temp_line.rotate_line(temp_line,delta_orientation) # make end of the line the new location for our current hexagon self.convex_hull[i] = temp_line.p2 return True
def change_scale(self, new_outside_diameter): ###change scale of entire hex field so outside diameter of source hex matches new_outside_diameter ### if not (new_outside_diameter > 0): raise badOutsideDiameter if self.roots == []: self.find_roots() scale_factor = new_outside_diameter / self.source_hex.outside_diameter # go through all the hexagons at each level of the tree and update their locations. for temp_root_hex in self.roots: for temp_key, temp1_hex in temp_root_hex.hexagon_dictionary.items( ): #make a line from the center of the hex field to our current hexagon temp_line = world.line(self.source_hex.location, temp1_hex.location) # calculate new point along ray properly scaled temp1_hex.location = temp_line.along_line( temp_line, scale_factor) # change the outside diameter for our current hexagon temp1_hex.outside_diameter = temp1_hex.outside_diameter * scale_factor # update the locations for the convex hull for i in range(0, len(self.convex_hull)): #make a line from the center of the hex field to our current convex hull temp_line = world.line(self.source_hex.location, self.convex_hull[i]) # make end of the line the new location for our current hexagon self.convex_hull[i] = temp_line.along_line(temp_line, scale_factor) return True
def line_of_hexagons(self, p_start, p_end, use_convex_hull=True): ### generator for a iterator which returns hexagons which from line from p_start to p_end ### # Note: p_start must be within the hexagon field # guarantees that first hex contains p_start and last hex contains p_end or else p_end is off the field ## print('line of hexagons called with use_convex_hull = '+str(use_convex_hull)) current_hex = self.lowest_hex_containing_point(p_start, use_convex_hull) ## print('starting hex location is '+str(current_hex.location)) reference_line = world.line(current_hex.location, p_end) ## print('reference line is '+str(reference_line)) current_distance = current_hex.distance_between( current_hex.location, p_end) yield current_hex for temp_hex in current_hex.adjacent: if temp_hex.line_intersects(reference_line): current_hex = temp_hex current_distance = current_hex.distance_between( current_hex.location, p_end) break else: # none of and adjacents have the reference line crossing them, we are done return yield current_hex while current_hex.is_interior(p_end) != True and len( current_hex.adjacent) == 6: # zigzag across reference line until we get there, stopping when we get to p_end or reach the edge candidate_hexs = [] for temp_hex in current_hex.adjacent: # see which adjacent hexs are on other side of reference line temp_line = world.line(current_hex.location, temp_hex.location) if temp_hex.segments_intersect(p_start, p_end, current_hex.location, temp_hex.location): # we found an adjacent hex on the other side of the reference line candidate_hexs.append(temp_hex) if candidate_hexs == []: # we did not find any hexs on the other side of the reference line return else: old_current_hex = current_hex for temp_hex in candidate_hexs: if temp_hex.distance_between(temp_hex.location, p_end) < current_distance: current_hex = temp_hex current_distance = temp_hex.distance_between( temp_hex.location, p_end) if old_current_hex == current_hex: # none of the candidate hexs are better than before return yield current_hex # when we get this far, current_hex contains p_end return
def draw_path(self): temp_hex_path_element = self while temp_hex_path_element.predecessor != None: temp_hex_path_element.hexagon.draw() line_to_predecessor = world.line(temp_hex_path_element.hexagon.location,\ temp_hex_path_element.predecessor.hexagon.location) line_to_predecessor.draw_line() temp_hex_path_element = temp_hex_path_element.predecessor temp_hex_path_element.hexagon.draw() #draw the origin hexagon
def draw_ripple(self, ripple_level): if ripple_level >= len( self.ripple_sextant_lists[0]) or ripple_level < 0 or type( ripple_level) != type(1): print('ripple level is', ripple_level) print('type of ripple_level is', type(ripple_level)) raise nonexistantRippleLevel for current_sextant in range(0, len(self.ripple_sextant_lists)): for temp_hex_path_element in self.ripple_sextant_lists[ current_sextant][ripple_level]: temp_hex_path_element.hexagon.draw() if temp_hex_path_element.predecessor != None: line_to_predecessor = world.line(temp_hex_path_element.hexagon.location,\ temp_hex_path_element.predecessor.hexagon.location) line_to_predecessor.draw_line()