Example #1
0
 def draw(self) -> None:
     top = Point(self.x + self.__width / 2, self.y - self.__height / 2)
     bottom_left = Point(self.x + self.__width / 2 - self.__width / 2,
                         self.y + self.__height / 2)
     bottom_right = Point(self.x + self.__width / 2 + self.__width / 2,
                          self.y + self.__height / 2)
     graphics.draw_polygon((top, bottom_left, bottom_right), self.color)
Example #2
0
    def draw(self) -> None:
        first_point = Point(self.x - self.__width / 2,
                            self.y + self.__height / 2)
        second_point = Point(self.x + self.__width / 2,
                             self.y + self.__height / 2)
        third_point = Point(self.x, self.y - self.__height / 2)

        objects = [first_point, second_point, third_point]
        graphics.draw_polygon(objects, self.color)
Example #3
0
def main(stdscr):
    curses.curs_set(0)

    win_height, win_width = stdscr.getmaxyx()
    pix_height = win_height * 4 - win_height % 4
    pix_width = win_width * 2 - win_width % 2

    arr = []
    for i in range(pix_height):
        row = []
        for j in range(pix_width):
            row.append(0)
        arr.append(row)

    last_frame = time.time()
    while True:
        # Clear the screen
        stdscr.refresh()
        stdscr.erase()
        for i in range(pix_height):
            for j in range(pix_width):
                arr[i][j] = 0

        # Draw
        graphics.draw_circle(arr, [pix_width / 6, pix_height / 8],
                             min(pix_width / 6, pix_height / 8))
        graphics.draw_square(arr, [pix_width / 2, pix_height / 8],
                             min(pix_width / 6, pix_height / 8))
        graphics.draw_ellipse(arr, [5 * pix_width / 6 - 1, pix_height / 4],
                              pix_width / 12, pix_height / 4)
        graphics.draw_ellipse(arr, [pix_width / 3, 3 * pix_height / 8],
                              pix_width / 3, pix_height / 8)
        graphics.draw_polygon(arr, [pix_width / 3, 5 * pix_height / 8 + 3],
                              min(pix_width / 4, pix_height / 8),
                              3,
                              angle_offset=-90)
        graphics.draw_polygon(arr, [2 * pix_width / 3, 5 * pix_height / 8 + 3],
                              min(pix_width / 4, pix_height / 8),
                              7,
                              angle_offset=13)
        graphics.draw_rectangle(arr, [pix_width / 9, pix_height - 2],
                                [2 * pix_width / 9, 3 * pix_height / 4])
        graphics.draw_rectangle(arr, [2 * pix_width / 3, 5 * pix_height / 6],
                                [pix_width - 2, 11 * pix_height / 12])
        graphics.draw_polygon(arr, [pix_width / 2, 7 * pix_height / 8],
                              min(pix_width / 6, pix_height / 8),
                              5,
                              angle_offset=-18)

        # Render
        chars = array_to_pixels(arr)

        for i in range(win_height - 1):
            for j in range(win_width - 1):
                stdscr.addstr(i, j, chars[i][j])

        # Show FPS
        now = time.time()
        stdscr.addstr(0, 0, f'FPS: {int(1/(now - last_frame))}')
        last_frame = now
Example #4
0
import graphics
import turtle

hector = turtle.Turtle()
screen = turtle.Screen()
screen.colormode(255)


#hector.pencolor(0.71, 0.76, 0.228)
hector.pencolor(255, 0, 0)
graphics.draw_square(hector, 100)

graphics.move_turtle(hector, -100, 100)

hector.pencolor(0, 255, 0)
graphics.draw_polygon(hector, 50, 8)

graphics.move_turtle(hector, 200, 200)

# a circle using the draw_polygon()
#graphics.draw_polygon(hector, 1, 360)

hector.pencolor(255, 255, 0)
graphics.draw_circle(hector, 32)






Example #5
0
    def draw(self):
        draw_polygon(self._pixels, self._cutting_off_field.points, self._cutting_off_field.color)

        # figures = {i: {'lines': make_lines_from_points(self._figures[i].points),
        #  'color': self._figures[i].color, 'hidden_color': self._figures[i].hidden_color}
        #  for i in range(len(self._figures))}

        fig_a = self._figures[0]
        fig_b = self._figures[1]

        lines_a = make_lines_from_points(fig_a.points)
        lines_b = make_lines_from_points(fig_b.points)
        lines_cutting_off = make_lines_from_points(self._cutting_off_field.points)

        points_a = []
        points_b = []

        for line_b in lines_b:
            intersection_points = []
            mu_vector = []
            for line in lines_a:
                intersection_point, mu = calc_intersection_point_of_two_lines(line, line_b)
                if intersection_point is not None:
                    intersection_points.append(intersection_point)
                    mu_vector.append(mu)
                    intersection_point.visibility = TRANSITIVE
                    # intersection_point.hidden_by |= FIGURE
                    intersection_point.with_ = FIGURE
            for line in lines_cutting_off:
                intersection_point, mu = calc_intersection_point_of_two_lines(line, line_b)
                if intersection_point is not None:
                    intersection_points.append(intersection_point)
                    mu_vector.append(mu)
                    intersection_point.visibility = TRANSITIVE
                    # intersection_point.hidden_by |= CUTTING_OUT_FIELD
                    intersection_point.with_ = CUTTING_OUT_FIELD

            pack = list(zip(intersection_points, mu_vector))
            pack.sort(key=lambda a: a[1])
            intersection_points = list(map(lambda a: a[0], pack))

            points_b.append(line_b[0])
            points_b.extend(intersection_points)
            points_b.append(line_b[1])

        for line_a in lines_a:
            intersection_points = []
            mu_vector = []
            for line in lines_cutting_off:
                intersection_point, mu = calc_intersection_point_of_two_lines(line, line_a)
                if intersection_point is not None:
                    intersection_points.append(intersection_point)
                    mu_vector.append(mu)
                    intersection_point.visibility = TRANSITIVE
                    # intersection_point.hidden_by |= CUTTING_OUT_FIELD
                    intersection_point.with_ = CUTTING_OUT_FIELD

            pack = list(zip(intersection_points, mu_vector))
            pack.sort(key=lambda a: a[1])
            intersection_points = list(map(lambda a: a[0], pack))

            points_a.append(line_a[0])
            points_a.extend(intersection_points)
            points_a.append(line_a[1])

        points_a = self._unique_points(points_a)
        points_b = self._unique_points(points_b)

        self._determine_points_visibility(fig_b, points_b)
        self._determine_points_visibility(fig_a, points_a)

        self._draw_lines_by_points_with_visibility(points_a, fig_a.color, fig_a.hidden_color)
        self._draw_lines_by_points_with_visibility(points_b, fig_b.color, fig_b.hidden_color)

        for point in points_a:
            point.visibility = None
        for point in points_b:
            point.visibility = None
Example #6
0
 def _draw_polygon_with_cutting_off(self, polygon):
     draw_polygon(self._pixels, polygon.points, polygon.color)
Example #7
0
    def draw(self) -> None:
        point_1 = Point(self.x - self.__base / 2, self.y + self.__height / 2)
        point_2 = Point(self.x + self.__base / 2, self.y + self.__height / 2)
        point_3 = Point(self.x, self.y - self.__height / 2)

        graphics.draw_polygon(iter([point_1, point_2, point_3]), self.color)