Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
"""
Draw the grid. Used to draw the falling stones. The board is drawn
by the sprite list.
"""
# Draw the grid
for row in range(len(grid)):
for column in range(len(grid[0])):
# Figure out what color to draw the box
if grid[row][column]:
color = colors[grid[row][column]]
# Do the math to figure out where the box is
x = (MARGIN + WIDTH) * (column + offset_x) + MARGIN + WIDTH // 2
y = SCREEN_HEIGHT - (MARGIN + HEIGHT) * (row + offset_y) + MARGIN + HEIGHT // 2
# Draw the box
arcade.draw_rectangle_filled(x, y, WIDTH, HEIGHT, color)
def draw(self):
""" Draw the button """
arcade.draw_rectangle_filled(self.center_x, self.center_y, self.width,
self.height, self.face_color)
if not self.pressed:
color = self.shadow_color
else:
color = self.highlight_color
# Bottom horizontal
arcade.draw_line(self.center_x - self.width / 2, self.center_y - self.height / 2,
self.center_x + self.width / 2, self.center_y - self.height / 2,
color, self.button_height)
# Right vertical
arcade.draw_line(self.center_x + self.width / 2, self.center_y - self.height / 2,
self.center_x + self.width / 2, self.center_y + self.height / 2,
color, self.button_height)
def draw_pine_tree(position_x, position_y):
"""
This function draws a pine tree.
"""
# Draw the trunk
arcade.draw_rectangle_filled(position_x, position_y + 30, 30, 60, arcade.color.BROWN)
# Draw three levels of triangles
arcade.draw_triangle_filled(position_x - 70, position_y + 60,
position_x + 70, position_y + 60,
position_x, position_y + 150,
arcade.color.FOREST_GREEN)
arcade.draw_triangle_filled(position_x - 70, position_y + 100,
position_x + 70, position_y + 100,
position_x, position_y + 190,
arcade.color.FOREST_GREEN)
arcade.draw_triangle_filled(position_x - 55, position_y + 150,
position_x + 55, position_y + 150,
position_x, position_y + 230,
arcade.color.FOREST_GREEN)
# Draw the origin point, just for reference.
def draw_pine_tree(center_x, center_y):
"""
This function draws a pine tree at the specified location.
Args:
:center_x: x position of the tree center.
:center_y: y position of the tree trunk center.
"""
# Draw the trunk center_x
arcade.draw_rectangle_filled(center_x, center_y, 20, 40, arcade.color.DARK_BROWN)
tree_bottom_y = center_y + 20
# Draw the triangle on top of the trunk
point_list = ((center_x - 40, tree_bottom_y),
(center_x, tree_bottom_y + 100),
(center_x + 40, tree_bottom_y))
arcade.draw_polygon_filled(point_list, arcade.color.DARK_GREEN)
# Bottom half
arcade.draw_lrtb_rectangle_filled(30, 350, 350, 210, arcade.color.BROWN)
# Left-bottom window
arcade.draw_rectangle_filled(70, 260, 30, 40, arcade.color.BONE)
arcade.draw_rectangle_filled(70, 260, 20, 30, arcade.color.BLACK)
# Right-bottom window
arcade.draw_rectangle_filled(310, 260, 30, 40, arcade.color.BONE)
arcade.draw_rectangle_filled(310, 260, 20, 30, arcade.color.BLACK)
# Barn door
arcade.draw_rectangle_filled(190, 230, 100, 100, arcade.color.BLACK_BEAN)
# Rail above the door
arcade.draw_rectangle_filled(190, 280, 180, 5, arcade.color.BONE)
# Draw second level of barn
arcade.draw_polygon_filled([[20, 350],
[100, 470],
[280, 470],
[360, 340]],
arcade.color.BROWN)
# Draw loft of barn
arcade.draw_triangle_filled(100, 470, 280, 470, 190, 500, arcade.color.BROWN)
# Left-top window
arcade.draw_rectangle_filled(130, 440, 30, 40, arcade.color.BONE)
arcade.draw_rectangle_filled(130, 440, 20, 30, arcade.color.BLACK)
# Right-top window
# Barn cement base
arcade.draw_lrtb_rectangle_filled(30, 350, 210, 170, arcade.color.BISQUE)
# Bottom half
arcade.draw_lrtb_rectangle_filled(30, 350, 350, 210, arcade.color.BROWN)
# Left-bottom window
arcade.draw_rectangle_filled(70, 260, 30, 40, arcade.color.BONE)
arcade.draw_rectangle_filled(70, 260, 20, 30, arcade.color.BLACK)
# Right-bottom window
arcade.draw_rectangle_filled(310, 260, 30, 40, arcade.color.BONE)
arcade.draw_rectangle_filled(310, 260, 20, 30, arcade.color.BLACK)
# Barn door
arcade.draw_rectangle_filled(190, 230, 100, 100, arcade.color.BLACK_BEAN)
# Rail above the door
arcade.draw_rectangle_filled(190, 280, 180, 5, arcade.color.BONE)
# Draw second level of barn
arcade.draw_polygon_filled([[20, 350],
[100, 470],
[280, 470],
[360, 340]],
arcade.color.BROWN)
# Draw loft of barn
arcade.draw_triangle_filled(100, 470, 280, 470, 190, 500, arcade.color.BROWN)
# Left-top window
arcade.draw_rectangle_filled(130, 440, 30, 40, arcade.color.BONE)
def draw_section_1():
for row in range(30):
for column in range(30):
x = 0 # Instead of zero, calculate the proper x location using 'column'
y = 0 # Instead of zero, calculate the proper y location using 'row'
arcade.draw_rectangle_filled(x, y, 5, 5, arcade.color.WHITE)
def draw(self):
arcade.draw_rectangle_filled(self.x, self.y, self.width, self.height,
self.color, self.angle)
# --- Draw the barn ---
# Barn cement base
arcade.draw_lrtb_rectangle_filled(30, 350, 210, 170, arcade.color.BISQUE)
# Bottom half
arcade.draw_lrtb_rectangle_filled(30, 350, 350, 210, arcade.color.BROWN)
# Left-bottom window
arcade.draw_rectangle_filled(70, 260, 30, 40, arcade.color.BONE)
arcade.draw_rectangle_filled(70, 260, 20, 30, arcade.color.BLACK)
# Right-bottom window
arcade.draw_rectangle_filled(310, 260, 30, 40, arcade.color.BONE)
arcade.draw_rectangle_filled(310, 260, 20, 30, arcade.color.BLACK)
# Barn door
arcade.draw_rectangle_filled(190, 230, 100, 100, arcade.color.BLACK_BEAN)
# Rail above the door
arcade.draw_rectangle_filled(190, 280, 180, 5, arcade.color.BONE)
# Draw second level of barn
arcade.draw_polygon_filled([[20, 350],
[100, 470],
[280, 470],
[360, 340]],
arcade.color.BROWN)
# Draw loft of barn
arcade.draw_triangle_filled(100, 470, 280, 470, 190, 500, arcade.color.BROWN)
# Draw second level of barn
arcade.draw_polygon_filled([[20, 350],
[100, 470],
[280, 470],
[360, 340]],
arcade.color.BROWN)
# Draw loft of barn
arcade.draw_triangle_filled(100, 470, 280, 470, 190, 500, arcade.color.BROWN)
# Left-top window
arcade.draw_rectangle_filled(130, 440, 30, 40, arcade.color.BONE)
arcade.draw_rectangle_filled(130, 440, 20, 30, arcade.color.BLACK)
# Right-top window
arcade.draw_rectangle_filled(250, 440, 30, 40, arcade.color.BONE)
arcade.draw_rectangle_filled(250, 440, 20, 30, arcade.color.BLACK)
# Draw 2nd level door
arcade.draw_rectangle_outline(190, 310, 30, 60, arcade.color.BONE, 5)
# --- Draw the tractor ---
# Draw the engine
arcade.draw_rectangle_filled(600, 120, 140, 70, arcade.color.GRAY)
arcade.draw_rectangle_filled(590, 105, 90, 40, arcade.color.BLACK)
# Draw the smoke stack
arcade.draw_rectangle_filled(580, 175, 10, 40, arcade.color.BLACK)
# Back wheel
arcade.draw_circle_filled(490, 110, 50, arcade.color.BLACK)