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))
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)
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)
def nose_and_mouth(x_coord): # nose brushColor('brown') polygon([(x_coord + 20, 394), (x_coord - 20, 394), (x_coord, 424)]) # mouth brushColor('red') polygon([(x_coord - 130, 454), (x_coord + 150, 454), (x_coord, 534)])
def rectangle_inclined(x0, y0, width, height, alpha): if alpha >= 0: x1 = x0 + width * cos(alpha) y1 = y0 + width * sin(alpha) x2 = x1 + height * sin(alpha) y2 = y1 - height * cos(alpha) x3 = x0 + height * sin(alpha) y3 = y0 - height * cos(alpha) graph.polygon([(x0, y0), (x1, y1), (x2, y2), (x3, y3)]) else: alpha = -alpha x1 = x0 - width * cos(alpha) y1 = y0 + width * sin(alpha) x2 = x1 - height * sin(alpha) y2 = y1 - height * cos(alpha) x3 = x0 - height * sin(alpha) y3 = y0 - height * cos(alpha) graph.polygon([(x0, y0), (x1, y1), (x2, y2), (x3, y3)])
def zont(x1, y1, x2, y2): graph.brushColor("brown") graph.rectangle(x1, y1, x2, y2) graph.brushColor("orange") graph.polygon([(x2 - x1, y2 + 10), (x2 - x1, y2 - 20), (x2 + 30, y2 - 20), (x2 - x1, y2 + 10)]) graph.polygon([(x2 - x1, y2 + 10), (x2 - x1, y2 - 20), (x1 - 30, y2 - 20), (x2 - x1, y2 + 10)])
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)
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)
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)
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)
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 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)])
def sail(x, y, deck_lenght, carcass_height): """ Рисует двойной парус. (x, y) -- координаты правой верхней точки прямоугольника-палубы. deck_lenght, carcass_height -- длина прямоугольника-палубы и высота корпуса. """ graph.brushColor('white') graph.polygon([(x + 0.03*deck_lenght + deck_lenght/3, y), (x + 0.8*deck_lenght, y - 2.5*carcass_height/2), (x + 0.12*deck_lenght + deck_lenght/3, y - 2.5*carcass_height/2), (x + 0.03*deck_lenght + deck_lenght/3, y)]) graph.polygon([(x + 0.03*deck_lenght + deck_lenght / 3, y - 2.5*carcass_height), (x + 0.8 * deck_lenght, y - 2.5 * carcass_height / 2), (x + 0.12*deck_lenght + deck_lenght / 3, y - 2.5 * carcass_height / 2), (x + 5 + deck_lenght / 3, y - 2.5*carcass_height)])
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)])
def ellips1(xc, yc, a, b, fi=0): L = [] for x in range(-a, a): y = ((1 - x**2 / a**2) * b**2)**(1 / 2) L.append((xc + m.cos(fi) * x + m.sin(fi) * y, (yc - m.sin(fi) * x + m.cos(fi) * y))) for x in range(a, -a, -1): y = ((1 - x**2 / a**2) * b**2)**(1 / 2) L.append((xc + m.cos(fi) * x + m.sin(fi) * (-y), (yc - m.sin(fi) * x + m.cos(fi) * (-y)))) g.polygon(L)
def oval(x0, y0, radius, compression, alpha): t = 0 points = [] while t < 2 * pi: x = radius * cos(t) y = radius * sin(t) / compression xe = x0 + x * cos(alpha) - y * sin(alpha) ye = y0 + x * sin(alpha) + y * cos(alpha) points.append((xe, ye)) t += pi / 180 graph.polygon(points)
def bird(xb, yb, mb): polygon([(xb, yb), (xb - 5 * mb, yb), (xb - 10 * mb, yb - 1 * mb), (xb - 15 * mb, yb - 2 * mb), (xb - 20 * mb, yb - 3.5 * mb), (xb - 25 * mb, yb - 6 * mb), (xb - 30 * mb, yb - 9 * mb), (xb - 35 * mb, yb - 12.5 * mb), (xb - 37.5 * mb, yb - 15 * mb), (xb - 40 * mb, yb - 20 * mb), (xb - 30 * mb, yb - 20 * mb), (xb - 20 * mb, yb - 18 * mb), (xb - 10 * mb, yb - 15 * mb), (xb - 5 * mb, yb - 13 * mb), (xb, yb - 10 * mb), (xb + 3.5 * mb, yb - 8 * mb), (xb + 5 * mb, yb - 10 * mb), (xb + 7 * mb, yb - 13 * mb), (xb + 10 * mb, yb - 16 * mb), (xb + 15 * mb, yb - 18.5 * mb), (xb + 20 * mb, yb - 20 * mb), (xb + 30 * mb, yb - 22 * mb), (xb + 40 * mb, yb - 20 * mb)])
def update_mouth(): step = g.xCoord(mouth_help) global m m = 1 / (step + 2) g.brushColor('red') g.polygon([(600 / z, 500 / z + 150 / z), (600 / z + 150 * m / z, 500 / z + 60 / z), (600 / z - 150 * m / z, 500 / z + 60 / z), (600 / z, 500 / z + 150 / z)]) step += 1 if step >= 7: g.moveObjectBy(mouth_help, -7, 0)
def sun(x, y, r, ray): # Enter x, y - center coordinates, r - rad, ray - ray length + rad. brushColor('yellow') penColor('yellow') penSize(0) v = 40 # v is the number of rays. for i in range(v): phi1 = 2 * i * pi / v phi2 = 2 * (i + 1) * pi / v polygon([(x, y), (x + r * cos(phi1), y + r * sin(phi1)), (x + ray * cos(phi1 + pi / v), y + ray * sin(phi1 + pi / v)), (x + r * cos(phi2), y + r * sin(phi2))])
def ellipse(a, b, x0, y0): x = a y = 0 s = [(x0 + a, y0)] for i in range(2 * a): x -= 1 y = ((1 - x**2 / (a**2)) * b**2)**0.5 s.append((x + x0, y + y0)) for i in range(2 * a): x += 1 y = -(((1 - x**2 / (a**2)) * b**2)**0.5) s.append((x + x0, y + y0)) polygon(s)
def ice_cream(a, b): penColor(255, 215, 0) brushColor(255, 215, 0) polygon([(a, b), (a - 20, b - 100), (a - 58, b - 65), (a, b)]) penColor(139, 69, 19) brushColor(139, 69, 19) ellipse(14, 10, a - 47, b - 70) penColor(255, 0, 0) brushColor(255, 0, 0) ellipse(14, 12, a - 32, b - 95) penColor(255, 255, 255) brushColor(255, 255, 255) ellipse(15, 12, a - 49, b - 88)
def sun(x_center, y_center, radius, wave_height, definition, N): brushColor("yellow") # N - number of rays penColor(255, 100, 10) verts = [] t = 0 while t < (10 * N * definition + 1): z_1 = (pi / (N * definition)) * t z_2 = (pi / definition) * t x = x_center + radius * (1 + wave_height * sin(z_2)) * cos(z_1) y = y_center + radius * (1 + wave_height * sin(z_2)) * sin(z_1) verts.append((x, y)) t += 1 polygon(verts)
def elips(x1, y1, x2, r): el = [] for x in range(int(x1), int(x2) + 1): el.append( (x, y1 + math.sqrt(abs(((x1 - x2) / 2)**2 / r - (x - (x1 + x2) / 2)**2 / r)))) for x in range(int(x2), int(x1), -1): el.append( (x, y1 - math.sqrt(abs(((x1 - x2) / 2)**2 / r - (x - (x1 + x2) / 2)**2 / r)))) graph.polygon(el)
def mtn_line3(): penColor(51, 0, 51) brushColor(51, 0, 51) polygon([(1000, 500), (0, 500), (0, 240), (100, 265), (200, 365), (xf5[0], yf5[0]), (xf5[1], yf5[1]), (xf5[2], yf5[2]), (xf5[3], yf5[3]), (xf5[4], yf5[4]), (xf5[5], yf5[5]), (xf5[6], yf5[6]), (xf5[7], yf5[7]), (xf5[8], yf5[8]), (xf5[9], yf5[9]), (650, 435), (675, 450), (xf6[0], yf6[0]), (xf6[1], yf6[1]), (xf6[2], yf6[2]), (xf6[3], yf6[3]), (xf6[4], yf6[4]), (xf6[5], yf6[5]), (xf6[6], yf6[6]), (xf6[7], yf6[7]), (xf6[8], yf6[8]), (xf6[9], yf6[9]), (xf6[10], yf6[10]), (xf6[11], yf6[11]), (xf6[12], yf6[12]), (xf6[13], yf6[13])])
def oval(x0, y0, radius, compression, alpha): """Drawing oval with center in (x0, y0), stated radius, compression and angle of rotation.""" t = 0 points = [] while t < 2 * pi: x = radius * cos(t) y = radius * sin(t) / compression xe = x0 + x * cos(alpha) - y * sin(alpha) ye = y0 + x * sin(alpha) + y * cos(alpha) points.append((xe, ye)) t += pi / 180 graph.polygon(points)
def mtn_line2(): penColor(153, 0, 0) brushColor(153, 0, 0) polygon([(1000, 300), (0, 350), (0, 245), (5, 245), (25, 265), (xf3[0], yf3[0]), (xf3[1], yf3[1]), (xf3[2], yf3[2]), (xf3[3], yf3[3]), (xf3[4], yf3[4]), (xf3[5], yf3[5]), (xf3[6], yf3[6]), (xf3[7], yf3[7]), (xf3[8], yf3[8]), (xf3[9], yf3[9]), (xf3[10], yf3[10]), (175, 240), (235, 275), (255, 215), (320, 235), (385, 270), (520, 250), (xf4[0], yf4[0]), (xf4[1], yf4[1]), (xf4[2], yf4[2]), (xf4[3], yf4[3]), (xf4[4], yf4[4]), (xf4[5], yf4[5]), (xf4[6], yf4[6]), (xf4[7], yf4[7]), (xf4[8], yf4[8]), (xf4[9], yf4[9]), (xf4[10], yf4[10]), (xf4[11], yf4[11]), (750, 250), (800, 210), (835, 235), (860, 205), (930, 210), (1000, 160)])
def draw_an_ellipse(ellipse_center_x, ellipse_center_y, amplitude_x, amplitude_y): angle = 0 details = 300 angle_step = 2 * math.pi / details points = [] for i in range(details): x = ellipse_center_x + amplitude_x * math.cos(angle) y = ellipse_center_y + amplitude_y * math.sin(angle) points.append((x, y)) angle += angle_step points.append((ellipse_center_x + amplitude_x, ellipse_center_y)) g.polygon(points)
def plant(a, x, b, y): graph.brushColor(0, 102, 53) graph.penColor(0, 102, 53) graph.penSize(2) # Далее ветки graph.polyline([(119 * a + x, 27 * b + y), (152 * a + x, 30 * b + y), (174 * a + x, 37 * b + y), (199 * a + x, 49 * b + y), (213 * a + x, 58 * b + y), (229 * a + x, 71 * b + y)]) graph.polyline([(274 * a + x, 57 * b + y), (286 * a + x, 41 * b + y), (304 * a + x, 26 * b + y), (326 * a + x, 14 * b + y), (342 * a + x, 7 * b + y), (362 * a + x, 4 * b + y), (376 * a + x, 2 * b + y)]) graph.polyline([(270 * a + x, 113 * b + y), (274 * a + x, 103 * b + y), (280 * a + x, 96 * b + y), (287 * a + x, 88 * b + y), (297 * a + x, 80 * b + y), (305 * a + x, 76 * b + y), (314 * a + x, 76 * b + y), (321 * a + x, 75 * b + y), (329 * a + x, 78 * b + y), (333 * a + x, 79 * b + y)]) graph.polyline([(170 * a + x, 105 * b + y), (178 * a + x, 102 * b + y), (187 * a + x, 100 * b + y), (194 * a + x, 100 * b + y), (203 * a + x, 102 * b + y), (210 * a + x, 105 * b + y), (220 * a + x, 110 * b + y), (228 * a + x, 117 * b + y), (234 * a + x, 123 * b + y), (245 * a + x, 139 * b + y)]) # Далее ствол graph.polygon([(254 * a + x, 53 * b + y), (269 * a + x, 4 * b + y), (275 * a + x, 7 * b + y), (260 * a + x, 56 * b + y)]) graph.polygon([(244 * a + x, 94 * b + y), (256 * a + x, 60 * b + y), (266 * a + x, 64 * b + y), (254 * a + x, 98 * b + y)]) graph.rectangle(247 * a + x, 105 * b + y, 263 * a + x, 165 * b + y) graph.rectangle(247 * a + x, 225 * b + y, 263 * a + x, 173 * b + y) # Далее листья накл. вправо ellipse1(0, -3 * b, a, b, x, y) ellipse1(11 * a, -2 * b, a, b, x, y) ellipse1(21 * a, 0, a, b, x, y) ellipse1(33 * a, 5 * b, a, b, x, y) ellipse1(51 * a, 11 * b, a, b, x, y) ellipse1(50 * a, 71 * b, a, b, x, y) ellipse1(65 * a, 71 * b, a, b, x, y) ellipse1(81 * a, 78 * b, a, b, x, y) # Далее листья накл. влево ellipse2(0, 0, a, b, x, y) ellipse2(15 * a, -10 * b, a, b, x, y) ellipse2(24 * a, -13 * b, a, b, x, y) ellipse2(34 * a, -15 * b, a, b, x, y) ellipse2(44 * a, -16 * b, a, b, x, y) ellipse2(1 * a, 56 * b, a, b, x, y) ellipse2(-13 * a, 56 * b, a, b, x, y) ellipse2(-26 * a, 64 * b, a, b, x, y)
def sheep(x, y, n, mod): # making at first a left directed(mod = 1) # or right directed(mod = -1) ship in [0, 3] coordinates # and only after everything making it n-size and at x,y ship_form_coordinates = [] # making the nose of the sheep # but the translator says crazy englishmen call it just a bow for i in range(20): ship_form_coordinates.append([-i * mod / 20, 1 - (i / 20)**2]) # making sure that despite rounding of squares # the bow will be higher than the back of the ship ship_form_coordinates.append([(-1) * mod, -0.05]) # the back of the ship for i in range(20): ship_form_coordinates.append([(3 - i / 20) * mod, (i / 20)**2]) # n-size for i in range(len(ship_form_coordinates)): ship_form_coordinates[i] = [ n * ship_form_coordinates[i][0] + x, n * ship_form_coordinates[i][1] + y ] # the pipe brushColor('red') penColor('black') rectangle(mod * n * (3 / 4) + x, y, mod * n + x, y - (2 / 2) * n) # basic form of the ship brushColor('light grey') rectangle(x, +n / 2 + y, x + n * mod, y - n * (1 / 2)) polygon(ship_form_coordinates) # the window of the ship brushColor('grey') circle(x + mod * n / 4, y - 0.25 * n, n // 7) # steam or smoke or how do u wanna call it 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)
def woman(a, b): penColor(233, 99, 233) brushColor(233, 99, 233) polygon([(a, b + 30), (a + 75, b + 220), (a - 75, b + 220), (a, b + 30)]) penColor(229, 194, 152) brushColor(229, 194, 152) circle(a, b, 45) penColor(0, 0, 0) # отрисовывает ноги : первые две строки - правую, а вторые две строки - левую; line(a + 20, b + 220, a + 20, b + 330) line(a + 20, b + 330, a + 40, b + 330) line(a - 20, b + 220, a - 20, b + 330) line(a - 20, b + 330, a - 40, b + 330) # отрисовывает руки : первая строка - правую, а вторая строка - левую; line(a + 12, b + 60, a + 50, b + 100) line(a + 50, b + 100, a + 120, b + 65) line(a - 12, b + 60, a - 82, b + 140)