예제 #1
1
파일: tests.py 프로젝트: suguby/simple_draw
def main():
    points = [Point(x=230, y=450), Point(x=240, y=460), Point(x=230, y=470), Point(x=240, y=480)]
    polygon(point_list=points)
    points2 = [Point(p.x + 20, p.y + 20) for p in points]
    lines(point_list=points2, color=COLOR_DARK_ORANGE)
    line(start_point=Point(x=20, y=20), end_point=Point(x=40, y=300))
    square(left_bottom=Point(400, 300, ), side=100)
    rectangle(
        left_bottom=Point(x=200, y=200),
        right_top=Point(x=300, y=300),
        color=COLOR_DARK_GREEN
    )
    rectangle(
        left_bottom=Point(x=400, y=300),
        right_top=Point(x=300, y=400),
        color=COLOR_DARK_GREEN
    )
    sleep(2)
    clear_screen()
    vector(start=Point(x=230, y=260), angle=70, length=200, color=COLOR_PURPLE)
    for i in range(10):
        point = random_point()
        color = random_color()
        radius = random_number(20, 60)
        circle(center_position=point, radius=radius, color=color, width=0)
    sleep(2)
    clear_screen()
    for i in range(10):
        point = random_point()
        color = random_color()
        dx = random_number(30, 100)
        dy = random_number(30, 100)
        right_top = Point(x=point.x + dx, y=point.y + dy)
        ellipse(left_bottom=point, right_top=right_top, color=color)
    v3 = Vector(start_point=Point(0, 0), direction=45, length=50)
    for direction in range(0, 181, 20):
        v = Vector(start_point=Point(x=300, y=300), direction=direction, length=100)
        v.draw()
        v2 = Vector(start_point=v.end_point, direction=direction + 30, length=50)
        v2.draw(color=COLOR_GREEN)
        v2.add(v3)
        v2.draw(color=COLOR_ORANGE)
    snowflake(center=Point(), length=60, factor_b=0.2, factor_c=100)
    sleep(2)
    for k in range(2):
        y = 500
        for i in range(10):
            clear_screen()
            y -= 30
            for x in [100, 200, 300, 400, 500]:
                radius = random_number(30, 50)
                point = Point(x=x, y=y)
                snowflake(center=point, length=radius)
                mouse_point, mouse_buttons = get_mouse_state()
                print("mouse_state is {} + {}".format(mouse_point, mouse_buttons))
            if user_want_exit(sleep_time=0.1):
                break
        if user_want_exit(0):
            break
예제 #2
0
def hexa(startPoint, angle, length):
    listPoint = []
    step = 360 / 6
    angle_i = angle
    for i in range(6):
        v = sd.get_vector(startPoint, angle_i, length)
        angle_i += step
        listPoint.append(v.end_point)
        if i > 0:
            sd.line(listPoint[i - 1], listPoint[i], width=3)
    sd.line(listPoint[0], listPoint[-1], width=3)
예제 #3
0
def draw_fig(startPoint, angle, length, count):
    listPoint = []
    step = 360 / count
    angle_i = angle
    for i in range(count):
        v = sd.get_vector(startPoint, angle_i, length)
        angle_i += step
        listPoint.append(v.end_point)
        if i > 0:
            sd.line(listPoint[i - 1], listPoint[i], width=3)
    sd.line(listPoint[0], listPoint[-1], width=3)
예제 #4
0
 def draw_saddle(self):
     points_saddle = [
         sd.get_point(self.pos_saddle.x, self.pos_saddle.y + 20),
         sd.get_point(self.pos_saddle.x - 15, self.pos_saddle.y + 35),
         sd.get_point(self.pos_saddle.x + 50, self.pos_saddle.y + 35)
     ]
     sd.line(self.pos_saddle,
             points_saddle[0],
             color=sd.COLOR_BLUE,
             width=10)
     sd.polygon(point_list=points_saddle, color=sd.COLOR_BLACK, width=15)
예제 #5
0
def smile(x, y):
    face_point = sd.get_point(x, y)
    left_eye_point = sd.get_point(x - 30, y + 20)
    right_eye_point = sd.get_point(x + 30, y + 20)
    color = (255, 255, 255)
    start_point = sd.get_point(x - 20, y - 30)
    end_point = sd.get_point(x + 20, y - 30)
    sd.circle(face_point, 70, color, 2)
    sd.circle(left_eye_point, 10, color, 1)
    sd.circle(right_eye_point, 10, color, 1)
    sd.line(start_point, end_point, color, 2)
예제 #6
0
def draw_house(_x=300, _y=10):
    brick_height = 10
    brick_length = 30
    brick_seam = 3
    house_length = brick_length * 9 + brick_seam * 8
    house_height = (brick_height + brick_seam) * 18
    brick_color = (136, 69, 53)
    seam_color = (104, 108, 94)
    bottom_point = sd.get_point(_x, _y)
    top_point = sd.get_point(x=_x + house_length, y=_y + house_height)
    sd.rectangle(left_bottom=bottom_point,
                 right_top=top_point,
                 color=brick_color)
    triangle = [
        sd.Point(_x - 50, _y + house_height),
        sd.Point(_x + house_length + 50, _y + house_height),
        sd.Point(_x + house_length // 2, _y + house_length),
    ]
    sd.polygon(point_list=triangle, width=0, color=seam_color)
    for y in range(house_height // (brick_height + brick_seam)):
        if y % 2 == 0:
            start_x = _x + brick_length
        else:
            start_x = _x + brick_length // 2
        if 0 < y <= house_height // (brick_height + brick_seam):
            line_point1 = sd.get_point(x=_x,
                                       y=_y + y * (brick_height + brick_seam))
            line_point2 = sd.get_point(x=_x + house_length - 1,
                                       y=_y + y * (brick_height + brick_seam))
            sd.line(start_point=line_point1,
                    end_point=line_point2,
                    color=seam_color,
                    width=brick_seam)
        for x in range(start_x, _x + house_length, brick_length + brick_seam):
            line_point1 = sd.get_point(x=x,
                                       y=_y + y * (brick_height + brick_seam))
            line_point2 = sd.get_point(x=x,
                                       y=_y + (y + 1) *
                                       (brick_height + brick_seam))
            sd.line(start_point=line_point1,
                    end_point=line_point2,
                    color=seam_color,
                    width=brick_seam)
    bottom_point = sd.get_point(x=_x + (brick_length + brick_seam) * 3 - 2,
                                y=_y + (brick_height + brick_seam) * 6 + 2)
    top_point = sd.get_point(x=_x + (brick_length + brick_seam) * 6,
                             y=_y + (brick_height + brick_seam) * 12)
    sd.rectangle(left_bottom=bottom_point,
                 right_top=top_point,
                 color=(157, 161, 170))
    sd.rectangle(left_bottom=bottom_point,
                 right_top=top_point,
                 color=(138, 102, 66),
                 width=4)
예제 #7
0
파일: smile.py 프로젝트: tidml/python_base
def smile(x, y, size, eye):
    face_point = sd.get_point(x, y)
    left_eye_point = sd.get_point(x - (eye * 2), y + eye)
    right_eye_point = sd.get_point(x + (eye * 2), y + eye)
    color = sd.COLOR_BLACK
    start_point = sd.get_point(x - (eye * 2), y - (eye * 2))
    end_point = sd.get_point(x + (eye * 2), y - (eye * 2))
    sd.circle(face_point, size, color, 2)
    sd.circle(left_eye_point, eye, color, 1)
    sd.circle(right_eye_point, eye, color, 1)
    sd.line(start_point, end_point, color, 2)
예제 #8
0
def triangle(start_point, angle, length):
    width = 3
    current_point = start_point
    for tilt_angle in range(angle, angle + 240, 120):
        v = sd.get_vector(start_point=current_point,
                          angle=tilt_angle + angle,
                          length=length,
                          width=width)
        v.draw()
        current_point = v.end_point
    sd.line(start_point=point_0, end_point=v.end_point, width=width)
예제 #9
0
def pentagon(point_3, angle, color, length):
    v1 = sd.get_vector(start_point=point_3, angle=angle, length=length, )
    l1 = sd.line(start_point=point_3, end_point=v1.end_point, color=color, width=1)
    v2 = sd.get_vector(start_point=v1.end_point, angle=angle + 72, length=length, )
    l2 = sd.line(start_point=v1.end_point, end_point=v2.end_point, color=color, width=1)
    v3 = sd.get_vector(start_point=v2.end_point, angle=angle + 144, length=length, )
    l3 = sd.line(start_point=v2.end_point, end_point=v3.end_point, color=color, width=1)
    v4 = sd.get_vector(start_point=v3.end_point, angle=angle + 216, length=length, )
    l4 = sd.line(start_point=v3.end_point, end_point=v4.end_point, color=color, width=1)
    v5 = sd.get_vector(start_point=v4.end_point, angle=angle + 288, length=length, )
    l5 = sd.line(start_point=v4.end_point, end_point=v5.end_point, color=color, width=1)
예제 #10
0
def pentagon(point=point, angle=10, length=100, color=sd.COLOR_DARK_CYAN):
    v1 = sd.get_vector(point, angle, length)
    v2 = sd.get_vector(v1.end_point, v1.angle + 360 / 5, length)
    v3 = sd.get_vector(v2.end_point, v2.angle + 360 / 5, length)
    v4 = sd.get_vector(v3.end_point, v3.angle + 360 / 5, length)
    v5 = sd.get_vector(v4.end_point, v4.angle + 360 / 5, length)
    sd.line(point, v1.end_point, color=color)
    sd.line(v2.start_point, v2.end_point, color=color)
    sd.line(v3.start_point, v3.end_point, color=color)
    sd.line(v4.start_point, v4.end_point, color=color)
    sd.line(v5.start_point, v5.end_point, color=color)
예제 #11
0
 def draw_shapes(point, angle=0, length=200, width=3):
     end_point = point
     for _ in range(n):
         vector = sd.get_vector(start_point=point,
                                angle=angle,
                                length=length,
                                width=width)
         vector.draw()
         point = vector.end_point
         angle += 360 / n
     sd.line(point, end_point, width=width)
예제 #12
0
def draw_triangle_v1(start_point=sd.get_point(100, 100), angle=0, length=50):
    vector_start_point = start_point
    for figure_angle in range(0, 240, 120):
        rib = sd.get_vector(start_point=vector_start_point,
                            angle=angle + figure_angle,
                            length=length,
                            width=1)
        print(figure_angle)
        rib.draw()
        vector_start_point = rib.end_point
    sd.line(start_point, vector_start_point, width=1, color=sd.COLOR_YELLOW)
예제 #13
0
def square(start_point, angle, length):
    width = 3
    current_point = start_point
    for tilt_angle in range(angle, angle + 361 - 120, 90):
        v = sd.get_vector(start_point=current_point,
                          angle=tilt_angle + angle,
                          length=length,
                          width=width)
        v.draw()
        current_point = v.end_point
    sd.line(start_point=point_1, end_point=v.end_point, width=width)
예제 #14
0
def pentagon(start_point, angle, length):
    width = 3
    current_point = start_point
    for tilt_angle in range(angle, angle + 361 - 72, 72):
        v = sd.get_vector(start_point=current_point,
                          angle=tilt_angle + angle,
                          length=length,
                          width=width)
        v.draw()
        current_point = v.end_point
    sd.line(start_point=point_2, end_point=v.end_point, width=width)
예제 #15
0
def smailik(point, radius):
    #eyes
    eye1 = simple_draw.get_point(point.x - radius * .35,
                                 point.y + radius * .35)
    eye2 = simple_draw.get_point(point.x + radius * .35,
                                 point.y + radius * .35)
    simple_draw.circle(center_position=eye1,
                       radius=radius * .1,
                       color=simple_draw.COLOR_GREEN,
                       width=0)
    simple_draw.circle(center_position=eye2,
                       radius=radius * .1,
                       color=simple_draw.COLOR_GREEN,
                       width=0)
    #nose
    nose_point1 = simple_draw.get_point(point.x, point.y + radius * .5)
    nose_point2 = simple_draw.get_point(point.x, point.y - radius * .25)
    simple_draw.line(nose_point1, nose_point2, width=2)
    #mouth
    mouth_point1 = simple_draw.get_point(point.x - radius * .3,
                                         point.y - radius * .4)
    mouth_point2 = simple_draw.get_point(point.x + radius * .3,
                                         point.y - radius * .4)
    simple_draw.line(mouth_point1, mouth_point2, width=1)
    simple_draw.get_vector(start_point=mouth_point1,
                           angle=150,
                           length=radius * .25).draw()
    simple_draw.get_vector(start_point=mouth_point2,
                           angle=30,
                           length=radius * .25).draw()
    #full face
    simple_draw.circle(center_position=point, radius=radius)
    #body
    body_point1 = simple_draw.get_point(point.x, point.y - radius)
    body = simple_draw.get_vector(start_point=body_point1,
                                  angle=270,
                                  length=radius * 2)
    body.draw()
    #legs
    simple_draw.get_vector(start_point=body.end_point,
                           angle=240,
                           length=radius * 1.7).draw()
    simple_draw.get_vector(start_point=body.end_point,
                           angle=300,
                           length=radius * 1.7).draw()
    #arms
    arm_point = simple_draw.get_point(point.x, point.y - radius * 1.7)
    simple_draw.get_vector(start_point=arm_point,
                           angle=140,
                           length=radius * 1.6).draw()
    simple_draw.get_vector(start_point=arm_point,
                           angle=40,
                           length=radius * 1.6).draw()
예제 #16
0
 def draw_figure(point, length, angle):
     point_start = point
     angel_step = 0
     for _ in range(n - 1):
         angel_step += angle
         vector = sd.get_vector(start_point=point,
                                angle=angel_step,
                                length=length,
                                width=3)
         vector.draw()
         point = vector.end_point
     sd.line(start_point=point, end_point=point_start, width=3)
예제 #17
0
파일: 01_shapes.py 프로젝트: kv2709/sandbox
 def polygon(point=sd.get_point(0, 0), angle=0, length=100):
     corner = n
     first_vector = sd.get_vector(start_point=point, angle=angle, length=length, width=1)
     first_vector.draw()
     next_vector = first_vector
     for i in range(corner - 1):
         if i == corner - 2:
             sd.line(start_point=next_vector.end_point, end_point=point)
         else:
             angle += int(360 / corner)
             next_vector = sd.get_vector(start_point=next_vector.end_point, angle=angle, length=length, width=1)
             next_vector.draw()
def draw_line_rainbow(start_x=0, end_x=100):

    step = 0

    for color in rainbow_colors:
        start_point = sd.get_point(start_x + step, start_x)
        end_point = sd.get_point(end_x + step, end_x)
        sd.line(start_point=start_point,
                end_point=end_point,
                color=color,
                width=5)
        step += 5
예제 #19
0
 def polygon(point, angle, length):
     now_point = point
     now_length = length
     for m in range(0, 360, side):
         angle += m
         v = sd.get_vector(start_point=now_point,
                           angle=m,
                           length=now_length,
                           width=3)
         v.draw()
         now_point = v.end_point
     sd.line(start_point=now_point, end_point=now_point, width=3)
예제 #20
0
def sd_regular_polygon(point, angle, length, sides, color=sd.COLOR_RED):
    current_start = point
    current_angle = angle
    angle_step = 360 / sides
    for i in range(sides - 1):
        v = sd.get_vector(start_point=current_start,
                          angle=current_angle,
                          length=length)
        v.draw(color=color)
        current_start = v.end_point
        current_angle += angle_step
    sd.line(start_point=current_start, end_point=point, color=color)
예제 #21
0
def draw_shapes(
        start_point=sd.get_point(100, 100), incline_angle=0, *, step, length):
    shapes_sides = None
    next_start_point = start_point
    # ниже из суммы углов вычетается 1 шаг = угол, так как последняя сторона рисуется отдельно из-за проблемы округления
    for step in range(incline_angle, 360 - step, step):
        shapes_sides = sd.get_vector(start_point=next_start_point,
                                     angle=step,
                                     length=length)
        shapes_sides.draw(color=sd.COLOR_PURPLE)
        next_start_point = shapes_sides.end_point
    sd.line(start_point=start_point, end_point=shapes_sides.end_point, width=1)
예제 #22
0
def triangle(point, angle=0, length=200, color=sd.COLOR_BLACK, width=10):
    width = width
    sides = 3
    angle_step = 360 / sides
    end_point = draw_shapes(point,
                            sides,
                            angle_step,
                            angle,
                            length,
                            color=color,
                            width=width)
    sd.line(point, end_point, color, width=width)
예제 #23
0
def rainbow_line():
    x_start = 50
    y_start = 50
    x_end = 350
    y_end = 450

    for color in rainbow_colors:
        start_point = sd.get_point(x_start, y_start)
        end_point = sd.get_point(x_end, y_end)
        sd.line(start_point, end_point, color, 4)
        x_start = x_start + 5
        x_end = x_end + 5
예제 #24
0
def draw_vector(count_angle, start_point, start_angle, lenght, color):
    angle = 360 / count_angle
    local_point = start_point
    for i in range(count_angle):
        v1 = sd.get_vector(start_point=local_point,
                           angle=start_angle + i * angle,
                           length=lenght,
                           width=3)
        v1.draw(color=color)
        local_point = v1.end_point
        if i == count_angle - 1:
            sd.line(local_point, start_point, color, width=3)
예제 #25
0
def polygon(angle_num, point, angle=0, length=100):
    angle_n = 180 - round(((angle_num - 2) / angle_num), 15) * 180
    for i in range(angle_num):
        if i == angle_num - 1:
            sd.line(point, p, width=3)
            break
        v = sd.get_vector(start_point=point,
                          angle=angle + i * angle_n,
                          length=length,
                          width=3)
        v.draw()
        point = v.end_point
예제 #26
0
 def draw_vector(point, angle, length):
     corner = 360 / n
     local_point = point
     for i in range(n):
         v1 = sd.get_vector(start_point=local_point,
                            angle=angle + i * corner,
                            length=length,
                            width=3)
         v1.draw()
         local_point = v1.end_point
         if i == n - 1:
             sd.line(local_point, point, sd.COLOR_YELLOW, width=3)
예제 #27
0
def all_in(point, angle, length, count, color):
    v2 = sd.get_vector(point, angle, length)
    step = (360 // count) - 1
    for cur_angle in range(step):
        v1 = sd.get_vector(start_point=point,
                           angle=angle,
                           length=length,
                           width=3)
        v1.draw(color=color)
        point = v1.end_point
        angle += count
    sd.line(start_point=point, end_point=v2.start_point, width=3, color=color)
예제 #28
0
def smile_draw(x, y, color):
    radius = 80
    sd.circle(center_position=sd.get_point(x, y), color=color, radius=radius, width=2)

    for step in (-25, 25):
        eye = sd.get_point(x + step, y + 15)
        sd.circle(center_position=eye, color=color, radius=5, width=2)

    for i in range(45, 140):
        start_point = sd.get_point(x - 90 + i, y + 50 - 100 * sd.sin(i))
        end_point = sd.get_point(x - 90 + i, y + 50 - 100 * sd.sin(i))
        sd.line(start_point=start_point, end_point=end_point, color=color, width=2)
예제 #29
0
def build_roof(
        start_point=sd.get_point(100, 100), length=50, color=sd.COLOR_YELLOW):
    for roof_length in range(length):
        vector_start_point = start_point
        for figure_angle in range(0, 240, 120):
            rib = sd.vector(start=vector_start_point,
                            angle=figure_angle,
                            length=roof_length,
                            color=color,
                            width=2)
            vector_start_point = rib
        sd.line(start_point, vector_start_point, color=color)
예제 #30
0
def draw_smile(x, y, col):
    coor1 = sd.get_point(x, y)
    coor2 = sd.get_point(x + 150, y + 100)
    eye1 = sd.get_point(x + 40, y + 60)
    eye2 = sd.get_point(x + 100, y + 60)
    mouth_line1 = sd.get_point(x + 40, y + 20)
    mouth_line2 = sd.get_point(x + 70, y + 15)
    mouth_line3 = sd.get_point(x + 100, y + 20)
    sd.ellipse(coor1, coor2, col, 2)
    sd.circle(eye1, 10, col, 2)
    sd.circle(eye2, 10, col, 2)
    sd.line(mouth_line1, mouth_line2, col, 2)
    sd.line(mouth_line2, mouth_line3, col, 2)
예제 #31
0
def vertical_line():
    space = 0
    for i, step_y in enumerate(range(0, 1000, 50)):
        if i % 2 == 0:
            step_x = 50
        else:
            step_x = 0

        for i, step in enumerate(range(0, 1000, 100)):
            space += step
            start = sd.get_point(step + step_x, step_y)
            end = sd.get_point(step + step_x, 50 + step_y)
            sd.line(start_point=start, end_point=end, width=1)