# Display the art image plt.imshow(canvas) plt.axis(‘off’) plt.show()
Here’s a line-by-line explanation of the code:
import numpy as np: This line imports the NumPy library, which is used for working with arrays, and renames it to np for convenience.
import matplotlib.pyplot as plt: This line imports the pyplot module from the matplotlib library, which is used for creating plots and visualizations, and renames it to plt for convenience.
canvas = np.zeros((200, 200, 3), dtype=np.uint8): This line creates a 200x200 pixel canvas (image) with 3 color channels (RGB) and sets all pixel values to 0 (black).
canvas[:, :, :] = [0, 0, 0]: This line sets the color of the entire canvas to black (all pixel values are set to 0).
center_x, center_y = 100, 100: These lines define the center coordinates of a circle that will be drawn on the canvas.
radius = 50: This line defines the radius of the circle that will be drawn on the canvas.
canvas[center_y-radius:center_y+radius, center_x-radius:center_x+radius, 0] = 255: This line sets the red color channel of all pixels within the circle to 255 (maximum value), creating a red circle on the canvas.
canvas[center_y-radius:center_y+radius, center_x-radius:center_x+radius, 1] = 0: This line sets the green color channel of all pixels within the circle to 0 (minimum value).
canvas[center_y-radius:center_y+radius, center_x-radius:center_x+radius, 2] = 0: This line sets the blue color channel of all pixels within the circle to 0 (minimum value).
canvas[50:150, 20:80, 0] = 0: These lines draw a green rectangle on the canvas by setting the red and blue color channels of all pixels within the rectangle to 0 and setting the green color channel to 255 (maximum value).
canvas[50:150, 20:80, 1] = 255:
canvas[50:150, 20:80, 2] = 0:
triangle_coords = np.array([(100, 10), (80, 60), (120, 60)]): These lines draw a blue triangle on the canvas by defining the coordinates of its vertices and creating a mask that selects all pixels within the triangle.
canvas[triangle_mask, 0] = 0: These lines set the red and green color channels of all pixels within the triangle to 0 and set the blue color channel to 255 (maximum value), creating a blue triangle on the canvas.
canvas[triangle_mask, 1] = 0:
canvas[triangle_mask, 2] = 255:
plt.imshow(canvas): This line displays the final image (art) created on the canvas using Matplotlib’s imshow function.
plt.axis(‘off’): This line turns off axis lines and labels in the plot.
plt.show(): This line displays the plot.
Hope My explanation was satisfying to you .
Thank You for giving your precious time for stopping by and reading this blog