All Projects → krychu → wfc

krychu / wfc

Licence: other
Wave Function Collapse library in C, plus a command-line tool

Programming Languages

c
50402 projects - #5 most used programming language
Makefile
30231 projects

Projects that are alternatives of or similar to wfc

world
This is a fantasy world generation API and set of Go packages for the same.
Stars: ✭ 42 (-86.75%)
Mutual labels:  procedural-generation, procgen
Godot-ProcGen-Dungeon-Generator
A simple Dungeon Procedural Generator using Godot.
Stars: ✭ 24 (-92.43%)
Mutual labels:  procedural-generation, procgen
wfc
Go port of the Wave Function Collapse algorithm
Stars: ✭ 47 (-85.17%)
Mutual labels:  procedural-generation, wfc
waveFunctionCollapse
C implementation of Maxim Gumin's wave function algorithm done as a part of our C project at Imperial
Stars: ✭ 26 (-91.8%)
Mutual labels:  procedural-generation, wfc
Wavefunctioncollapse
Bitmap & tilemap generation from a single example with the help of ideas from quantum mechanics
Stars: ✭ 17,156 (+5311.99%)
Mutual labels:  procedural-generation, wfc
Procedural Worlds Editor
Procedural World Editor is a node based procedural terrain generator
Stars: ✭ 218 (-31.23%)
Mutual labels:  procedural-generation
Shan Shui Inf
Procedurally generated Chinese landscape painting.
Stars: ✭ 3,168 (+899.37%)
Mutual labels:  procedural-generation
Nonflowers
Procedurally generated paintings of nonexistent flowers.
Stars: ✭ 208 (-34.38%)
Mutual labels:  procedural-generation
Procedural Generation
A mostly javascript-centric resource / links list on procedural content generation (PCG).
Stars: ✭ 203 (-35.96%)
Mutual labels:  procedural-generation
GuneyOzsanOutThereMusicVideo
Procedurally generated, real-time, demoscene style, open source music video made with Unity 3D for Out There by Guney Ozsan.
Stars: ✭ 26 (-91.8%)
Mutual labels:  procedural-generation
IntroToComputerGraphics-CityGenerator
A Procedural City Generator built in Three.js
Stars: ✭ 34 (-89.27%)
Mutual labels:  procedural-generation
Edgar Unity
Unity Procedural Level Generator
Stars: ✭ 237 (-25.24%)
Mutual labels:  procedural-generation
Edgar Dotnet
Configurable procedural layout generator
Stars: ✭ 220 (-30.6%)
Mutual labels:  procedural-generation
Koi
Koi Farm, a koi breeding game
Stars: ✭ 343 (+8.2%)
Mutual labels:  procedural-generation
Terraforged
Mod repo for TerraForged
Stars: ✭ 213 (-32.81%)
Mutual labels:  procedural-generation
balldrop
An experimental musical instrument, made with Godot 3.1.
Stars: ✭ 29 (-90.85%)
Mutual labels:  procedural-generation
Mixture
Mixture is a powerful node-based tool crafted in unity to generate all kinds of textures in realtime
Stars: ✭ 209 (-34.07%)
Mutual labels:  procedural-generation
Gorched
Gorched is terminal based game written in Go inspired by "The Mother of all games" Scorched Earth
Stars: ✭ 232 (-26.81%)
Mutual labels:  procedural-generation
Worldgeneratorfinal
Procedural world map generator
Stars: ✭ 225 (-29.02%)
Mutual labels:  procedural-generation
Terrain Builder
🏔 Procedural terrain using Three.js and perlin noise, Now Accelerated by your GPU!
Stars: ✭ 228 (-28.08%)
Mutual labels:  procedural-generation

wfc

Single-file Wave Function Collapse library in C, plus a command-line tool

  • License: MIT
  • Version: 0.7

This is an early version that supports the overlapping WFC method. The method takes a small input image and generates a larger output image which is locally similar to the input image. A few examples of input/output pairs:

The WFC is often used for procedural map generation, but is not limited to this use-case.

The library is very performant and includes a number of optimizations not found in other implementations. As an example, the generation of the above 128x128 images (from 3x3 patterns, flipped, and rotated), on a MacBook Air M1 (2020) took: 1.35, 0.92, 0.31, 7.7, 1.74, and 0.67 seconds respectively. This includes the image loading/saving time.

LANGUAGE BINDINGS

HOW TO USE THE LIBRARY

One file in your project should include wfc.h like this:

        #define WFC_IMPLEMENTATION
        #include "wfc.h"

Other files can also include and use wfc.h but they shouldn't define WFC_IMPLEMENTATION macro.

Alternatively, you can build a traditional .o file with make wfc.o and use wfc.h as a regular header file.

Usage:

        struct wfc *wfc = wfc_overlapping(
            128,             // Output image width in pixels
            128,             // Output image height in pixels
            input_image,     // Input image that will be cut into tiles
            3,               // Tile width in pixels
            3,               // Tile height in pixels
            1,               // Expand input image on the right and bottom
            1,               // Add horizontal flips of all tiles
            1,               // Add vertical flips of all tiles
            1                // Add n*90deg rotations of all tiles
        );

        wfc_run(wfc, -1);    // Run Wave Function Collapse
                             // -1 means no limit on iterations
        struct wfc_image *output_image = wfc_output_image(wfc);
        wfc_destroy(wfc);
        // use output_image->data
        // wfc_img_destroy(output_image);

By default you work with struct wfc_image for inputs and outputs.

        struct wfc_image {
            unsigned char *data;
            int component_cnt;
            int width;
            int height;
         }

data is tightly packed without padding. Each pixel consists of component_cnt components (e.g., four components for rgba format). The output image will have the same number of components as the input image.

wfc_run returns 0 if it cannot find a solution. You can try again like so:

        wfc_init(wfc);
        wfc_run(wfc, -1);

Working with image files

wfc can optionally use stb_image.h and stb_image_write.h to provide convenience functions for working directly with image files.

You will normally place stb_image.h and stb_image_write.h in the same directory as wfc.h and include their implementations in one of the project files:

        #define STB_IMAGE_IMPLEMENTATION
        #define STB_IMAGE_WRITE_IMPLEMENTATION
        #include "stb_image.h"
        #include "stb_image_write.h"

Further, you will instruct wfc.h to use stb:

        #define WFC_IMPLEMENTATION
        #define WFC_USE_STB
        #include "wfc.h"

Usage:

        struct wfc_image *input_image = wfc_img_load("input.png");
        struct wfc *wfc = wfc_overlapping(
            ...
            input_image,
            ...
        );

        wfc_run(wfc, -1);    // Run Wave Function Collapse
                             // -1 means no restriction on number of iterations
        wfc_export(wfc, "output.png");
        wfc_img_destroy(input_image);
        wfc_destroy(wfc);

Extra functions enabled by the inclusion of stb:

        struct wfc_image *image = wfc_img_load("image.png")
        wfc_img_save(image, "image.png")
        wfc_export(wfc, "output.png")
        wfc_export_tiles(wfc, "directory")
        // don't forget to wfc_img_destroy(image) loaded images

COMMAND-LINE TOOL

The command-line tool uses the library and allows to generate WFC images. The tool depends on stb_image.h and stb_image_write.h. Place both files in the same directory as wfctool.c.

        make
        ./wfc

Run ./wfc to see available options

Basic usage:

        ./wfc -m overlapping samples/wrinkles.png output.png

THANKS

Thanks for using wfc. If you find any bugs, have questions, or feedback please let me know. Also, if you'd like to share your works it's very appreciated.

samp.krystian at gmail.com

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].