示例#1
0
    def create_vertex(self, hex_vert, label="", radius=7, width=1, ffont=None, **kwargs):
        r = radius
        p = layout.hex_to_pixel(self.hex_layout, hex_vert)
        result = []
        result.append(self.create_circle(p.x, p.y, r, width=width, **kwargs))

        if not ffont:
            result.append(self.create_text(p, text=label, justify=CENTER))
        else:
            result.append(self.create_text(p, text=label, justify=CENTER, font=ffont))
        return result
示例#2
0
    def setCell(self, cell, *args, **kwargs ):
        """ Create a content in the cell of coordinates x and y. Could specify options throught keywords : color, fill, color1, color2, color3, color4; color5, color6"""

        #compute pixel coordinate of the center of the cell:
        if False:
            size = self.hexaSize
            dx = (size**2 - (size/2)**2)**0.5

            pix_x = dx + 2*dx*cell[0]
            if yCell%2 ==1 :
                pix_x += dx

            pix_y = size + 1.5*size*cell[1]
            pix_center = (pix_x, pix_y)
        else:
            if not hasattr(cell, 'y'):
                cell = layout.ScreenPoint(cell[0], cell[1])
            if no_layout_code:
                pix_center = layout.hex_to_pixel(self.hex_layout, cell)
            else:
                pix_center = cell
        self.create_hexagone(pix_center, *args, **kwargs)
示例#3
0
    def create_hexagone(self, center, label="", color = "black", fill="yellow", color1=None, color2=None, color3=None, color4=None, color5=None, color6=None):
        """ 
        Compute coordinates of 6 points relative to a center position.
        Point are numbered following this schema :

        Points in euclidiean grid:  
                    6

                5       1
                    .
                4       2

                    3

        Each color is applied to the side that link the vertex with same number to its following.
        Ex : color 1 is applied on side (vertex1, vertex2)

        Take care that tkinter ordinate axes is inverted to the standard euclidian ones.
        Point on the screen will be horizontally mirrored.
        Displayed points:

                    3
              color3/      \color2      
                4       2
            color4|     |color1
                5       1
              color6\      /color6
                    6

        """

        pix_center = center if no_layout_code else layout.hex_to_pixel(self.hex_layout, center)

        #if no_layout_code:
        #    center = (x,y)
        #else:
        #    center = layout.ScreenPoint(x,y)

        if no_layout_code:
            size = self.hexaSize
            dx = (size**2 - (size/2)**2)**0.5
            x = center[0]
            y = center[1]

            if no_vectorize:
                point1 = (x+dx, y+size/2)
                point2 = (x+dx, y-size/2)
                point3 = (x   , y-size  )
                point4 = (x-dx, y-size/2)
                point5 = (x-dx, y+size/2)
                point6 = (x   , y+size  )
            else:
                points = [(x+dx, y+size/2),
                          (x+dx, y-size/2),
                          (x   , y-size  ),
                          (x-dx, y-size/2),
                          (x-dx, y+size/2),
                          (x   , y+size  )]
        else:
            points = layout.polygon_corners(self.hex_layout, center)

        if no_vectorize:
            #this setting allow to specify a different color for each side.
            if color1 == None:
              color1 = color
            if color2 == None:
              color2 = color
            if color3 == None:
              color3 = color
            if color4 == None:
              color4 = color
            if color5 == None:
              color5 = color
            if color6 == None:
              color6 = color
        else:
            colors = [color1, color2, color3, color4, color5, color6]
            for i in range(len(colors)):
                if colors[i] == None:
                    colors[i] = color

        if no_vectorize:
            self.create_line(point1, point2, fill=color1, width=2)
            self.create_line(point2, point3, fill=color2, width=2)
            self.create_line(point3, point4, fill=color3, width=2)
            self.create_line(point4, point5, fill=color4, width=2)
            self.create_line(point5, point6, fill=color5, width=2)
            self.create_line(point6, point1, fill=color6, width=2)
        else:
            for i in range(len(points)):
                self.create_line(points[i], points[(i+1)%6], fill=colors[i], width=2)
                #self.create_text(layout.pix_avg(points[i], points[(i+1)%6]), text="{0}".format(i))

        if fill != None:
            if no_vectorize:
                result = self.create_polygon(point1, point2, point3, point4, point5, point6, fill=fill)
            else:
              if no_layout_code:
                result = self.create_polygon(points, fill=fill)
                #self.create_polygon(points[0], points[1], points[2], points[3], points[4], points[5], fill=fill)
              else:
                result = self.create_polygon([(i.x,i.y) for i in points], fill=fill)

        self.create_text(pix_center, text=label)
        return result