Skip to content

About

๐Ÿงฉ Interactive swap-tile puzzle game that transforms any image into a customizable brain-teaser. Race against the clock with 4-32 pieces, track your moves, and enjoy visual feedback.

Topics

Resources

Stars

1 star

Watchers

0 watching

Forks

Latest commit

ย 

History

7 Commits

Folders and files

NameName
Last commit message
Last commit date
ย 
ย 
ย 
ย 

Repository files navigation

๐Ÿงฉ Puzzlify โ€“ Image Puzzle Tool

Python Pillow License Tkinter

Puzzlify transforms any image into an interactive swap-tile puzzle. Load your favorite photo, scramble the pieces, and race against the clock to restore the original image. Perfect for brain training or just relaxing with a visual challenge.


โœจ Features

Category Description
๐Ÿ“ธ Image Loading Load any common image format (JPG, PNG, BMP, GIF, WebP, TIFF)
๐Ÿงฉ Flexible Grids Choose from 9 piece counts: 4, 6, 8, 9, 12, 16, 20, 25, or 32 pieces
๐ŸŽฎ Intuitive Controls Click a tile to select โ†’ click another to swap
โฑ๏ธ Stats Tracking Real-time timer and move counter during gameplay
๐ŸŽจ Visual Feedback Orange highlight for selected tiles, green outline for correct placements
๐Ÿ”„ Game Controls Shuffle & Start, Reset, and Solve (instant completion)
๐Ÿ–ผ๏ธ Thumbnail Preview See your loaded image in the left panel
๐Ÿ’ป Lightweight Pure Python with Tkinter + Pillow โ€“ no heavy dependencies

๐Ÿš€ Quick Start

Prerequisites

  • Python 3.8 or higher
  • Pillow library for image processing

Installation

# Clone the repository
git clone https://github.com/yourusername/puzzlify.git
cd puzzlify

# Install dependencies
pip install Pillow

# Run the game
python puzzle_tool.py

Note: Tkinter is included with Python on Windows and macOS.
On Linux, install it with: sudo apt-get install python3-tk


๐ŸŽฎ How to Play

  1. Load an Image
    Click [ LOAD IMAGE ] and select any photo from your computer.

  2. Choose Difficulty
    Select the number of puzzle pieces (more pieces = harder puzzle).

  3. Shuffle & Start
    Click [ SHUFFLE & START ] to scramble the tiles and begin the timer.

  4. Swap Tiles

    • Click a tile to select it (orange border appears)
    • Click another tile to swap positions
    • Continue until the image is fully restored
  5. Win!
    When all tiles are in place, a victory overlay appears with your final stats.

Additional Controls

Button Function
RESET Restores the puzzle to the solved state (keeps current image)
SOLVE Instantly completes the puzzle (useful for seeing the final image)

๐Ÿง  Technical Deep Dive

Image Processing Pipeline

Original Image โ†’ Crop to Aspect Ratio โ†’ Resize to Board (520ร—520) 
โ†’ Calculate Optimal Grid (cols ร— rows) โ†’ Slice into Pieces 
โ†’ Store in Memory โ†’ Display on Canvas

Grid Calculation Logic

The tool automatically determines the optimal grid layout to be as square as possible while exactly matching the chosen piece count:

def get_grid(n):
    """Returns (cols, rows) for n pieces โ€” closest to square, wider than tall."""
    best = (n, 1)
    best_diff = n - 1
    for c in range(2, n + 1):
        if n % c == 0:
            r = n // c
            diff = abs(c - r)
            if diff < best_diff or (diff == best_diff and c >= r):
                best_diff = diff
                best = (c, r)
    cols, rows = best
    if cols < rows:
        cols, rows = rows, cols
    return cols, rows

Swap & Solve Mechanics

  • Swap Algorithm: Two tiles exchange positions in the order list; each swap increments the move counter
  • Win Detection: Puzzle is solved when order == [0, 1, 2, ..., n-1]
  • Timer: Real-time tracking that stops automatically on solution

UI Architecture

  • Left Panel: Controls, image preview, stats, and instructions
  • Right Panel: Interactive canvas displaying the puzzle grid
  • Theme: Custom dark color scheme with accent colors for better visibility
  • Responsive: Automatically adjusts piece dimensions based on grid size

๐Ÿ“ Project Structure

puzzlify/
โ”œโ”€โ”€ puzzle_tool.py          # Main application (800+ lines of code)
โ”œโ”€โ”€ demo1.png               # Start screen screenshot
โ”œโ”€โ”€ demo2.png               # Loaded image screenshot  
โ”œโ”€โ”€ demo3.png               # Active gameplay screenshot
โ”œโ”€โ”€ README.md               # This file
โ””โ”€โ”€ LICENSE                 # MIT License

๐Ÿ› ๏ธ Built With


๐ŸŽฏ Future Roadmap

  • Save/Load State โ€“ Resume puzzles later
  • Difficulty Modes โ€“ Limited moves, timed challenges
  • Animations โ€“ Smooth tile swaps and transitions
  • Sound Effects โ€“ Feedback sounds for swaps and solves
  • Leaderboard โ€“ Track best times locally
  • Custom Themes โ€“ Multiple color schemes
  • Keyboard Shortcuts โ€“ Faster navigation

๐Ÿค Contributing

Contributions are welcome! Whether it's:

  • ๐Ÿ› Bug reports
  • ๐Ÿ’ก Feature suggestions
  • ๐Ÿ“ Documentation improvements
  • ๐Ÿ”ง Pull requests

Please open an issue first to discuss what you'd like to change.


๐Ÿ“„ License

This project is licensed under the MIT License โ€“ see the LICENSE file for details.


๐Ÿ‘จโ€๐Ÿ’ป Author

KAZIM KHAN


๐Ÿ™ Acknowledgments

  • Inspired by classic sliding puzzles and modern brain training apps
  • Built with Python's excellent Tkinter and Pillow libraries
  • Special thanks to the open-source community

โญ Show Your Support

If you found this project useful, please give it a star โญ on GitHub!
It helps others discover the project and motivates further development.


Made with ๐Ÿงฉ and โ˜•

About

๐Ÿงฉ Interactive swap-tile puzzle game that transforms any image into a customizable brain-teaser. Race against the clock with 4-32 pieces, track your moves, and enjoy visual feedback.

Topics

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages