예제 #1
0
def heart(a, b):
    line(a, b, a - 20, b - 80)
    penColor(255, 0, 0)
    brushColor(255, 0, 0)
    polygon([(a - 20, b - 80), (a - 7, b - 140), (a - 62, b - 120), (a - 20, b - 80)])
    circle(a - 25, b - 135, 18)
    circle(a - 47, b - 128, 18)
예제 #2
0
def apple(x, y, size, mirror):
    """
    apple function draws the apple of the radius r pxls for size = 1
        there are 3 components:
                1) main body
                2) root, represented by a line
                3) leaf, which is obviously a sqrt curve

            The coords of root and leaf are given regarding to r of an main body,
            so all "strange" numbers in the further functions are also just a calibrate number for beauty's purposes
            (._.)

            mirror is for drawing mirrored images
    """
    # apple body
    penColor(245, 84, 84)
    penSize(0)
    brushColor(245, 84, 84)
    circle(x, y, 25 * size)
    # root
    penColor("black")
    penSize(2 * size)
    line(x, y - size * 20, x + size * 12.5 * mirror, y - size * 42.5)
    # leaf
    brushColor(100, 225, 100)
    penSize(size)
    polygon(curve(x + size * 2.5 * mirror, y - size * 27.5, size, mirror))
예제 #3
0
def window(x0, y0, win_width, indent_out, indent_in):
    """Drawing window.
    (x0, y0) - right middle point, indent_out - window indent,
    indent_in - indent inside window"""
    graph.penColor(215, 255, 230)
    graph.brushColor(215, 255, 230)

    x1 = x0 - indent_out
    y1 = y0 - indent_out
    x2 = x0 - indent_out - win_width
    y2 = indent_out

    graph.rectangle(x1, y1, x2, y2)

    graph.penColor(135, 205, 225)
    graph.brushColor(135, 205, 225)
    graph.rectangle(x2 + indent_in, y2 + indent_in,
                    x2 + win_width / 2 - indent_in,
                    y2 + (y1 - y2) / 2 - indent_in)
    graph.rectangle(x2 + indent_in, y2 + (y1 - y2) / 2 + indent_in,
                    x2 + win_width / 2 - indent_in, y2 + (y1 - y2) - indent_in)
    graph.rectangle(x2 + win_width / 2 + indent_in, y2 + indent_in,
                    x2 + win_width - indent_in, y2 + (y1 - y2) / 2 - indent_in)
    graph.rectangle(x2 + win_width / 2 + indent_in,
                    y2 + (y1 - y2) / 2 + indent_in, x2 + win_width - indent_in,
                    y2 + (y1 - y2) - indent_in)
예제 #4
0
def alien(x, y, size, mirror, color='#C7F971'):
    """
    alien has a lot of atributes (it is possible to constract one by yourself):
            1)body consists of the main_body and ass (ass is able to be rotated)
            2)there are to types of hands: up and down
            3)two types of legs
            4)head part includes the head itself, horns, eyes
            5)apple (which is not necessary, but according to the task it is much easier to place apple function here)

            also it is possible to change proportions of an any part of the alien in the code section,
            by the way this alien is easy to be painted in any color

            p.s. alein's balls can be painted differentely by adding color atribute to the horns function
            (.Y.)
    """
    penColor(color)
    brushColor(color)

    main_body(x, y, size)
    ass(x, y, size)

    hand_down(x, y, size, mirror)
    hand_up(x, y, size, mirror)

    leg_left(x, y, size, mirror)
    leg_right(x, y, size, mirror)

    head(x, y, size)
    eyes(x, y, size, mirror)
    horns(x, y, size, "blue")

    apple(x + 3 * size * mirror, y - size * 3.2, size / 28, mirror)
예제 #5
0
def update():
    for object_ in objects_of_ship_2:
        g.moveObjectBy(object_, dx, 0)

    for object_ in cloud1:
        g.moveObjectBy(object_, dx / 3, 0)
    for object_ in cloud2:
        g.moveObjectBy(object_, dx * 2, 0)
    for object_ in cloud3:
        g.moveObjectBy(object_, dx * 1.5, 0)

    g.penColor('white')
    g.brushColor('white')
    g.rectangle(0, 0, frame_thickness, window_height)
    g.rectangle(window_width - frame_thickness, 0, window_width, window_height)

    if g.xCoord(stern_of_ship) > window_width:
        for object_ in objects_of_ship_2:
            g.moveObjectBy(object_, - window_width - ship_length, 0)

    if g.xCoord(cloud2[0]) > window_width:
        for object_ in cloud2:
            g.moveObjectBy(object_, - window_width - ship_length, 0)

    if g.xCoord(cloud1[0]) > window_width:
        for object_ in cloud1:
            g.moveObjectBy(object_, - window_width - ship_length, 0)

    if g.xCoord(cloud3[0]) > window_width:
        for object_ in cloud3:
            g.moveObjectBy(object_, - window_width - ship_length, 0)
예제 #6
0
def draw_clouds(center_of_the_fisrt_cloud_x, center_of_the_first_cloud_y,
                cloud_radius_x, cloud_radius_y):
    cloud_object = []
    g.penSize(pen_width_1)
    cloud_color = 'white'
    g.brushColor(cloud_color)
    g.penColor('grey')
    step_of_clouds = 3 / 2 * cloud_radius_x

    center_cloud_1_x = center_of_the_fisrt_cloud_x
    center_cloud_1_y = center_of_the_first_cloud_y
    number_of_clouds_1 = 2
    for _ in range(number_of_clouds_1):
        obj = draw_an_ellipse(center_cloud_1_x, center_cloud_1_y, cloud_radius_x, cloud_radius_y)
        center_cloud_1_x += step_of_clouds
        cloud_object.append(obj)

    center_cloud_2_x = center_of_the_fisrt_cloud_x - cloud_radius_x
    center_cloud_2_y = center_of_the_first_cloud_y + cloud_radius_y
    number_of_clouds_2 = 3
    for _ in range(number_of_clouds_2):
        obj = draw_an_ellipse(center_cloud_2_x, center_cloud_2_y, cloud_radius_x, cloud_radius_y)
        center_cloud_2_x += step_of_clouds
        cloud_object.append(obj)

    obj1 = draw_an_ellipse(center_cloud_1_x, center_cloud_1_y, cloud_radius_x, cloud_radius_y)
    cloud_object.append(obj1)
    obj2 = draw_an_ellipse(center_cloud_2_x, center_cloud_2_y, cloud_radius_x, cloud_radius_y)
    cloud_object.append(obj2)

    return cloud_object
예제 #7
0
def sheep(x, y, n):
    coordintes = []

    for i in range(20):
        coordintes.append([-i * mod / 20, 1 - (i / 20)**2])

    coordintes.append([3 * mod, 0])

    for i in range(20):
        coordintes.append([(3 - i / 20) * mod, (i / 20)**2])

    for i in range(len(coordintes)):
        coordintes[i] = [n * coordintes[i][0] + x, n * coordintes[i][1] + y]

    brushColor('red')
    penColor('black')
    rectangle(mod * n * (3 / 4) + x, y, mod * n + x, y - (2 / 2) * n)
    brushColor('light grey')
    rectangle(x, +n / 2 + y, x + n * mod, y - n * (1 / 2))
    polygon(coordintes)
    brushColor('grey')
    circle(x + mod * n / 4, y - 0.25 * n, n // 6)
    brushColor("light grey")
    penColor("light grey")
    circle(x + (n + n // 7) * mod, y - 1.5 * n, n // 8)
    circle(x + (n + n // 2) * mod, y - 2.0 * n, n // 7)
    circle(x + mod * 2.2 * n, y - 2.5 * n, n // 6)
예제 #8
0
def clouds(x1, y1, radius):
    """
    x1 - координата центра центральной окружности X
    y1 - координата центра центральной окружности Y
    radius - радиус шариков составляющих облако

    Центр каждого из шариков расположен на расстоянии
    2 * radius от центра окружности лежащей с ней на одной высоте

    Координаты наивысших шариков
    graph.circle(x1, y1 - 1.5 * radius, radius)
    graph.circle(x1, y1 + 1.5 * radius, radius)
    """
    graph.penColor("black")
    graph.brushColor("white")
    graph.circle(x1, y1 - 1.5 * radius, radius)
    graph.circle(x1, y1 + 1.5 * radius, radius)

    graph.circle(x1 + 2 * radius, y1, radius)
    graph.circle(x1 - 2 * radius, y1, radius)

    graph.circle(x1 - radius, y1 - radius, radius)
    graph.circle(x1 + radius, y1 + radius, radius)

    graph.circle(x1 - radius, y1 + radius, radius)
    graph.circle(x1 + radius, y1 - radius, radius)
    graph.circle(x1, y1, radius)
예제 #9
0
def draw_clouds(center_of_the_fisrt_cloud_x, center_of_the_first_cloud_y,
                cloud_radius_x, cloud_radius_y):

    g.penSize(pen_width_1)
    cloud_color = 'white'
    g.brushColor(cloud_color)
    g.penColor('grey')
    step_of_clouds = 3 / 2 * cloud_radius_x

    center_cloud_1_x = center_of_the_fisrt_cloud_x
    center_cloud_1_y = center_of_the_first_cloud_y
    number_of_clouds_1 = 2
    for i in range(number_of_clouds_1):
        draw_an_ellipse(center_cloud_1_x, center_cloud_1_y, cloud_radius_x,
                        cloud_radius_y)
        center_cloud_1_x += step_of_clouds

    center_cloud_2_x = center_of_the_fisrt_cloud_x - cloud_radius_x
    center_cloud_2_y = center_of_the_first_cloud_y + cloud_radius_y
    number_of_clouds_2 = 3
    for i in range(number_of_clouds_2):
        draw_an_ellipse(center_cloud_2_x, center_cloud_2_y, cloud_radius_x,
                        cloud_radius_y)
        center_cloud_2_x += step_of_clouds

    draw_an_ellipse(center_cloud_1_x, center_cloud_1_y, cloud_radius_x,
                    cloud_radius_y)
    draw_an_ellipse(center_cloud_2_x, center_cloud_2_y, cloud_radius_x,
                    cloud_radius_y)
예제 #10
0
def window(x0, y0, width, indent, small_indent):
    graph.penColor(215, 255, 230)
    graph.brushColor(215, 255, 230)

    x1 = x0 - indent
    y1 = y0 - indent
    x2 = x0 - indent - width
    y2 = indent

    graph.rectangle(x1, y1, x2, y2)

    graph.penColor(135, 205, 225)
    graph.brushColor(135, 205, 225)
    graph.rectangle(x2 + small_indent, y2 + small_indent,
                    x2 + width / 2 - small_indent,
                    y2 + (y1 - y2) / 2 - small_indent)
    graph.rectangle(x2 + small_indent, y2 + (y1 - y2) / 2 + small_indent,
                    x2 + width / 2 - small_indent,
                    y2 + (y1 - y2) - small_indent)
    graph.rectangle(x2 + width / 2 + small_indent, y2 + small_indent,
                    x2 + width - small_indent,
                    y2 + (y1 - y2) / 2 - small_indent)
    graph.rectangle(x2 + width / 2 + small_indent,
                    y2 + (y1 - y2) / 2 + small_indent,
                    x2 + width - small_indent, y2 + (y1 - y2) - small_indent)
예제 #11
0
def el(x, y, r, g, b):
    a = []
    n = 500
    for i in range(n):
        a.append((x + 120 * math.cos(2 * math.pi * i / n),
                  y + 30 * math.sin(2 * math.pi * i / n)))
        penColor(r, g, b)
        polygon(a)
예제 #12
0
def fon():
    canvasSize(1200, 800)  # drawing size
    penColor(0, 255, 0)  # grass
    brushColor(0, 245, 0)
    rectangle(0, 400, 1200, 800)
    penColor(200, 230, 255)  # sky
    brushColor(200, 230, 255)
    rectangle(0, 0, 1200, 400)
예제 #13
0
파일: project3.py 프로젝트: dikuzakov/p_3
def background(h, d):
    graph.penColor('#000000')
    graph.brushColor('#a1f5ff')
    graph.rectangle(0, 0, d, 7 / 15 * h)
    graph.brushColor('#4423df')
    graph.rectangle(0, 7 / 15 * h, d, 10 / 15 * h)
    graph.brushColor('#eef60c')
    graph.rectangle(0, 10 / 15 * h, d, h)
예제 #14
0
def eyes(color_red, color_green, color_blue, x_coord):
    brushColor(color_red, color_green, color_blue)
    penColor('black')
    circle(x_coord + 65, 349, 35)
    circle(x_coord - 65, 349, 35)
    brushColor('black')
    circle(x_coord + 65, 349, 10)
    circle(x_coord - 65, 349, 10)
예제 #15
0
def head(x_coord, r, g, b, hair_color):
    brushColor(233, 200, 176)
    penColor(200, 200, 200)
    circle(x_coord, 384, 200)
    penColor(0, 0, 0)
    eyes(r, g, b, x_coord)
    nose_and_mouth(x_coord)
    hair(hair_color, x_coord)
예제 #16
0
def house(x, y, n):  # n - parameter that sets the size of the house
    penColor(0, 0, 0)  # x, y - coordinates of the upper left edge of the house
    brushColor(210, 200, 10)
    rectangle(x, y, x + 200 * n, y + 150 * n)
    brushColor(255, 100, 100)
    polygon([(x, y), (x + 200 * n, y), (x + 100 * n, y - 100 * n), (x, y)])
    brushColor(150, 150, 255)
    penColor(255, 100, 10)
    rectangle(x + 50 * n, y + 50 * n, x + 150 * n, y + 100 * n)
예제 #17
0
def cloud(x, y, r, n):  # n - parameter that sets the size
    penColor(0, 0, 0)  # of the cloud x, y - coordinates
    brushColor(255, 255, 255)  # of the upper left corner of a rectangle
    circle(x + 10 * n, y + 20 * n, r * n)  # with the (50*n; 30*n)
    circle(x + 20 * n, y + 20 * n, r * n)  # dimensios described
    circle(x + 30 * n, y + 20 * n, r * n)  # around the cloud
    circle(x + 40 * n, y + 20 * n, r * n)
    circle(x + 18 * n, y + 10 * n, r * n)
    circle(x + 32 * n, y + 10 * n, r * n)
예제 #18
0
def ufo_ship(x, y, size):
    # main body
    brushColor(168, 168, 168)
    penColor(168, 168, 168)
    ellips(x, y, 20 * size, 5 * size, 0)
    # glass
    brushColor(180, 220, 220)
    penColor(180, 220, 220)
    ellips(x, y - 3 * size, 12 * size, 4 * size, 0)
예제 #19
0
def right_arm(length, angle, x_coord):
    brushColor(233, 200, 176)
    penColor(200, 200, 200)
    polygon([(x_coord + 167, 549), (x_coord + 207, 569),
             (x_coord + 207 + length * cos(angle), 569 - length * sin(angle)),
             (x_coord + 167 + length * cos(angle), 549 - length * sin(angle))])
    penColor('white')
    circle(
        (2 * x_coord + length * cos(angle) + 207 + length * cos(angle) + 167) /
        2, (569 - length * sin(angle) + 549 - length * sin(angle)) / 2, 40)
예제 #20
0
def left_arm(length, angle, x_coord):
    brushColor(233, 200, 176)
    penColor(200, 200, 200)
    polygon([(x_coord - 233, 569), (x_coord - 193, 549),
             (x_coord - 193 - length * cos(angle), 549 + length * sin(angle)),
             (x_coord - 233 - length * cos(angle), 569 + length * sin(angle))])
    penColor('white')
    circle(
        (2 * x_coord - length * cos(angle) - 233 - length * cos(angle) - 193) /
        2, (549 + length * sin(angle) + 569 + length * sin(angle)) / 2, 40)
def bird_pts():
    """Generate a point array which can be used to draw a bird"""
    penColor('white')
    penSize(3)
    points = []
    for i in range(30):
        points.append((i - 30, 0.02 * i * (i - 30)))
    for i in range(31):
        points.append((i, 0.02 * i * (i - 30)))
    return points
예제 #22
0
def clouds(x1, y1, radius):
    graph.penColor("black")
    graph.brushColor("white")
    graph.circle(x1 + 2 * radius, y1, radius)
    graph.circle(x1 - 2 * radius, y1, radius)
    graph.circle(x1 - radius, y1 - radius, radius)
    graph.circle(x1 + radius, y1 + radius, radius)
    graph.circle(x1 - radius, y1 + radius, radius)
    graph.circle(x1 + radius, y1 - radius, radius)
    graph.circle(x1, y1, radius)
예제 #23
0
def cloud(x, y, size, color):
    """
    just 3 elipses along each other
    """
    colinc = 10
    brushColor(color + colinc, color + colinc, color + colinc)
    penColor(color + colinc, color + colinc, color + colinc)
    ellips(x - 1.2 * size, y, size, size, 0)
    ellips(x, y, size, size, 0)
    ellips(x + 1.2 * size, y, size, size, 0)
예제 #24
0
def ufo_light(x, y, size):
    # light - light pillar of an ufo
    penSize(0)
    brushColor(210, 250, 210)
    penColor(210, 250, 210)
    light = []
    light.append((x, y))
    light.append((x - 20 * size, y + 20 * size))
    light.append((x + 20 * size, y + 20 * size))
    polygon(light)
예제 #25
0
def star(x_star, y_star):
    """
    draws a star '+' shaped
    """
    penColor(255, 244, 164)
    point(x_star, y_star)
    point(x_star + 1, y_star)
    point(x_star - 1, y_star)
    point(x_star, y_star + 1)
    point(x_star, y_star - 1)
def swan(scale: float = 1., reflect: bool = False):
    """The Swan"""
    penSize(scale)
    penColor('black')
    brushColor('orange')
    swan_objs = [
        ellipse_sr(380, 110, 418, 120, scale,
                   reflect),  # Element #0 - beak lower part
        ellipse_sr(380, 105, 420, 115, scale,
                   reflect),  # Element #1 - beak upper part
        foot(scale, reflect),  # Element #2 - left foot
        foot(scale, reflect)
    ]  # Element #3 - right foot
    moveObjectBy(swan_objs[2], reflect_offset(14 * scale, reflect),
                 6 * scale)  # Move left foot to needed position
    moveObjectBy(swan_objs[3], reflect_offset(74 * scale, reflect),
                 6 * scale)  # Move left right to needed position
    brushColor('white')
    # Points were selected randomly, attention
    tail_pts = [(160, 125), (160, 150), (80, 163), (103, 150), (70, 141),
                (100, 129), (80, 110)]
    swan_objs.extend([
        wing(scale, reflect),  # Element #4 - left wing
        wing(scale, reflect),  # Element #5 - right wing
        poly_sr(tail_pts, scale, reflect)
    ])  # Element #6 - tail
    moveObjectBy(swan_objs[4], reflect_offset(140 * scale, reflect),
                 7 * scale)  # Move left wing to needed position
    moveObjectBy(swan_objs[5], reflect_offset(190 * scale, reflect),
                 7 * scale)  # Move right wing to needed position
    penColor('white')
    swan_objs.extend([
        ellipse_sr(150, 100, 300, 180, scale, reflect),  # Element #7 - body
        ellipse_sr(280, 110, 340, 140, scale, reflect),  # Element #8 - neck
        ellipse_sr(330, 95, 390, 130, scale, reflect)
    ])  # Element #9 - head
    brushColor('black')
    swan_objs.append(ellipse_sr(360, 102, 372, 110, scale,
                                reflect))  # Element #10 - eye
    penSize(10 * scale)
    swan_objs.extend([
        line_sr(190, 160, 220, 230, scale, reflect),  # Elements ##11-16 - legs
        line_sr(250, 160, 280, 230, scale, reflect),
        line_sr(220, 230, 240, 240, scale, reflect),
        line_sr(280, 230, 300, 240, scale, reflect),
        circle({
            False: 220 * scale,
            True: 400 - 220 * scale
        }[reflect], 230 * scale, 1.5 * scale),
        circle({
            False: 280 * scale,
            True: 400 - 280 * scale
        }[reflect], 230 * scale, 1.5 * scale)
    ])
    return swan_objs
예제 #27
0
def main_body(color, x_coord):
    penColor(color)
    brushColor(color)
    circle(x_coord, 769, 300)
    penColor('black')
    brushColor(color)
    # shoulders
    polygon([(x_coord - 163, 629), (x_coord - 243, 629), (x_coord - 253, 539),
             (x_coord - 183, 489), (x_coord - 143, 549)])
    polygon([(x_coord + 237, 629), (x_coord + 157, 629), (x_coord + 147, 539),
             (x_coord + 217, 489), (x_coord + 257, 549)])
예제 #28
0
def spyral(koef=1, X=100, Y=150):
    penSize(10)
    moveTo(X * k, Y * k)
    j = 0
    while j < 360 * 4 * abs(koef):
        rho = j / 10 * koef / abs(koef)
        lineTo(100 * k + rho * math.sin(j / 360 * 3.14) + X * k - 100 * k,
               150 * k + rho * math.cos(j / 360 * 3.14) + Y * k - 150 * k)
        j += 1
        if j % 30 == 0:
            penColor(randColor())
예제 #29
0
def tree(x, y, r, n):  # x, y - coordinates of the upper left corner
    penColor(0, 0, 0)  # of a rectangle with the (70*n; 100*n)
    brushColor(0, 0, 0)  # dimensios described around the cloud
    rectangle(x + 30 * n, y + 50 * n, x + 40 * n, y + 100 * n)
    brushColor(0, 90, 0)  # n - parameter that sets the size of the tree
    circle(x + 35 * n, y + 15 * n, r * n)
    circle(x + 15 * n, y + 25 * n, r * n)  # r - radius
    circle(x + 55 * n, y + 25 * n, r * n)
    circle(x + 35 * n, y + 35 * n, r * n)
    circle(x + 20 * n, y + 50 * n, r * n)
    circle(x + 50 * n, y + 50 * n, r * n)
예제 #30
0
def dog(x_oporn, y_oporn):

    graph.brushColor("#8B4513")
    graph.penColor("#8B4513")

    x2 = x_oporn - 70  # coordinate for head
    y2 = y_oporn - 50

    ellipse(x_oporn, y_oporn, 60, 30)  # body front

    ellipse(x_oporn - 65, y_oporn + 25, 13, 35)  # legs front upper
    ellipse(x_oporn - 10, y_oporn + 45, 13, 35)

    ellipse(x_oporn + 50, y_oporn - 15, 20, 27)  # body behing
    ellipse(x_oporn + 80, y_oporn - 15, 30, 27)
    ellipse(x_oporn + 95, y_oporn + 5, 20, 27)

    ellipse(x_oporn + 110, y_oporn + 35, 5, 25)  # legs upper behind
    ellipse(x_oporn + 60, y_oporn + 15, 5, 25)

    ellipse(x_oporn - 75, y_oporn + 60, 15, 5)  # legs under front
    ellipse(x_oporn - 21, y_oporn + 80, 15, 5)

    ellipse(x_oporn + 48, y_oporn + 39, 13, 4)  # legs under behind
    ellipse(x_oporn + 99, y_oporn + 58, 13, 4)

    graph.penColor("black")

    graph.rectangle(x2, y2, x2 + 60, y2 + 60)  # head

    ellipse(x2, y2 + 15, 10, 14)  # ears
    ellipse(x2 + 60, y2 + 15, 10, 14)

    graph.brushColor("white")  # left eye
    ellipse(x_oporn - 52, y_oporn - 22, 7, 3)
    graph.brushColor("black")
    ellipse(x_oporn - 52, y_oporn - 22, 2, 2)

    graph.brushColor("white")  # right eye
    ellipse(x_oporn - 28, y_oporn - 22, 7, 3)
    graph.brushColor("black")
    ellipse(x_oporn - 28, y_oporn - 22, 2, 2)

    x = x_oporn - 60
    y = y_oporn + 5

    graph.polyline([(x, y), (x + 5, y - 6), (x + 8, y - 7), (x + 10, y - 8),
                    (x + 30, y - 8), (x + 32, y - 7), (x + 35, y - 6),
                    (x + 40, y)])  # mouth without tith

    graph.brushColor("white")
    graph.polygon([(x + 5, y - 6), (x + 10, y - 8),
                   (x + 7, y - 15)])  # toth without mouth
    graph.polygon([(x + 35, y - 6), (x + 30, y - 8), (x + 33, y - 15)])