mr-highball / wfc

wave function collapse algorithm
MIT License
6 stars 2 forks source link
delphi fpc gamedev procedural-generation wfc

wfc

wave function collapse algorithm

Features

some features at a glance...

Sample

Below is a sample which shows a possible use for wfc:

//easily define the shape (2D or 3D is supported)
LGraph := TGraph.Create.Reshape({width} 5, {height} 5, {depth} 1);

(*
  constraints are also very easy to add and the interface provide fluent setters.
  in this case A's & B's can be present in "any direction" on the graph (north, east, up, down, etc...)
*)
LGraph.AddValue('A')
  .NewRule(AllDirections, ['A', 'B']);

(*  
  but here, we constrain to just a few directions 
  A or B (N & S) of a "C"
*)
LGraph.AddValue('C')
  .NewRule([gdNorth, gdSouth], ['A', 'B']); 

(*
  when you're finished defining constraints and all of the
  possible values (states), then just run and the result can be 
  persisted or you can access the completed graph directly
*)
LGraph.Run();

How To Use

  1. download and install lazarus if you don't already have it (http://www.lazarus-ide.org)
  2. git clone this repo
    • some examples have submodule dependencies so if you want to clone this repo and bring in all of those do a git clone --recursive
    • if you already cloned you can update submodules with git submodule update --init --recursive
  3. open wfc_test.lpr and attempt to compile/run (F9 Key)
    • this project shows some basic usage of the library
    • also, by going to Toolbar -> Project\Project Options\Paths you can copy the other units text to include in your own project
  4. add .\src path to your project other units

Tip Jar