Giter Site home page Giter Site logo

wave_function_collapse's Introduction

Wave Function Collapse (WFC) Algorithm

This is an implementation of the Wave Function Collapse (WFC) algorithm in Python, based on the first half of Daniel Shiffman's video tutorial on the subject (https://youtu.be/rI_y2GAlQFM).

example of tileset2

Description

The Wave Function Collapse algorithm is used to generate tile-based patterns by propagating constraints through a grid of cells. Each cell has a set of possible tile states, and the algorithm collapses cells by eliminating incompatible states based on neighboring cells. The process continues until either all cells have collapsed or contradictions arise.

This implementation uses the Pygame library to provide a graphical representation of the generated patterns. The grid is displayed on a window, and the tiles are rendered as images.

Dependencies

This program requires the following dependencies:

  • Python 3.x
  • Pygame

How to Run

  1. Make sure you have Python and Pygame installed on your system.
  2. Clone or download the code files to your local machine.
  3. Open a terminal or command prompt and navigate to the directory containing the code files.
  4. Run the following command to execute the program:
    python main.py
    
  5. The generated patterns will be displayed in the Pygame window.
  6. Upon completion a clean screenshot of the result will be saved to the output folder and the time taken to generate will be displayed on the center of the screen.

Controls

  • Press the Spacebar to reset the board and generate a new pattern.
  • Press Escape or close the window to exit the program.

Customization

You can customize the following parameters in the main.py file:

  • debug_mode: Set to True to display possible tile states.
  • grid_size: The size of the grid (number of cells per row and column).
  • tileset: a string, the name of the tileset folder
  • weights: weights to use when selecting a random tile

License

This project is provided without any specific license. You are free to use and modify the code for personal or educational purposes. However, please refer to the licenses of the dependencies (if any) for their usage terms.

example of tileset2 example of tileset2 example of tileset2 example of tileset2

wave_function_collapse's People

Contributors

robthedudeyo avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.