Code Monkey home page Code Monkey logo

wave-function-collapse's Introduction

wave-function-collapse

Wave function collapse python implementation. It supports 1D, 2D, 3D samples.

wfc_example

Installation

pip install -r requirements.txt

py-vox-io is used to load magica voxel file to numpy array.

Usage

See main.py for usage example.

Examples

Midi file

See examples/midi.py

Voxel

See examples/voxel.py

wfc_example

wave-function-collapse's People

Contributors

coac avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

wave-function-collapse's Issues

Question: regarding multiprocessing

As far as i understand you are using pool in the Propagator to compute the possible legal patterns out of all patterns and offsets.

patterns_compatibility = pool.starmap( self.legal_patterns, patterns_offsets) pool.close() pool.join()

For an experiment I am trying to run wfc without pool. Is it possible to rewrite this statement to run in a single thread? At this point i do not understand what legal_patterns() expects me to provide. Thanks in advance.

Understanding the "Propagation" step

Dear @Coac ,

Thank you for this clear, pythonic and efficient port of the original C# script. I learned a lot from reading it.

A point is still obscure to me, during propagation:

  • Why are you starting to iterate over the neighbors of the neighbors of the collapsed cell ?
    (Every other implementation start by iterating over the 4 direct nighbors of the collapsed cell, not the neighbors of its neighbors)

  • Are you iterating over neighbors that have been collapsed as well ? (updating collapsed cell ?)

  • What happens when you remove the last available pattern of a cell (line 62 of propagator.py) ? (How do you handle cells with 0 patterns left ? Normally, this should throw an error)

In other words:

def propagate(cell):
        to_update = [neighbour for neighbour, _ in cell.get_neighbors()] 

       # Why putting the neighbors of the collapsed cell in the stack ?
       # Other implementations put the collapsed cell in the stack, then iterate over its neighbors

        while len(to_update) > 0:
            cell = to_update.pop(0)
            for neighbour, offset in cell.get_neighbors():

                # Usually, other implementations have an "if" statement here: "if neighbour is not collapsed:"

                for pattern_index in cell.allowed_patterns:
                    pattern = Pattern.from_index(pattern_index)
                    pattern_still_compatible = False
                    for neighbour_pattern_index in neighbour.allowed_patterns:
                        neighbour_pattern = Pattern.from_index(neighbour_pattern_index)

                        if pattern.is_compatible(neighbour_pattern, offset):
                            pattern_still_compatible = True
                            break

                    if not pattern_still_compatible:
                        cell.allowed_patterns.remove(pattern_index)  
               
                       # What happens if the cell has now 0 pattern available because of this removal ?

                        for neigh, _ in cell.get_neighbors():
                            if neigh not in to_update:
                                to_update.append(neigh)

                               # Also, what happens if you put in the stack a neighbor that a has been collapsed ?

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.