Exemplo n.º 1
0
 def move_points(self, *points, canvas=None):
     if len(points) != 2:
         raise Exception('Number of points is {}, not 2'.format(len(points)))
     p1 = points[0]
     p2 = points[1]
     dx, dy = Point2D.offset(p1, p2)
     self.p1 = p1
     self.p2 = p2
     if abs(dy) < abs(dx):
         self.p2.y = p1.y + copysign(dx, dy)
     elif abs(dy) > abs(dx):
         self.p2.x = p1.x + copysign(dy, dx)
     self.center = Point2D.mid_point(self.p1, self.p2)
     if canvas is not None and self.drawn is not None:
         canvas.coords(self.drawn, self.get_location()[2:])
Exemplo n.º 2
0
 def move(self, new_center: Point2D, canvas=None):
     dx, dy = Point2D.offset(self.center, new_center)
     for point in self.points:
         point.x += dx
         point.y += dy
     self.center = new_center
     if self.is_drawn() and canvas is not None:
         canvas.coords(self.drawn, self.get_location())
Exemplo n.º 3
0
 def move(self, new_center: Point2D, canvas=None):
     dx, dy = Point2D.offset(self.center, new_center)
     self.p1.x += dx
     self.p2.x += dx
     self.p1.y += dy
     self.p2.y += dy
     self.center = new_center
     if self.drawn is not None:
         canvas.coords(self.drawn, self.get_location()[2:])
Exemplo n.º 4
0
 def move_points(self, *points, canvas=None):
     if len(points) != 2:
         raise Exception('Number of points is not 2')
     p1 = points[0]
     p2 = points[1]
     self.p1 = points[0]
     self.p2 = points[1]
     self.center = Point2D.mid_point(p1, p2)
     if canvas is not None and self.drawn is not None:
         canvas.coords(self.drawn, self.get_location()[2:])
Exemplo n.º 5
0
 def move_points(self, *points, canvas=None):
     if len(points) != 2:
         raise Exception('Number of points is not 2')
     p1 = points[0]
     p2 = points[1]
     dx, dy = Point2D.offset(p1, p2)
     tan = abs(dy / dx) if dx != 0 else 0
     self.center = Point2D.mid_point(p1, p2)
     if p1.x > p2.x:
         self.p1.x = self.center.x + 10000
         self.p2.x = self.center.x - 10000
     elif p1.x < p2.x:
         self.p1.x = self.center.x - 10000
         self.p2.x = self.center.x + 10000
     if p1.y < p2.y:
         self.p2.y = self.center.y + 10000 * tan
         self.p1.y = self.center.y - 10000 * tan
     elif p1.y > p2.y:
         self.p2.y = self.center.y - 10000 * tan
         self.p1.y = self.center.y + 10000 * tan
     if canvas is not None and self.drawn is not None:
         canvas.coords(self.drawn, self.get_location()[2:])
Exemplo n.º 6
0
 def __init__(self, color: str, fill: str, width: int, *points):
     Figure.__init__(self, color, fill, width)
     self.points = list(points)
     self.center = Point2D(0, 0)
     if len(points) != 0:
         self.center = points[0]
Exemplo n.º 7
0
 def __init__(self, color: str, fill: str, width: int, p1: Point2D,
              p2: Point2D):
     super().__init__(color, fill, width)
     self.p1 = p1
     self.p2 = p2
     self.center = Point2D.mid_point(p1, p2)
Exemplo n.º 8
0
 def get_location(self):
     dx, dy = Point2D.offset(self.p1, self.p2)
     return (self.center.x, self.center.y, self.p1.x + dx // 2, self.p1.y,
             self.p2.x, self.p1.y + dy // 2, self.p1.x + dx // 2, self.p2.y,
             self.p1.x, self.p1.y + dy // 2)