Skip to content

a web app to generate lego art base on existing sets

Notifications You must be signed in to change notification settings

BIueMan/Lego-Art-Generator

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

23 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Lego Art Creator

This project main idea is to take any image and create a lego-art instraction of how to build it. it allow the user to specify the size of the wanted lego-art, and the number the code can use to create the iamge.

Full Image Lenna

How to Use

Run the program using the following command:

python main.py

Setting Input Parameters

Modify the main.py file to set the input parameters:

if __name__ == "__main__":
    image_path = "Data/Lenna.png"  # Set the path to the input image
    size = [4, 4]  # Set the size of each block (e.g., 4x4)
    k_mean = 9  # Set the number of dominant colors
    main(image_path, size, k_mean)
  • image_path: Path to the input image.
  • size: Size of each block in the output Lego art, specified as a list [width, height].
  • k_mean: Number of dominant colors to be detected using k-means clustering.

Program Workflow

The program follows these steps:

  1. Pixelation: The input image is pixelated to the specified size (a multiple of 16x16).
  2. K-means Clustering: The program uses k-means clustering to find the k most dominant colors in the pixelated image.
  3. Color Selection: The user is presented with a Pygame window where they can adjust the selected colors generated by k-means clustering. Once satisfied, the user closes the window.
  4. Lego Color Assignment: Another Pygame window opens where the user can manually select Lego colors for each dominant color detected in the image.
  5. update - personal touch: Let the user to change every pixel in the image, before PDF creation
  6. PDF Creation: Finally, the program generates a PDF instruction for the Lego art and saves it in the output/ directory.
0 1 2 3

personal touch

here, i have used the personal touch to add the mouth, fix heart and shadow

with out with

Explanation of Functions

Here's an explanation of the functions used in the program:

From math_function.clustering

  • get_kmean_color: This function performs k-means clustering on the pixelated image to find the k most dominant colors.
  • cluster_points: This function assigns each pixel to its nearest cluster center.

From generate_pdf_func

  • create_pdf_from_directory: This function creates a PDF instruction from the images saved in a directory.
  • generate_pixel_images: This function generates pixelated images from the input image.
  • run_app: This function handles the Pygame application for color selection and Lego color assignment.

From personal_touch

  • personal_touch: This function help you added final personal touch to the image, before pdf is generated

Enjoy creating Lego art from your favorite images! 🎨🧱

About

a web app to generate lego art base on existing sets

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages