示例#1
0
    def append(self, data):
        """
        Append data to the copper
        :param dict data:
        :return:
        """
        self._identify_type(data)
        if self.type == 'LINE':
            self.geometry = shape.Polygon()
            self._append_polygon_data(data)
        else:
            if not self.geometry:
                self.geometry = shape.Polygon()

            self._append_polygon_data(data)
示例#2
0
def setupScene(width, height):
    # Some shapes
    triangle_vertices = [[width / 5, height / 5], [2 * width / 5, height / 5],
                         [3 * width / 10, 4 * height / 10]]
    global my_triangle
    my_triangle = shape.Polygon(triangle_vertices, color=colors.RED)

    center = [width / 2, 2 * height / 3]
    global my_circle
    my_circle = shape.Circle(center, color=colors.GREEN, radius=height / 5)

    square_vertices = [[3 * width / 5, height / 5],
                       [3 * width / 5 + width / 5, height / 5],
                       [3 * width / 5 + width / 5, height / 5 + width / 5],
                       [3 * width / 5, height / 5 + width / 5]]
    global my_square
    my_square = shape.Polygon(square_vertices, color=colors.BLUE)

    # Animate them!
    animation.Morph(1, 3, my_triangle, my_circle)
    animation.Morph(3, 4.5, my_circle, my_square)
示例#3
0
def setupScene(width, height):
    # Some shapes
    triangle_vertices = [[width / 5, height / 5], [2 * width / 5, height / 5],
                         [3 * width / 10, 4 * height / 10]]
    global my_triangle
    my_triangle = shape.Polygon(triangle_vertices, color=colors.WHITE)

    center = [width / 2, 2 * height / 3]
    global my_circle
    my_circle = shape.Circle(center, color=colors.WHITE, radius=height / 6)

    square_vertices = [[4 * width / 6, height / 6],
                       [4 * width / 6 + width / 7, height / 6],
                       [4 * width / 6 + width / 7, height / 6 + width / 7],
                       [4 * width / 6, height / 6 + width / 7]]
    global my_square
    my_square = shape.Polygon(square_vertices, color=colors.WHITE)

    # Animate them!
    animation.Morph(1, 3, my_triangle, my_circle)
    animation.Morph(1.5, 3.5, my_square, my_circle)
def setupScene(width, height):
    # Some shapes
    triangle_vertices = [[width / 3, height / 3], [2 * width / 3, height / 3],
                         [width / 2, 2 * height / 3]]
    global my_triangle
    my_triangle = shape.Polygon(triangle_vertices)
    my_triangle.translate(np.asarray([0, 100]))

    center = [width / 2, 5 * height / 7]
    global my_circle
    my_circle = shape.Circle(my_triangle.center, radius=height / 5 - 10)

    square_vertices = [[4 * width / 7, height / 5],
                       [4 * width / 7 + width / 6, height / 5],
                       [4 * width / 7 + width / 6, height / 5 + width / 6],
                       [4 * width / 7, height / 5 + width / 6]]
    global my_square
    my_square = shape.Polygon(square_vertices)
    my_square.translate(my_triangle.center - my_square.center)
    my_square.scale(1.3)

    # Animate them!
    animation.Morph(1, 3, my_square, my_circle)
    animation.Morph(3.1, 4.5, my_circle, my_triangle)
    def load_image(self):
        # load image
        imagepath = self.imageList[self.cur - 1]
        img = Image.open(imagepath)
        width, height = img.size
        img = img.resize((int(width / 2), int(height / 2)), Image.ANTIALIAS)
        self.tkimg = ImageTk.PhotoImage(img)
        self.mainPanel.config(width=max(self.tkimg.width(), 100), height=max(self.tkimg.height(), 100))
        self.mainPanel.create_image(0, 0, image=self.tkimg, anchor=tk.NW)
        self.progLabel.config(text="{0}/{1}".format(os.path.basename(self.imageList[self.cur - 1]),
                                                    os.path.basename(self.imageList[self.total - 1])))


        # reset mouse state
        self.shapeId = None
        self.shape = None
        self.selected_shape_idx = -1
        self.dragging = False

        # load labels
        self.clear_shape()
        self.image_name = os.path.split(imagepath)[-1].split('.')[0]
        label_name = self.image_name + '.txt'
        print("label directory:" + self.outDir)
        self.label_filename = os.path.join(self.outDir, label_name)
        print("label save path:" + self.label_filename)
        if os.path.exists(self.label_filename):
            with open(self.label_filename) as f:
                for (i, line) in enumerate(f):
                    if i == 0:
                        continue
                    split = line.split(' ')
                    parsable = " ".join(split[1:])
                    shape_type = split[0]
                    if shape_type == 'POLY':
                        tmp = shape.Polygon(parse=parsable)
                    elif shape_type == 'CIRC':
                        tmp = shape.Circle(parse=parsable)
                    else:
                        raise RuntimeError("unknown shape: " + shape_type)

                    self.shapeList.append(tmp)

                    tmp_id = self.draw_shape(tmp, idx=i-1)
                    self.shapeIdList.append(tmp_id)
                    self.listbox.insert(tk.END, str(i - 1) + ': ' + tmp.to_string())
    def mouse_click(self, event):

        if self.shape:
            self.shape.handle_click([event.x, event.y])
            if self.shape.defined:
                self.del_shape_id(self.shapeId)
                self.listbox.insert(tk.END, str(len(self.shapeList)) + ': ' + self.shape.to_string())
                self.shapeIdList.append(self.draw_shape(self.shape, idx=len(self.shapeList)))
                self.shapeList.append(self.shape)
                self.shapeId = None
                self.shape = None
                self.save_image()
        else:
            closest_idx = -1
            closest_dist = m.inf
            for i, shp in enumerate(self.shapeList):
                dist = shape.Shape.dist(shp.location[0], shp.location[1], event.x, event.y)
                if dist < closest_dist:
                    closest_idx = i
                    closest_dist = dist
            if closest_dist <= SELECT_RADIUS and closest_idx != self.selected_shape_idx:
                self.dragging = True
                if self.selected_shape_idx != -1:
                    self.listbox.selection_clear(0, tk.END)
                    self.del_shape_id(self.shapeIdList[self.selected_shape_idx])
                    self.shapeIdList[self.selected_shape_idx] = self.draw_shape(self.shapeList[self.selected_shape_idx], idx=self.selected_shape_idx)
                self.selected_shape_idx = closest_idx
                self.listbox.selection_set(self.selected_shape_idx)
                self.del_shape_id(self.shapeIdList[self.selected_shape_idx])
                self.shapeIdList[self.selected_shape_idx] = self.draw_shape(self.shapeList[self.selected_shape_idx], idx=self.selected_shape_idx, selected=True, color='red')
            elif closest_dist <= SELECT_RADIUS and closest_idx == self.selected_shape_idx:
                self.listbox.selection_clear(0, tk.END)
                self.del_shape_id(self.shapeIdList[self.selected_shape_idx])
                self.shapeIdList[self.selected_shape_idx] = self.draw_shape(self.shapeList[self.selected_shape_idx], idx=self.selected_shape_idx)
                self.selected_shape_idx = -1
            else:
                if self.shape_type.get() != 'Select Shape Type':
                    new_shape_opts = {'Polygon': shape.Polygon(),
                                      'Circle': shape.Circle()}
                    self.shape = new_shape_opts[self.shape_type.get()]
                    self.shape.handle_click([event.x, event.y])
示例#7
0
 def render(self):
     width, height = self.size
     cytoband_info = self.cytoband_info['cytoband']
     chrom2endposition = self.cytoband_info['chrom2endposition']
     for chrom, position, start, end, color in cytoband_info:
         if chrom != self.chrom: continue
         if color == 'acen':
             if 'p' in position:
                 points = [(start, 0), (start, height),
                           (end, 2.0 * height / 3), (end, 1.0 * height / 3)]
             if 'q' in position:
                 points = [(start, 1.0 * height / 3),
                           (start, 2.0 * height / 3), (end, height),
                           (end, 0)]
             stroke_pattern = [0, 1, 0, 1]
             cytoband = shape.Polygon(
                 points,
                 stroke_width=0.2,
                 stroke_pattern=stroke_pattern,
                 opacity=self.opacity,
                 fill=self.cytoband_color_scheme[color],
             ).render()
         else:
             insert = start, 0
             size = end - start, height
             front, end = chrom2endposition[chrom]
             if position == front: stroke_lines = ['up', 'bottom', 'left']
             elif position == end: stroke_lines = ['up', 'bottom', 'right']
             else: stroke_lines = ['up', 'bottom']
             cytoband = svgobject.Rect(
                 insert,
                 size,
                 stroke_width=0.3,
                 stroke_lines=stroke_lines,
                 opacity=self.opacity,
                 fill=self.cytoband_color_scheme[color],
             ).render()
         self._svg.add(cytoband)
     return self._svg
示例#8
0
 def add_geometry(self):
     self.geometries.append(shape.Polygon())
     self.geometry = self.geometries[-1]
示例#9
0
screen.onkey(selection_is_polygon, "1")
screen.onkey(selection_is_star, "2")
screen.onkey(selection_is_cube, "3")
screen.onkey(selection_is_spiral, "4")

#program ana döngüsü
while True:
    # 
    screen.update()

    if selection=="1":  # Poligon
        shape.pen.clear()
        shape.pen.setheading(0)
        side = screen.numinput("POLİGON", "Poligon kenar sayısını giriniz: ", minval=3)
        length = screen.numinput("POLİGON", "Poligon bir kenar uzunluğunu giriniz: ", minval=10)
        shape.Polygon(side, length)
        turtle.getcanvas().focus_force()
        selection=""

    elif selection=="2":  # Yıldız
        shape.pen.clear()
        shape.pen.setheading(0)
        length = screen.numinput("YILDIZ", "Yıldızın bir kenar uzunluğunu giriniz: ", minval=10)
        shape.Star(length)
        turtle.getcanvas().focus_force()
        selection=""

    elif selection=="3":  # Küp
        shape.pen.clear()
        shape.pen.setheading(0)
        length = screen.numinput("KÜP", "Küpün bir kenar uzunluğunu giriniz: ", minval=10)
示例#10
0
 def __init__(self, data=None):
     self._normalized = False
     self._offset = None
     self.geometry = shape.Polygon()
     if data:
         self.append(data)