Ejemplo n.º 1
0
 def get_frame_corners(self) -> []:
     return [
         self.__origin,
         Point(self.__origin.x + self.__size.width, self.__origin.y),
         Point(self.__origin.x + self.__size.width,
               self.__origin.y + self.__size.height),
         Point(self.__origin.x, self.__origin.y + self.__size.height)
     ]
Ejemplo n.º 2
0
    def __init__(self,
                 origin,
                 size,
                 master_canvas,
                 fill_color=None,
                 border_color=None):
        self.__rotation = 0
        self.__rotation_180 = False

        self.__size = size
        self.__origin = origin
        self.__center = Point(origin.x + size.width / 2,
                              origin.y + size.height / 2)
        self.__fill_color = fill_color
        self.__border_color = border_color

        self._calculate_curr_distance()
        self.__turtle = Shape.setup_turtle(master_canvas)
        self.__master_canvas = master_canvas

        # Test code
        self.using_sin = False
        self.overX = False
        self.overY = False
        self.lastNonstopPoint = self.__origin
        self.lastlastNonstopPoint = None
        self.lastlastDegree = 0
        self.lastDegree = 0

        self.delay_necessary = 0

        self.previous_quadrant = 0

        self.draw()
Ejemplo n.º 3
0
 def _calculate_curr_distance(self):
     self.__curr_distance = Point.distance(self.get_origin(),
                                           self.get_center())
     print("distance " + str(self.__curr_distance))
Ejemplo n.º 4
0
    def _calculate_origin(self, degrees):

        radius = self.__curr_distance
        shape_origin = Point(self.__origin.x - self.__center.x,
                             self.__center.y - self.__origin.y)
        acos_value = shape_origin.x / radius
        asin_value = shape_origin.y / radius

        current_quadrant = Shape.get_current_quadrant(shape_origin)
        print("Quadrant " + str(current_quadrant))

        if self.previous_quadrant == 0:
            self.previous_quadrant = current_quadrant
            if current_quadrant == 1:
                self.overY = True
                self.overX = False
            elif current_quadrant == 2:
                self.overX = False
                self.overY = False
            elif current_quadrant == 3:
                self.overX = True
                self.overY = False
            elif current_quadrant == 4:
                self.overX = True
                self.overY = True

        if self.using_sin:
            theta = math.asin(asin_value)
        else:
            theta = math.acos(acos_value)

        print("asin: " + str(asin_value))
        print("acos: " + str(acos_value))
        print("Theta: " + str(math.degrees(theta)))

        # Modify this section!
        if self.overX and self.overY:
            print("Over")
            theta_new = theta + math.radians(degrees)
            final_y = math.sin(theta_new) * radius + self.__center.y
            final_x = math.cos(theta_new) * radius + self.__center.x
        elif self.overX:
            print("Under")
            # Modify this for initial direction
            theta_new = theta + math.radians(degrees)

            final_y = math.sin(theta_new) * radius + self.__center.y
            final_x = math.cos(theta_new) * radius + self.__center.x
        elif self.overY:
            print("Over1")
            # Modify this for initial direction
            theta_new = theta - math.radians(degrees)

            final_y = -math.sin(theta_new) * radius + self.__center.y
            final_x = math.cos(theta_new) * radius + self.__center.x
        else:
            print("Under2")
            # Modify this for initial direction
            theta_new = theta - math.radians(degrees)

            final_y = -math.sin(theta_new) * radius + self.__center.y
            final_x = math.cos(theta_new) * radius + self.__center.x

        final_pt = Point(final_x, final_y)

        if self.previous_quadrant == 1:
            if current_quadrant == 2:
                self.delay_necessary += 1
                self.overY = False
                final_pt = Point(
                    self.lastlastNonstopPoint.x -
                    2 * radius * math.cos(self.lastlastDegree),
                    self.lastlastNonstopPoint.y)
                print("1-2")
            elif current_quadrant == 3:
                self.delay_necessary += 1
                self.overX = True
                self.overY = False
                final_pt = Point(
                    self.lastlastNonstopPoint.x +
                    2 * radius * math.cos(self.lastlastDegree),
                    self.lastlastNonstopPoint.y -
                    2 * radius * math.sin(self.lastlastDegree))
                print("1-3")
            elif current_quadrant == 4:
                self.delay_necessary += 1
                self.overX = True
                final_pt = Point(
                    self.lastlastNonstopPoint.x, self.lastlastNonstopPoint.y +
                    4 * radius * math.sin(self.lastlastDegree))
                print("1-4")
        elif self.previous_quadrant == 2:
            if current_quadrant == 1:
                self.delay_necessary += 1
                self.overY = True
                final_pt = Point(
                    self.lastlastNonstopPoint.x -
                    2 * radius * math.cos(self.lastlastDegree),
                    self.lastlastNonstopPoint.y)
                print("2-1")
            elif current_quadrant == 3:
                self.delay_necessary += 1
                self.overX = True
                final_pt = Point(
                    self.lastlastNonstopPoint.x, self.lastlastNonstopPoint.y +
                    2 * radius * math.sin(self.lastlastDegree))
                print("2-3")
            elif current_quadrant == 4:
                self.delay_necessary += 1
                self.overX = True
                self.overY = True
                final_pt = Point(
                    self.lastlastNonstopPoint.x -
                    2 * radius * math.cos(self.lastlastDegree),
                    self.lastlastNonstopPoint.y -
                    2 * radius * math.sin(self.lastlastDegree))
                print("2-4")
        elif self.previous_quadrant == 3:
            if current_quadrant == 1:
                self.delay_necessary += 1
                self.overY = True
                self.overX = False
                final_pt = Point(
                    self.lastlastNonstopPoint.x -
                    2 * radius * math.cos(self.lastlastDegree),
                    self.lastlastNonstopPoint.y +
                    2 * radius * math.sin(self.lastlastDegree))
                print("3-1")
            elif current_quadrant == 2:
                self.delay_necessary += 1
                self.overX = False
                self.overY = False
                final_pt = Point(
                    self.lastlastNonstopPoint.x, self.lastlastNonstopPoint.y -
                    2 * radius * math.sin(self.lastlastDegree))
                print("3-2")
            elif current_quadrant == 4:
                self.delay_necessary += 1
                self.overY = True
                final_pt = Point(
                    self.lastlastNonstopPoint.x -
                    2 * radius * math.cos(self.lastlastDegree),
                    self.lastlastNonstopPoint.y)
                print("3-4")
        elif self.previous_quadrant == 4:
            if current_quadrant == 1:
                self.delay_necessary += 1
                self.overX = False
                final_pt = Point(
                    self.lastlastNonstopPoint.x, self.lastlastNonstopPoint.y -
                    2 * radius * math.sin(self.lastlastDegree))
                print("4-1")
            elif current_quadrant == 2:
                self.delay_necessary += 1
                self.overX = False
                self.overY = False
                final_pt = Point(
                    self.lastlastNonstopPoint.x +
                    2 * radius * math.cos(self.lastlastDegree),
                    self.lastlastNonstopPoint.y +
                    2 * radius * math.sin(self.lastlastDegree))
                print("4-2")
            elif current_quadrant == 3:
                self.delay_necessary += 1
                self.overY = False
                final_pt = Point(
                    self.lastlastNonstopPoint.x -
                    2 * radius * math.cos(self.lastlastDegree),
                    self.lastlastNonstopPoint.y)
                print("4-3")

        self.lastlastNonstopPoint = self.lastNonstopPoint
        self.lastNonstopPoint = final_pt

        self.lastlastDegree = self.lastDegree
        self.lastDegree = theta_new

        # Set over 180
        if self.overX:
            self.__previous_acos = asin_value
        else:
            self.__previous_acos = acos_value

        print("X: " + str(final_x))
        print("Y: " + str(final_y))
        print("Rotation: " + str(self.__rotation))

        self.previous_quadrant = current_quadrant

        return final_pt
Ejemplo n.º 5
0
 def set_center(self, center):
     self.__origin = Point(center.x - self.__size.width / 2,
                           center.y - self.__size.height / 2)
     self.__center = center
     self.draw()
     self._calculate_curr_distance()
Ejemplo n.º 6
0
 def __set_center(self):
     self.__center = Point(self.__origin.x + self.__size.width / 2,
                           self.__origin.y + self.__size.height / 2)
     self.draw()
     self._calculate_curr_distance()
Ejemplo n.º 7
0
 def sety(self, y):
     self.__origin = Point(self.__origin.x, y)
     self.__set_center()
     self._calculate_curr_distance()
Ejemplo n.º 8
0
 def setx(self, x):
     self.__origin = Point(x, self.__origin.y)
     self.__set_center()
     self._calculate_curr_distance()
Ejemplo n.º 9
0
    def contains(self, point):
        distance = Point.distance(point, self.get_center())
        if distance <= self.__radius:
            return True

        return False