Javascript port of https://github.com/mxgmn/WaveFunctionCollapse
MIT License
Javascript port of https://github.com/mxgmn/WaveFunctionCollapse
With npm do:
npm install wavefunctioncollapse --production
new OverlappingModel(data, dataWidth, dataHeight, N, width, height, periodicInput, periodicOutput, symmetry[, ground])
var wfc = require('wavefunctioncollapse');
var imgData = ... // let's pretend this is an ImageData retrieved from a canvas context in the browser
var model = new wfc.OverlappingModel(imgData.data, imgData.width, imgData.height, 3, 48, 48, true, true, 4);
model.graphics([array])
Retrieve the RGBA data of the generation.
// create a blank ImageData
var imgData = canvasContext.createImageData(48, 48);
// write the RGBA data directly in the ImageData
model.graphics(imgData.data);
// print the ImageData in the canvas
canvasContext.putImageData(imgData, 0, 0);
new SimpleTiledModel(data, subsetName, width, height, periodicOutput)
var wfc = require('wavefunctioncollapse');
var data = ... // object with tiles, subsets and constraints definitions
var model = new wfc.SimpleTiledModel(data, null, 48, 48, false);
model.graphics([array[, defaultColor]])
Retrieve the RGBA data of the generation.
// create a blank ImageData
var imgData = canvasContext.createImageData(48, 48);
// write the RGBA data directly in the ImageData, use an opaque blue as the default color
model.graphics(imgData.data, [0, 0, 255, 255]);
// print the ImageData in the canvas
canvasContext.putImageData(imgData, 0, 0);
model.generate([rng])
Execute a complete new generation. Returns whether the generation was successful.
model.generate(Math.random); // return true or false
model.iterate(iterations[, rng])
Execute a fixed number of iterations. Stop when the generation is successful or reaches a contradiction. Returns whether the iterations ran without reaching a contradiction.
model.iterate(30, Math.random); // return true or false
model.isGenerationComplete()
Returns whether the previous generation completed successfully.
model.clear()
Clear the internal state to start a new generation.
MIT