Beispiel #1
0
 def click_event(event, x, y, flags, params):
     global i
     if event == cv.EVENT_LBUTTONDOWN:
         point = (x, y)
         pts.append(point)
         draw_point(img, *point)
         draw_text(img, *point, i)
         i += 1
         print(point)
         cv.imshow('image', img)
Beispiel #2
0
    def draw(self, cr):
        px, py = self.get_position()
        sx, sy = self.size
        drawing.draw_round_rectangle(cr, px, py, sx, sy, self.radius)

        if self.inactive:
            color = (0.5, 0.5, 0.5)
        else:
            color = (0, 0, 0)

        cr.set_source_rgb(1, 1, 1)
        cr.fill()

        if self.highlight:
            drawing.draw_round_rectangle(cr, px, py, sx, sy, self.radius)
            cr.set_line_width(6.5)
            cr.set_source_rgba(*self.highlight)
            cr.stroke()

        drawing.draw_round_rectangle(cr, px, py, sx, sy, self.radius)
        cr.set_line_width(1.2)
        cr.set_source_rgb(*color)
        cr.stroke()

        if self.thicklines:
            cr.rectangle(px, py, 8, sy)
            cr.rectangle(px + sx - 8, py, 8, sy)
            cr.fill()
        elif self.doubleborder:
            if self.radius > 3:
                drawing.draw_round_rectangle(cr, px, py, sx, sy,
                                             self.radius - 3.5)
            else:
                drawing.draw_round_rectangle(cr, px + 3, py + 3, sx - 6,
                                             sy - 6, self.radius)
            cr.stroke()
        drawing.draw_centered_text(cr, px + sx / 2, py + sy / 2, self.name)
        if self.corner_text:
            if self.thicklines:
                shift_x = 10
                shift_y = 3
            elif self.doubleborder:
                shift_x = 6
                shift_y = 6
            else:
                shift_x = 3
                shift_y = 3
            cr.save()
            cr.set_font_size(8)
            drawing.draw_text(cr, px + sx - shift_x, py + shift_y,
                              self.corner_text, 1, 1)
            cr.restore()
Beispiel #3
0
def draw_tiles():
    for location in g.map.all_locations:
        draw_one_tile(g.map[location].tile, location)

        # Draw edges
        if False and settings.debug:
            for edge in range(4):
                edge_state = g.map[location].edges[edge]
                location_on_map = Vector(
                    location.x * settings.tile_size.width,
                    location.y * settings.tile_size.height
                )
                draw_text(location_on_map + settings.light_map_location + edge_offset(edge), edge_state)
Beispiel #4
0
    def draw(self, cr):
        px, py = self.get_position()
        sx, sy = self.size
        drawing.draw_round_rectangle(cr, px, py, sx, sy, self.radius)

        if self.inactive:
            color = (0.5, 0.5, 0.5)
        else:
            color = (0, 0, 0)

        cr.set_source_rgb(1, 1, 1)
        cr.fill()

        if self.highlight:
            drawing.draw_round_rectangle(cr, px, py, sx, sy, self.radius)
            cr.set_line_width(6.5)
            cr.set_source_rgba(*self.highlight)
            cr.stroke()

        drawing.draw_round_rectangle(cr, px, py, sx, sy, self.radius)
        cr.set_line_width(1.2)
        cr.set_source_rgb(*color)
        cr.stroke()

        if self.thicklines:
            cr.rectangle(px, py, 8, sy)
            cr.rectangle(px + sx - 8, py, 8, sy)
            cr.fill()
        elif self.doubleborder:
            if self.radius > 3:
                drawing.draw_round_rectangle(cr, px, py, sx, sy, self.radius - 3.5)
            else:
                drawing.draw_round_rectangle(cr, px + 3, py + 3, sx - 6, sy - 6, self.radius)
            cr.stroke()
        drawing.draw_centered_text(cr, px + sx / 2, py + sy / 2, self.name)
        if self.corner_text:
            if self.thicklines:
                shift_x = 10
                shift_y = 3
            elif self.doubleborder:
                shift_x = 6
                shift_y = 6
            else:
                shift_x = 3
                shift_y = 3
            cr.save()
            cr.set_font_size(8)
            drawing.draw_text(cr, px + sx - shift_x, py + shift_y, self.corner_text, 1, 1)
            cr.restore()
Beispiel #5
0
def draw_facial_landmarks(img, with_text=False):
    img = img.copy()
    shape = detect_facial_landmarks(img)
    i = 0
    for (x, y) in shape:
        draw_point(img, x, y)
        if with_text:
            draw_text(img, x, y, i)
        i += 1
    return img


# img = cv.imread("w1.jpg")
# img = draw_facial_landmarks(img, with_text=True)
# cv.imwrite("detect1.jpg", img)
Beispiel #6
0
    def draw(self, cr):
        if self.text:
            px, py = self.get_position()

            if self.inactive:
                cr.set_source_rgb(0.5, 0.5, 0.5)
            else:
                cr.set_source_rgb(*self.color)

            if self.highlight:
                background_color = self.highlight
            else:
                background_color = self.background_color

            if self.format:
                text = self.format.format(self.text)
            else:
                text = self.text

            self.size = drawing.draw_text(cr,
                                          px,
                                          py,
                                          text,
                                          self.align_x,
                                          self.align_y,
                                          padding_left=self.padding_left,
                                          padding_right=self.padding_right,
                                          padding_top=self.padding_top,
                                          padding_bottom=self.padding_bottom,
                                          radius=self.radius,
                                          background_color=background_color,
                                          border_color=self.border_color)
        else:
            self.size = (0, 0)
Beispiel #7
0
    def draw(self, cr):
        if self.text:
            px, py = self.get_position()

            if self.inactive:
               cr.set_source_rgb(0.5,0.5,0.5)
            else:
               cr.set_source_rgb(*self.color)

            if self.highlight:
                background_color = self.highlight
            else:
                background_color = self.background_color

            if self.format:
                text = self.format.format(self.text)
            else:
                text = self.text

            self.size = drawing.draw_text(
                   cr, px, py, text, self.align_x, self.align_y,
                   padding_left=self.padding_left,
                   padding_right=self.padding_right,
                   padding_top=self.padding_top,
                   padding_bottom=self.padding_bottom,
                   radius=self.radius,
                   background_color=background_color,
                   border_color=self.border_color)
        else:
            self.size = (0, 0)
Beispiel #8
0
def draw_one_player(player, row, score):
    location = Vector(
        settings.player_details_location.x,
        settings.player_details_location.y + row * settings.player_details_height
    )

    name = '>> {}'.format(player.name) if row == g.current_player_number else player.name
    draw_text(location, name)

    live_workers = len(player.unplaced_workers(alive=True))
    ghost_workers = len(player.unplaced_workers(alive=False))

    worker_location = location + settings.player_workers_offset
    for i in range(live_workers):
        g.images.images['light_{}'.format(player.colour)].draw(location=worker_location)
        worker_location.x += settings.worker_size.x

    for i in range(ghost_workers):
        g.images.images['dark_{}'.format(player.colour)].draw(location=worker_location)
        worker_location.x += settings.worker_size.x

    draw_text(worker_location, str(score))
Beispiel #9
0
    def draw(self, cr):
        if self.text:
            px, py = self.get_position()

            if self.inactive:
               cr.set_source_rgb(0.5,0.5,0.5)
            else:
               cr.set_source_rgb(*self.color)

            if self.highlight:
                background_color = self.highlight
            else:
                background_color = self.background_color

            self.size = drawing.draw_text(
                   cr, px, py, self.text, self.align_x, self.align_y,
                   padding_x=self.padding_x,
                   padding_y=self.padding_y,
                   radius=self.radius,
                   background_color=background_color,
                   border_color=self.border_color)
        else:
            self.size = (0, 0)
Beispiel #10
0
def draw_hive_plot(file_name,
                data,
                hive_plot_settings,
                genotype_ordering):

    """ Writes a .svg file containing the plot using the settings passed in as parameters

    file_name is the name of the resulting .svg
    data is a pandas.DataFrame object containing the splicing expression data
    dimension is the dimension of the resulting .svg file
    axis_angles is a list containing the angles of the axes of the plot in degrees
    axis_thickness is a number describing the thickness of the axes of the plot
    axis_color is a 3-element list containing the RGB values for the color of the axes
    axis_start_radius is the radius of the beginning of the axes, measured from the center of the plot
    axis_end_radius is the radius of the end of the axes, measured from the center of the plot
    axis_step is the step size of the axis. This controls the spacing of the tick marks on the axis
    custom_scale is a list containing lists of the lower and upper bounds for each axis
    axis_label_size is a number describing the size of the axis labels
    axis_label_radius is a list containing the radii of each of the axis labels, measured from the center of the plot
    use_ticks is a boolean which determines whether tick marks are drawn on the axes
    tick_length is a number describing the length of the tick marks. Used only if use_ticks is true
    tick_label_from_axis is a number determining the distance of the tick labels from the axis
    tick_label_size is a number determining the font size of the tick label. It is set to 0 if no tick label is drawn
    bezier_colors is a list containing lists which hold the RGB values of each of the bezier curves
    bezier_thickness is a number determining the thickness of the bezier curves
    include_key is a boolean determining whether the key is drawn
    key_title_size is a number determining the font size of the key title
    key_text_color is a 3-element list containing the RGB values for the color of the key text
    key_position is a 2-element list describing the cartesian coordinates of the key. (0,0) is the center of the plot
    key_font_size is a number determining the font size of the labels in the key
    """

    # parse hive_plot_settings
    dimension=hive_plot_settings['dimension']
    axis_angles=hive_plot_settings['axis_angles']
    axis_thickness=hive_plot_settings['axis_thickness']
    axis_color=hive_plot_settings['axis_colors']
    axis_start_radius=hive_plot_settings['axis_start_radius']
    axis_end_radius=hive_plot_settings['axis_end_radius']
    axis_step=hive_plot_settings['axis_subdivision']
    custom_scale = hive_plot_settings['custom_scale']
    axis_label_size=hive_plot_settings['axis_label_size']
    axis_label_radius=hive_plot_settings['axis_label_radius']
    use_ticks=hive_plot_settings['tick_marks']
    tick_length=hive_plot_settings['tick_height']
    tick_label_from_axis=hive_plot_settings['tick_label_distance']
    tick_label_size=hive_plot_settings['tick_label_font_size']
    bezier_colors=hive_plot_settings['bezier_colors']
    bezier_thickness=hive_plot_settings['bezier_thickness']
    include_key=hive_plot_settings['include_key']
    key_title_size=hive_plot_settings['key_title_size']
    key_text_color=hive_plot_settings['key_text_color']
    key_position=hive_plot_settings['key_position']
    key_font_size=hive_plot_settings['key_font_size']


    f1 = open(file_name,'w+')

    # set up svg
    f1.write('<?xml version="1.0"?>\n')
    f1.write('<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">\n')

    f1.write('<svg width="{0}in" height="{0}in" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" viewBox="0 0 {0} {0}">\n'.format(int(dimension)))

    f1.write('<g transform="translate({0},{0}) scale(1, -1)">\n'.format((dimension / 2)))

    # get dimensions of data frame
    data_shape = data.shape

    #######################
    # create axis objects #
    #######################
    number_of_axes = data.shape[1]-1
    axis_angles = axis_angles[0:number_of_axes]

    # determine minimum and maximum for each axis
    axis_minima = list(data.min(0)[1:])
    axis_maxima = list(data.max(0)[1:])

    all_axes = [None] * number_of_axes

    for i in range(number_of_axes):
        if custom_scale:
            all_axes[i] = Axis(axis_start_radius, axis_end_radius, axis_angles[i], custom_scale[i][0],custom_scale[i][1],axis_step)
        else:
            all_axes[i] = Axis.auto_boundary_axis(axis_start_radius,axis_end_radius,axis_angles[i],axis_minima[i],axis_maxima[i],axis_step)

    # assign colors to genotypes
    unique_genotypes = genotype_ordering
    color_assignment = {}
    for i in range(0,len(unique_genotypes)):
        color_assignment[unique_genotypes[i]] = bezier_colors[i]
        
    # draw in the bezier curves
    for individual_name in data.index:
        individual = data.loc[individual_name]

        indiv_genotype = individual[0]
        indiv_expression = individual[1:]

        for i in range(0,len(indiv_expression)-1):
            start_axis = all_axes[i]
            end_axis = all_axes[i+1]

            bezier_origin_x, bezier_origin_y = polar_to_cartesian(start_axis.radius_map(indiv_expression[i]),start_axis.angle)
            bezier_dest_x, bezier_dest_y = polar_to_cartesian(end_axis.radius_map(indiv_expression[i+1]),end_axis.angle)

            start_to_end_x, start_to_end_y = bezier_dest_x - bezier_origin_x, bezier_dest_y - bezier_origin_y

            mid_x, mid_y = 0.5 * (bezier_origin_x + bezier_dest_x), 0.5 * (bezier_origin_y + bezier_dest_y)
            control_x, control_y = 0.6 * start_to_end_y + mid_x, -0.6 * start_to_end_x + mid_y

            drawing.draw_bezier(f1,bezier_origin_x,bezier_origin_y,bezier_dest_x,bezier_dest_y,control_x,control_y,color=color_assignment[indiv_genotype],thickness=bezier_thickness)

    # draw axes and tick marks
    for axis in all_axes:
        start_x, start_y = polar_to_cartesian(axis.start_radius,axis.angle)
        end_x, end_y = polar_to_cartesian(axis.end_radius,axis.angle)

        drawing.draw_line_polar(f1,start_x,start_y,axis.end_radius-axis.start_radius,axis.angle,thickness=axis_thickness,color=axis_color)

        if use_ticks:
            i = axis.minimum
            while i <= axis.maximum:
                radius = axis.radius_map(i)
                tick_start_x, tick_start_y = polar_to_cartesian(radius,axis.angle)
                drawing.draw_line_polar(f1,tick_start_x,tick_start_y,tick_length / 2,axis.angle+90,thickness=0.3*axis_thickness,color=axis_color)
                drawing.draw_line_polar(f1,tick_start_x,tick_start_y,tick_length / 2,axis.angle-90,thickness=0.3*axis_thickness,color=axis_color)

                if tick_label_size:
                    normal_vector_x, normal_vector_y = polar_to_cartesian(tick_label_from_axis,axis.angle+90)
                    label_x, label_y = tick_start_x + normal_vector_x, normal_vector_y + tick_start_y

                    # draw right side up
                    if (axis.angle % 360 <= 90) or (axis.angle % 360 >= 270):
                        drawing.draw_text(f1,i,label_x,label_y,tick_label_size,angle=-axis.angle,color=axis_color)

                    # draw upside down
                    else:
                        drawing.draw_text(f1,i,label_x,label_y,tick_label_size,angle=-axis.angle - 180,color=axis_color)

                i += axis.step

    # draw axis labels
    for i in range(len(data.columns[1:])):
        x, y = polar_to_cartesian(axis_label_radius[i], axis_angles[i])
        drawing.draw_multiline_text(f1,data.columns[i+1].replace(':','\n'),x,y,axis_label_size,axis_color)

    # draw key
    if include_key:
        drawing.draw_text_left(f1,data.columns[0],key_position[0],key_position[1],key_title_size,color=key_text_color)

        new_reference_y = key_position[1] - key_title_size - key_font_size / 2
        spacing = key_font_size * 2

        for i in range(len(unique_genotypes)):
            genotype = unique_genotypes[i]
            color = color_assignment[genotype]

            drawing.draw_rectangle(f1,key_position[0],new_reference_y - i * spacing,key_font_size,key_font_size,color)
            drawing.draw_text_left(f1,genotype,key_position[0]+spacing,new_reference_y - i * spacing,key_font_size,color=key_text_color)
                
    # close svg
    f1.write('</g>\n')
    f1.write('</svg>\n')
    f1.close()    
Beispiel #11
0
def draw_population_structure_graph(output_file_name,
                                    data,
                                    genotypes_ordering,
                                    struct_plot_settings):
    """ Draws a structure plot from the splicing data, broken up by genotype

    output_file_name is the file path where the plot will be written
    data is a pandas.DataFrame object representing the splicing data
    width is the width of the plot
    height is the height of the plot
    left_margin is the amount of white space on the left side of the plot
    right_margin is the amount of white space on the right side of the plot
    bottom_margin is the amount of white space below the plot
    top_margin is the amount of white space above the plot
    colors is a list of RGB objects which determine the colors of the bars in the structure plot
    axis_color is an RGB object representing the color of the axes, labels, and tick marks
    axis_thickness is the thickness of the axes and ticks
    tick_length is the length of the tick marks
    horiz_label_size is the font size of the labels along the horizontal (x) axis
    horiz_label_spacing represents the distance from the horizontal axis labels are drawn below the horizontal axis
    horiz_axis_title_size is the font size of the label for the horizontal axis
    horiz_axis_title_spacing is the distance from the horizontal axis that the title is drawn below the horizontal axis
    use_vertical_ticks is a boolean determining whether or not tick marks are drawn for the vertical (y) axis
    vertical_tick_spacing represents the scale for the tick marks on the vertical axis. Must be between 0 and 1
    vert_label_size is the font size of the vertical axis tick mark labels
    vert_label_spacing represents the distance from which the vertical axis labels are drawn to the left of the vertical axis
    include_key is a boolean determining whether or not a key should be drawn
    key_position is an array representing the cartesian coordinates of the key. [0,0] refers to the bottom left corner of the plot
    key_font_size is the font size of each entry in the key
    key_text_color is an RGB object which represents the color of the text in the key
    """

    # parse settings
    width=struct_plot_settings['plot_width']
    height=struct_plot_settings['plot_height']
    left_margin=struct_plot_settings['left_margin']
    right_margin=struct_plot_settings['right_margin']
    bottom_margin=struct_plot_settings['bottom_margin']
    top_margin=struct_plot_settings['top_margin']
    colors=struct_plot_settings['colors']
    axis_color=struct_plot_settings['axis_color']
    axis_thickness =struct_plot_settings['axis_thickness']
    tick_length=struct_plot_settings['tick_length']
    horiz_label_size=struct_plot_settings['horiz_label_size']
    horiz_label_spacing=struct_plot_settings['horiz_label_spacing']
    horiz_axis_title_size=struct_plot_settings['horiz_axis_title_size']
    horiz_axis_title_spacing=struct_plot_settings['horiz_axis_title_spacing']
    use_vertical_ticks=struct_plot_settings['use_vertical_ticks']
    vertical_tick_spacing=struct_plot_settings['vertical_tick_spacing']
    vert_label_size=struct_plot_settings['vert_label_size']
    vert_label_spacing=struct_plot_settings['vert_label_spacing']
    include_key=struct_plot_settings['include_key']
    key_position=struct_plot_settings['key_position']
    key_font_size=struct_plot_settings['key_font_size']
    key_text_color=struct_plot_settings['key_text_color']


    # sort the data frame so that homozygous reference is first, heterozygous is in the middle, etc
    indiv_and_genotypes = data.iloc[:,0]
    indivs_by_genotype = {}
    for indiv_id, genotype in indiv_and_genotypes.iteritems():
        if genotype not in indivs_by_genotype:
            indivs_by_genotype[genotype] = []
        indivs_by_genotype[genotype].append(indiv_id)

    new_index_order = []
    for genotype in genotypes_ordering:
        new_index_order.extend(indivs_by_genotype[genotype])
    sorted_data = data.reindex(index=new_index_order)

    # assign colors for each junction
    color_lookup = {}
    all_junctions = list(sorted_data.columns[1:])
    for i in range(len(all_junctions)):
        color_lookup[all_junctions[i]] = colors[i]

    width_per_individual = (width - (left_margin + right_margin)) / len(sorted_data.index)

    
    # create svg file
    f1 = open(output_file_name,'w+')

    # set up svg
    f1.write('<?xml version="1.0"?>\n')
    f1.write('<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">\n')
    f1.write('<svg width="{0}in" height="{1}in" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" viewBox="0 0 {0} {1}">\n'.format(width,height))

    # flip to cartesian coordinates, (0,0) is at bottom left corner
    f1.write('<g transform="translate(0,{0}) scale(1,-1)">\n'.format(height))

    # draw the rectangles. also draw vertical separators and horizontal axis labels
    previous_width = left_margin
    current_width = left_margin
    current_genotype = sorted_data.iloc[0,0]
    for row_number in range(sorted_data.shape[0]):
        individual = sorted_data.iloc[row_number]

        # draw rectangles
        expression_total_value = 0
        for junction in all_junctions:

            junction_color = color_lookup[junction]

            current_junction_expression = individual[junction]
            start_y, rect_height = (height - top_margin - bottom_margin) * expression_total_value + bottom_margin, (height - top_margin - bottom_margin) * current_junction_expression            
            drawing.draw_rectangle(f1,current_width,start_y,width_per_individual,rect_height,junction_color)
            expression_total_value += current_junction_expression

        # draw separators and horizontal axis labels
        if individual.iloc[0] != current_genotype or row_number == sorted_data.shape[0] - 1:
            if individual.iloc[0] != current_genotype:
                drawing.draw_line(f1,current_width,bottom_margin-tick_length*0.5,current_width,height-top_margin,axis_thickness,axis_color)

            if horiz_label_size:
                drawing.draw_text(f1,current_genotype,previous_width+(current_width-previous_width)*0.5,bottom_margin-horiz_label_spacing,horiz_label_size,angle=0,color=axis_color)

            previous_width = current_width
            current_genotype = individual.iloc[0]

        current_width += width_per_individual


    # draw vertical tick marks
    if use_vertical_ticks:
        i = vertical_tick_spacing
        while i <= 1:
            y_coordinate = (height - top_margin - bottom_margin) * i + bottom_margin
            x_coordinate = left_margin - vert_label_spacing

            drawing.draw_line(f1,left_margin-tick_length*0.5,y_coordinate,left_margin+tick_length*0.5,y_coordinate,axis_thickness,axis_color)
            drawing.draw_text(f1,i,x_coordinate,y_coordinate-vert_label_size*0.25,vert_label_size,angle=0,color=axis_color)

            drawing.draw_line
            i += vertical_tick_spacing


    # draw the plot border
    left_x, right_x = left_margin, current_width
    top_y, bottom_y = height - top_margin, bottom_margin

    drawing.draw_line(f1,left_x-axis_thickness/2,top_y,right_x+axis_thickness/2,top_y,axis_thickness,axis_color)
    drawing.draw_line(f1,left_x,top_y+axis_thickness/2,left_x,bottom_y-axis_thickness/2,axis_thickness,axis_color)
    drawing.draw_line(f1,right_x,bottom_y-axis_thickness/2,right_x,top_y+axis_thickness/2,axis_thickness,axis_color)
    drawing.draw_line(f1,right_x+axis_thickness/2,bottom_y,left_x-axis_thickness/2,bottom_y,axis_thickness,axis_color)


    # draw horizontal axis title, if desired
    if horiz_axis_title_size != 0:
        drawing.draw_text(f1,data.columns[0],(left_margin+current_width)*0.5,bottom_margin-horiz_axis_title_spacing,horiz_axis_title_size,angle=0,color=axis_color)


    # draw the key if desired
    if include_key:

        spacing = key_font_size * 2

        for i in range(len(all_junctions)):
            junction_name = all_junctions[i]
            color = color_lookup[junction_name]

            drawing.draw_rectangle(f1,key_position[0],key_position[1] - i * spacing,key_font_size,key_font_size,color)
            drawing.draw_text_left(f1,data.columns[i+1],key_position[0]+spacing,key_position[1] - i * spacing,key_font_size,color=key_text_color)
    
            
    f1.write('</g>\n')
    f1.write('</svg>\n')

    f1.close()
Beispiel #12
0
def main():
    # Start pygame and create the display at a start of 700x700
    pygame.init()
    pygame.display.set_caption("RPG Storyteller")
    display = pygame.display.set_mode((1200, 700), 0, 32)
    # Create map
    tile_map = tile.generate_tilemap(constants.WORLDSIZE)
    # Generate the first tilemap
    WorldGen.generate_terrain(tile_map)
    # Variables
    label_list = drawing.yes_labels()
    # --------------------------------------------
    # -------------- MAP -------------------------
    # --------------------------------------------
    loop_var = True
    while loop_var:
        # Draw map, and option squares
        drawing.draw_geography(tile_map, display)
        pygame.draw.rect(display, constants.GRAY, constants.SQUAREOFTRUTH)
        display.blit(label_list[0], (820, 140))
        display.blit(label_list[1], (810, 475))
        pygame.draw.line(display, constants.BLACK, (700, 350), (1200, 350))
        # Look through all events
        for event in pygame.event.get():
            # Quit
            if event.type == QUIT:
                pygame.quit()
                sys.exit()
            # User clicks either yes or no to finish making maps or move on
            if event.type == MOUSEBUTTONDOWN:
                mouse_x, mouse_y = pygame.mouse.get_pos()
                if mouse_x > 700:
                    if mouse_y > 350:
                        WorldGen.generate_terrain(tile_map)
                    else:
                        loop_var = False
        pygame.display.update()
    # Generate history and then loop until user is also satisfied with that
    backup_map = copy.deepcopy(tile_map)
    HistoryGen.start_making_history(constants.TURNS, constants.CIVS, tile_map)
    owner_list = drawing.set_influence_colors(tile_map)
    # ----------------------------------------
    # -----------------HISTORY ---------------
    # ----------------------------------------
    # Loop through until the user is happy with the map
    loop_var = True
    while loop_var:
        # Draw map, and option squares
        drawing.draw_geography(tile_map, display)
        drawing.draw_civilization(tile_map, display)
        drawing.draw_influence(tile_map, display, owner_list)
        pygame.draw.rect(display, constants.GRAY, constants.SQUAREOFTRUTH)
        display.blit(label_list[0], (820, 140))
        display.blit(label_list[1], (810, 475))
        pygame.draw.line(display, constants.BLACK, (700, 350), (1200, 350))
        # Look through all events
        for event in pygame.event.get():
            # Quit
            if event.type == QUIT:
                pygame.quit()
                sys.exit()
            # User clicks either yes or no to finish making maps or move on
            if event.type == MOUSEBUTTONDOWN:
                mouse_x, mouse_y = pygame.mouse.get_pos()
                if mouse_x > 700:
                    if mouse_y > 350:
                        tile_map = copy.deepcopy(backup_map)
                        HistoryGen.start_making_history(
                            constants.TURNS, constants.CIVS, tile_map)
                        owner_list = drawing.set_influence_colors(tile_map)
                    else:
                        loop_var = False
        pygame.display.update()
    # Clear the yes/no labels, generate a history given the tile_map and develop the owners of the colors
    label_list.clear()
    town_list = drawing.get_town_list(tile_map)
    # ----------------------------------
    # -------------MAIN LOOP -----------
    # ----------------------------------
    # Main "game" loop, where the user can inspect specific squares
    while True:
        # Draw geography, civilizations, influence, then the info box
        drawing.draw_geography(tile_map, display)
        drawing.draw_civilization(tile_map, display)
        drawing.draw_influence(tile_map, display, owner_list)
        pygame.draw.rect(display, constants.GRAY, constants.SQUAREOFTRUTH)
        # Look through all events
        for event in pygame.event.get():
            # Quit
            if event.type == QUIT:
                pygame.quit()
                sys.exit()
            # User clicks a square it gives information
            if event.type == MOUSEBUTTONDOWN:
                tile_x, tile_y = drawing.get_indices(constants.WIDTH,
                                                     constants.HEIGHT,
                                                     len(tile_map))
                if tile_y >= len(tile_map) or tile_x >= len(tile_map):
                    # Generate hook
                    label_list = drawing.draw_hooks(display, town_list)
                else:
                    label_list = drawing.tile_info(tile_map[tile_y][tile_x])
        # Draw the text when tile clicked
        drawing.draw_text(display, label_list)
        pygame.display.update()
Beispiel #13
0
    def draw(self):
        draw_rectangle(self.rect,
                       background_colour=settings.button_background_colour)

        text_location = self.location + settings.button_text_offset
        draw_text(text_location, 'Ok')