Coding project for creative purposes utilizing Python and the PIL library.
While working at YVA Arquitetura, the office was commissioned to design a unique bathroom tile layout for a residential project. The clients selected three tile models inspired by the renowned artist Athos Bulcao and requested a randomized mosaic that creatively incorporated these tiles.
To meet this request, I developed a Python script that generates randomized tile mosaic simulations. The code uses the Pillow library to arrange and rotate the chosen tile images within a defined grid, adding realistic grout spacing between tiles. Each simulation presents a different combination, helping the client visualize various layout possibilities before final selection.
I structured the code by combining my own research with support from ChatGPT, allowing me to quickly prototype and refine the solution based on project needs.
Utilized Tiles
Generated Mosaic
3D Renderings
Code
# Importing libraries
import random
from PIL import Image
# Variables
tile_size = 124 # Tile size
grout_width = 4 # Grout width
tiles_x = 20 # Number of tiles in the X direction
tiles_y = 11 # Number of tiles in the Y direction
simulations = 10 # Number of simulations to be generated
grout_color = (200, 200, 200) # Grout color (RGB)
# Base path
base_path = r"C:\\Users\\User\\OneDrive\\Desktop\\Tile Mosaic"
# File paths
tile_paths = [
f"{base_path}\\1.jpg",
f"{base_path}\\2.jpg",
f"{base_path}\\3.jpg"
]
# Create tile mosaic
mosaic_width = (tiles_x * tile_size) + ((tiles_x - 1) * grout_width)
mosaic_height = (tiles_y * tile_size) + ((tiles_y - 1) * grout_width)
tiles = [Image.open(path).resize((tile_size, tile_size)) for path in tile_paths]
def create_mosaic():
mosaic = Image.new('RGB', (mosaic_width, mosaic_height), color=grout_color)
for y in range(tiles_y):
for x in range(tiles_x):
tile = random.choice(tiles).rotate(random.choice([0, 90, 180, 270]))
pos_x = x * (tile_size + grout_width)
pos_y = y * (tile_size + grout_width)
mosaic.paste(tile, (pos_x, pos_y))
return mosaic
for i in range(simulations):
mosaic = create_mosaic()
mosaic.save(f"{base_path}\\mosaic_{i+1}.jpg")
print(f"Simulation {i+1} saved successfully.")