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)
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)
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 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)
def quadrant(x, y, radius): graph.penSize(0) graph.brushColor("brown") graph.circle(x, y, radius) graph.brushColor("blue") graph.rectangle(x - radius, y - radius, x, y) graph.rectangle(x, y - radius, x + radius + 1, y + radius + 1)
def mast(x, y, deck_lenght, carcass_height): """ Рисует мачту. (x, y) -- координаты правой верхней точки прямоугольника-палубы. deck_lenght, carcass_height -- длина прямоугольника-палубы и высота корпуса. """ graph.brushColor('black') graph.rectangle(x + deck_lenght/3, y, x + 0.03*deck_lenght +deck_lenght/3, y - 2.5*carcass_height)
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 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)
def sky(x, y): """ Рисует небо. (x, y) -- координаты левой верхней точки прямоугольника-неба. """ graph.brushColor(173, 216, 230) graph.penSize(0) graph.rectangle(0, 0, x + 800, y + 330)
def sea(x, y): """ Рисует море. (x, y) -- координаты левой верхней точки прямоугольника-моря. """ graph.brushColor(30, 144, 255) graph.penSize(0) graph.rectangle(x, y, x + 800, y + 120)
def beach(x, y): """ Рисует песчаный пляж. (x, y) -- координаты левой верхней точки прямоугольника-пляжа. """ graph.brushColor('yellow') graph.penSize(0) graph.rectangle(x, y, x + 800, y + 150)
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 background(xmax, ymax, middle): """Setting background for the picture. xmax, ymax - size of the window middle - middle point for separation""" graph.brushColor(85, 70, 0) graph.rectangle(0, 0, xmax, middle) graph.brushColor(125, 100, 0) graph.rectangle(0, middle, xmax, ymax)
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)
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 tree(bottom_tree_x, bottom_tree_y, barrel_length): """ bottom_tree_x and bottom_tree_y -- центральные координаты низа дерева. barrel_length -- высота дерева barrel_lengt/8 -- ширина этого дерева У всех шариков радиусы barrel_length/4 Центры двух нижних шариков находятся на той же выстое, что и макушка дерева, и они на расстоянии barrel_length/4 от центральной оси симметрии. Их координаты: левая: (bottom_tree_x - barrel_length/4, bottom_tree_y - barrel_length) правая -- (bottom_tree_x + barrel_length/4, bottom_tree_y - barrel_length) Третий шарик считая снизу выше макушки дерева на barrel_length/5 Он находится по центру координата x -- bottom_tree_x координата y -- bottom_tree_y - 6/5 * barrel_length) Четвёртый и пятый шарик считая снизу выше маушки дерева на barrel_length/3, и они на расстоянии barrel_length/3 от центральной оси симметрии левый шарик: координата x -- bottom_tree_x - barrel_length/3 кооридината y -- bottom_tree_y - 4/3 * barrel_length) правый шарик: координата x -- bottom_tree_x + barrel_length/3, координата y -- bottom_tree_y - 4/3 * barrel_length) Наивысшый шарик выше макушки дерева на 4/7*barrel_length, и он расположен по центру координата x -- bottom_tree_x координата y -- bottom_tree_y - 27 / 17 * barrel_length), barrel_length/4) """ # barrel graph.penColor("black") graph.brushColor("black") graph.rectangle(bottom_tree_x - barrel_length / 16, bottom_tree_y, bottom_tree_x + barrel_length / 16, bottom_tree_y - barrel_length) # leaves graph.penSize(1) graph.penColor("black") graph.brushColor("green") graph.circle(bottom_tree_x, bottom_tree_y - 27 / 17 * barrel_length, barrel_length / 4) graph.circle(bottom_tree_x - barrel_length/3, bottom_tree_y - (barrel_length + barrel_length/3), barrel_length/4) graph.circle(bottom_tree_x + barrel_length/3, bottom_tree_y - (barrel_length + barrel_length/3), barrel_length/4) graph.circle(bottom_tree_x, bottom_tree_y - (barrel_length + barrel_length/5), barrel_length/4) graph.circle(bottom_tree_x - barrel_length/4, bottom_tree_y - barrel_length, barrel_length/4) graph.circle(bottom_tree_x + barrel_length/4, bottom_tree_y - barrel_length, barrel_length/4)
def backstage(): penColor(255, 204, 153) brushColor(255, 204, 153) rectangle(0, 0, 1000, 100) penColor(255, 229, 204) brushColor(255, 229, 204) polygon([(0, 100), (1000, 100), (1000, 215), (0, 200)]) penColor(255, 255, 153) brushColor(255, 255, 153) polygon([(0, 200), (1000, 215), (1000, 300), (0, 350)]) penColor(188, 143, 143) brushColor(188, 143, 143) polygon([(0, 350), (1000, 300), (1000, 500), (0, 500)])
def the_wallpaper(r0, g0, b0): # making an array of RGB per square 2x2 # the RGB is the mean of upper-left and upper-right neighbor +- random # to make horizontal clusters that look like waves # instead of diagonally clusters when going by lines rgb_array = [[0] * 500 for k in range(500)] for diagonal_number in range(1000): if diagonal_number > 499: number_of_lines_in_the_diagonal = 499 - (diagonal_number - 499) else: number_of_lines_in_the_diagonal = diagonal_number for almost_y in range(number_of_lines_in_the_diagonal, -1, -1): if diagonal_number > 499: x = diagonal_number - 499 +\ number_of_lines_in_the_diagonal - almost_y y = (499 - number_of_lines_in_the_diagonal) + almost_y else: x = diagonal_number - almost_y y = almost_y # for the first column and line just making them standard if x == 0: R, G, B = r0, g0, b0 elif y == 499 or y == 0: R, G, B = r0, g0, b0 else: R = (rgb_array[x - 1][y - 1][0] + rgb_array[x - 1][y + 1][0]) // 2 G = (rgb_array[x - 1][y - 1][1] + rgb_array[x - 1][y + 1][1]) // 2 B = (rgb_array[x - 1][y - 1][2] + rgb_array[x - 1][y + 1][2]) // 2 R += randint(-10, 10) G += randint(-10, 10) B += randint(-10, 10) R, G, B = whether_matches_rgb(R, G, B, 10, 60) rgb_array[x][y] = [R, G, B] # drawing the square brushColor(R, G, B) penColor(R, G, B) rectangle(2 * x, 2 * y, 2 * x + 2, 2 * y + 2)
def backgroung(length_sky): """ Эта функция берёт длинну неба и заполняет остальное пространство кроме неба травой. Также она отвечает за ширину и высоту экрана """ main_screen_width = 1600 main_screen_height = 1000 graph.windowSize(main_screen_width, main_screen_height) graph.penSize(0) graph.brushColor("skyblue") graph.rectangle(0, 0, main_screen_width, length_sky) graph.brushColor("limegreen") graph.rectangle(0, length_sky, main_screen_width, main_screen_height)
def window(x0, y0, size): # x0, y0 are top left corner coordinates """back""" graph.brushColor("#D1FFEB") graph.rectangle(x0, y0, x0 + 320 * size, y0 + 450 * size) """front""" graph.brushColor("#87CDDE") graph.rectangle(x0 + 20 * size, y0 + 20 * size, x0 + 150 * size, y0 + 220 * size) graph.brushColor("#87CDDE") graph.rectangle(x0 + 170 * size, y0 + 20 * size, x0 + 300 * size, y0 + 220 * size) rectangle_1 = graph.rectangle(x0 + 20 * size, y0 + 20 * size, x0 + 150 * size, y0 + 220 * size) graph.moveObjectBy(rectangle_1, 0, 220 * size) rectangle_2 = graph.rectangle(x0 + 170 * size, y0 + 20 * size, x0 + 300 * size, y0 + 220 * size) graph.moveObjectBy(rectangle_2, 0, 220 * size)
def window(x1, y1, x2, y2): penColor(255, 255, 255) brushColor(255, 255, 255) rectangle(x1, y1, x2, y2) penColor(0, 231, 255) brushColor(141, 207, 255) rectangle(0.95 * x1 + 0.05 * x2, 0.95 * y1 + 0.05 * y2, 0.55 * x1 + 0.45 * x2, 0.75 * y1 + 0.25 * y2) rectangle(0.45 * x1 + 0.55 * x2, 0.95 * y1 + 0.05 * y2, 0.05 * x1 + 0.95 * x2, 0.75 * y1 + 0.25 * y2) rectangle(0.95 * x1 + 0.05 * x2, 0.67 * y1 + 0.33 * y2, 0.55 * x1 + 0.45 * x2, 0.05 * y1 + 0.95 * y2) rectangle(0.45 * x1 + 0.55 * x2, 0.67 * y1 + 0.33 * y2, 0.05 * x1 + 0.95 * x2, 0.05 * y1 + 0.95 * y2)
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 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 carcass(x, y, deck_lenght, carcass_height): """ Рисует корпус корабля. (x, y) -- координаты правой верхней точки прямоугольника-палубы. deck_lenght, carcass_height -- длина прямоугольника-палубы и высота корпуса. """ graph.brushColor(139, 69, 19) graph.penSize(0) graph.rectangle(x, y, x + deck_lenght, y + carcass_height) graph.brushColor(139, 69, 19) graph.penSize(0) graph.polygon([(x + deck_lenght, y), (x + deck_lenght, y + carcass_height), (x + 1.5*deck_lenght, y), (x + deck_lenght, y)]) graph.brushColor(139, 69, 19) graph.penSize(0) graph.arc(x + carcass_height, y - carcass_height, x - carcass_height, y + carcass_height, -180, -90) graph.brushColor('black') graph.circle(x + 1.1*deck_lenght, y + 0.4*carcass_height, carcass_height/4.5) graph.brushColor('white') graph.circle(x + 1.1 * deck_lenght, y + 0.4 * carcass_height, carcass_height / 6.5)
def home(center_x, center_y, side_length): # side graph.penSize(1) graph.penColor("black") graph.brushColor("peru") graph.rectangle(center_x - side_length / 2, center_y + side_length / 2, center_x + side_length / 2, center_y - side_length / 2) # window graph.penColor("red") graph.brushColor("aqua") graph.rectangle(center_x - side_length / 8, center_y + side_length / 8, center_x + side_length / 8, center_y - side_length / 8) # roof graph.penColor("black") graph.brushColor("red") graph.polygon([(center_x + side_length / 2, center_y - side_length / 2), (center_x - side_length / 2, center_y - side_length / 2), (center_x, center_y - side_length), (center_x + side_length / 2, center_y - side_length / 2)])
def umbrella(x, y, s): graph.penColor('#e38219') graph.brushColor('#e38219') d_stolbik = 0.01 * d * s h_stolbik = 0.43 * h * s d_zont = 3 / 24 * d * s h_zont = 3 / 49 * h * s graph.rectangle(x, y, x + d_stolbik, y + h_stolbik) graph.penColor('#f45151') graph.brushColor('#f45151') graph.polygon([(x, y), (x - d_zont, y + h_zont), (x, y + h_zont), (x, y)]) graph.rectangle(x, y, x + d_stolbik, y + h_zont) graph.polygon([(x + d_stolbik, y), (x + d_stolbik + d_zont, y + h_zont), (x + d_stolbik, y + h_zont), (x + d_stolbik, y)]) graph.penColor('#000000') graph.line(x, y, x - 0.1 * d_zont, y + h_zont) graph.line(x, y, x - 0.4 * d_zont, y + h_zont) graph.line(x, y, x - 0.7 * d_zont, y + h_zont) graph.line(x + d_stolbik, y, x + d_stolbik + 0.1 * d_zont, y + h_zont) graph.line(x + d_stolbik, y, x + d_stolbik + 0.4 * d_zont, y + h_zont) graph.line(x + d_stolbik, y, x + d_stolbik + 0.7 * d_zont, y + h_zont)
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)
def paint_window(x, y, window_width, window_height, window_color_1, window_color_2): penColor(window_color_1) brushColor(window_color_1) rectangle(x, y, (x + window_width), (y + window_height)) penColor(window_color_2) brushColor(window_color_2) rectangle((x + window_width / 10), (y + window_height / 10), (x + window_width - window_width / 10), \ (y + window_height - window_height / 10)) penColor(window_color_1) brushColor(window_color_1) rectangle(x, (y + window_height / 3), (x + window_width), (y + window_height / 3 + window_height / 10)) rectangle((x + window_width / 2 - window_width / 20), y, (x + window_width / 2 + window_width / 20), (y + window_height))
def yacht(x, y, s): # Enter x, y - mast base coordinates, s - size (1>2>...). mast = 230 / s w = 60 / s bow = 100 / s col = 5 / s # col is the mast column width. # Draws mast. penSize(w / 5) penColor('black') moveTo(x, y) # Draws sail. penColor('white') brushColor(230, 230, 250) polygon([(x + col, y - mast), (x + col + bow, y - mast / 2), (x + col + bow / 4, y - mast / 2)]) polygon([(x + col, y), (x + col + bow, y - mast / 2), (x + col + bow / 4, y - mast / 2)]) # Draws boat. brushColor(170, 102, 0) penColor(170, 102, 0) rectangle(x - mast / 2, y, x + mast / 2, y + w) polygon([(x + mast / 2, y), (x + mast / 2 + bow, y), (x + mast / 2, y + w)]) for i in range(100): phi1 = i * pi / 200 phi2 = (i + 1) * pi / 200 polygon([(x - mast / 2 - w * cos(phi1), y + w * sin(phi1)), (x - mast / 2 - w * cos(phi2), y + w * sin(phi2)), (x - mast / 2, y)]) # Drwas window. penSize(0) brushColor('black') circle(x + mast / 2 + bow / 4, y + w / 3, w / 4) brushColor('white') circle(x + mast / 2 + bow / 4, y + w / 3, w / 6)
def ship(x, y, s): a = [] r = 1 / 30 * d * s h_m = 0.005 * d * s a.append( c.create_arc(x - r, y - r, x + r, y + r, start=180, extent=90, fill='#ba5005')) graph.penColor('#000000') graph.brushColor('#ba5005') a.append(graph.rectangle(x, y, x + 4 * r, y + r)) a.append( graph.polygon([(x + 4 * r, y), (x + 6 * r, y), (x + 4 * r, y + r), (x + 4 * r, y)])) graph.brushColor('#000000') a.append(graph.rectangle(x + 1.5 * r, y, x + 1.5 * r + h_m, y - 3 * r)) graph.brushColor('#ded599') a.append( graph.polygon([(x + 1.5 * r + h_m, y - 3 * r), (x + 2 * r + h_m, y - 1.5 * r), (x + 3 * r + h_m, y - 1.5 * r), (x + 1.5 * r + h_m, y - 3 * r)])) a.append( graph.polygon([(x + 1.5 * r + h_m, y), (x + 2 * r + h_m, y - 1.5 * r), (x + 3 * r + h_m, y - 1.5 * r), (x + 1.5 * r + h_m, y)])) graph.brushColor('#000000') a.append(graph.circle(x + 13 / 3 * r, y + 1 / 3 * r, 1 / 4 * r)) graph.brushColor('#ffffff') a.append(graph.circle(x + 13 / 3 * r, y + 1 / 3 * r, 1 / 5 * r)) return a