from PIL import Image, ImageDraw
# ASCII art
ascii_art = [
".............",
".#####.......",
".#####.......",
".............",
".............",
".....##......",
"...#######...",
"...#######...",
"...#...#.....",
"...#...#.....",
"...#####.....",
"...#####.....",
"............."
]
# Parameters
shape = "circle" # Available shapes: "circle", "square", "triangle"
blur_radius = 2
threshold = 128
# Compute image dimensions
art_width = len(ascii_art[0])
art_height = len(ascii_art)
image_width = art_width * 10 # Each ASCII character is 10 pixels wide
image_height = art_height * 10 # Each ASCII character is 10 pixels tall
# Convert ASCII art to shape pixels
pixels = []
for row in ascii_art:
for char in row:
char_pixels = []
if char == '#':
if shape == "circle":
char_pixels = [(x, y) for x in range(10) for y in range(10) if (x - 5) ** 2 + (y - 5) ** 2 <= 25]
elif shape == "square":
char_pixels = [(x, y) for x in range(10) for y in range(10)]
elif shape == "triangle":
char_pixels = [(x, y) for x in range(10) for y in range(10) if y >= 10 - x]
pixels.extend([(coord[0] + x, coord[1] + y) for coord in char_pixels for x in range(art_width) for y in range(art_height)])
# Create image with white background
image = Image.new("L", (image_width, image_height), (255))
# Draw shape pixels
draw = ImageDraw.Draw(image)
for pixel in pixels:
draw.point(pixel, fill=0)
# Blur image
blurred_image = image.filter(ImageFilter.GaussianBlur(radius=blur_radius))
# Apply threshold
thresholded_image = blurred_image.point(lambda x: 0 if x < threshold else 255, "L")
# Display image
thresholded_image.show()
In this example, the program takes an ASCII art representation (stored in the ascii_art list). You can change the ASCII art to any other shape you want. It then converts the ASCII art into shape pixels based on the selected shape (circle, square, or triangle), blurs the image with the chosen radius, and applies a threshold to create the final image.