import numpy as np
import matplotlib.pyplot as plt

# Define the dimensions of the trapezoid
base1 = 5
base2 = 3
height = 4

# Calculate the width of the rectangle that can be cut from each side of the trapezoid
rect_width = (base1 + base2) / 2

# Cut off two rectangles from the trapezoid
trap_points = np.array([[0, 0], [base1, 0], [base1, height], [0, height]])
rect_points = np.array([[0, 0], [rect_width, 0], [rect_width, height], [0, height]])
trap_cut_points = np.array([[rect_width, 0], [base2, 0], [base2, height], [rect_width, height]])

# Plot the original trapezoid and cut off rectangles
plt.fill(trap_points[:, 0], trap_points[:, 1], color='gray')
plt.fill(rect_points[:, 0], rect_points[:, 1], color='blue')
plt.fill(trap_cut_points[:, 0], trap_cut_points[:, 1], color='blue')

# Calculate the size of the remaining triangle
triangle_width = base2 - rect_width
triangle_height = (base2 * height) / base1

# Cut off the triangle from the trapezoid
tri_points = np.array([[rect_width, 0], [base2, 0], [(base2 + rect_width) / 2, height]])
tri_cut_points = np.array([[(base2 + rect_width) / 2, 0], [(base2 + rect_width) / 2, triangle_height], [rect_width, triangle_height]])

# Plot the remaining triangle and cut off triangles
plt.fill(tri_points[:, 0], tri_points[:, 1], color='green')
plt.fill(tri_cut_points[:, 0], tri_cut_points[:, 1], color='green')

# Calculate the size of the small squares
small_square_size = min(rect_width, triangle_height) / 2

# Cut off the small squares from the rectangle and triangle
rect_small_squares_points = np.array([[0, 0], [small_square_size, 0], [small_square_size, small_square_size], [0, small_square_size]])
tri_small_squares_points = np.array([[(base2 + rect_width) / 2 - small_square_size, small_square_size], [(base2 + rect_width) / 2, 0], [(base2 + rect_width) / 2 - small_square_size, 0]])

# Plot the small squares
plt.fill(rect_small_squares_points[:, 0], rect_small_squares_points[:, 1], color='red')
plt.fill(tri_small_squares_points[:, 0], tri_small_squares_points[:, 1], color='red')

# Show the plot
plt.axis('scaled')
plt.show()
