All Projects → kchapelier → Wavefunctioncollapse

kchapelier / Wavefunctioncollapse

Licence: mit
Javascript port of https://github.com/mxgmn/WaveFunctionCollapse

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Wavefunctioncollapse

AsLib
🎨: RPG map maker (paint tool)
Stars: ✭ 82 (-72.39%)
Mutual labels:  procedural-generation, tilemap
Ndwfc
🌊💥 N-dimensional Wave Function Collapse with infinite canvas
Stars: ✭ 159 (-46.46%)
Mutual labels:  procedural-generation, tilemap
SdfFontDesigner
Offline font tuning/bitmap generation via shaders
Stars: ✭ 56 (-81.14%)
Mutual labels:  procedural-generation
Bwo
An infinity procedural online game using Flutter with NodeJS and flames
Stars: ✭ 262 (-11.78%)
Mutual labels:  procedural-generation
meta2d
Meta2D is open source WebGL 2D game engine for making cross platform games.
Stars: ✭ 33 (-88.89%)
Mutual labels:  tilemap
macroverse
An entire universe on the Ethereum blockchain
Stars: ✭ 31 (-89.56%)
Mutual labels:  procedural-generation
texture generator
Generating procedural textures
Stars: ✭ 23 (-92.26%)
Mutual labels:  tilemap
UnityModularSystem
Unity Modular system let's you create game object with procedural generated parts.
Stars: ✭ 31 (-89.56%)
Mutual labels:  procedural-generation
Project Skylines
procedural retro 3d game, winner of the GitHub Gameoff 2017
Stars: ✭ 293 (-1.35%)
Mutual labels:  procedural-generation
city-tour
A procedurally generated city built with WebGL and three.js
Stars: ✭ 57 (-80.81%)
Mutual labels:  procedural-generation
VulkanRenderer
Personal repo for learning the vulkan graphics api
Stars: ✭ 42 (-85.86%)
Mutual labels:  procedural-generation
FallingSandSurvival
2D survival game inspired by Noita and slightly Terraria
Stars: ✭ 66 (-77.78%)
Mutual labels:  procedural-generation
cl-tiled
Tiled map library for CL
Stars: ✭ 15 (-94.95%)
Mutual labels:  tilemap
DungeonTemplateLibraryUnity
🌏: Dungeon free resources (terrain & roguelike generation)
Stars: ✭ 51 (-82.83%)
Mutual labels:  procedural-generation
differential-growth
adrianton3.github.io/differential-growth/
Stars: ✭ 27 (-90.91%)
Mutual labels:  procedural-generation
Wavefunctioncollapse
Bitmap & tilemap generation from a single example with the help of ideas from quantum mechanics
Stars: ✭ 17,156 (+5676.43%)
Mutual labels:  procedural-generation
DoomlikeDungeons
A procedural multi-room dungeon generator for Minecraft
Stars: ✭ 23 (-92.26%)
Mutual labels:  procedural-generation
Procedural-Generation
An Overview of Procedural Generation Techniques and Applications
Stars: ✭ 23 (-92.26%)
Mutual labels:  procedural-generation
fishdraw
procedurally generated fish drawings
Stars: ✭ 1,963 (+560.94%)
Mutual labels:  procedural-generation
Mapgen2
JavaScript version of mapgen2 polygon map generator algorithms
Stars: ✭ 296 (-0.34%)
Mutual labels:  procedural-generation

wavefunctioncollapse

Javascript port of https://github.com/mxgmn/WaveFunctionCollapse

Installing

With npm do:

npm install wavefunctioncollapse --production

Public API

OverlappingModel Constructor

new OverlappingModel(data, dataWidth, dataHeight, N, width, height, periodicInput, periodicOutput, symmetry[, ground])

  • data : The RGBA data of the source image.
  • dataWidth : The width of the source image.
  • dataHeight : The height of the source image.
  • N : Size of the patterns.
  • width : The width of the generation (in pixels).
  • height : The height of the generation (in pixels).
  • periodicInput : Whether the source image is to be considered as periodic / as a repeatable texture.
  • periodicOutput : Whether the generation should be periodic / a repeatable texture.
  • symmetry : Allowed symmetries from 1 (no symmetry) to 8 (all mirrored / rotated variations)
  • ground : Id of the specific pattern to use as the bottom of the generation (learn more)
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);

OverlappingModel Methods

model.graphics([array])

Retrieve the RGBA data of the generation.

  • array : Array to write the RGBA data into (must already be set to the correct size), if not set a new Uint8Array will be created and returned. It is recommended to use Uint8Array or Uint8ClampedArray.
// 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);

SimpleTiledModel Constructor

new SimpleTiledModel(data, subsetName, width, height, periodicOutput)

  • data : Tiles, subset and constraints definitions. The proper doc on this matter is yet to be written, check the example in the meantime.
  • subsbetName : Name of the subset to use from the data. If falsy, use all tiles.
  • width : The width of the generation (in tiles).
  • height : The height of the generation (in tiles).
  • periodicOutput : Whether the generation should be periodic / a repeatable texture.
var wfc = require('wavefunctioncollapse');

var data = ... // object with tiles, subsets and constraints definitions

var model = new wfc.SimpleTiledModel(data, null, 48, 48, false);

SimpleTiledModel Methods

model.graphics([array[, defaultColor]])

Retrieve the RGBA data of the generation.

  • array : Array to write the RGBA data into (must already be set to the correct size), if not set a new Uint8Array will be created and returned. It is recommended to use Uint8Array or Uint8ClampedArray.
  • defaultColor : RGBA data of the default color to use on untouched tiles.
// 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);

Common Methods

model.generate([rng])

Execute a complete new generation. Returns whether the generation was successful.

model.generate(Math.random); // return true or false
  • rng : A function to use as random number generator, defaults to Math.random.

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.

  • iterations : Maximum number of iterations to execute (0 = infinite).
  • rng : A function to use as random number generator, defaults to Math.random.
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.

Changelog

2.0.0 (2019-07-06)

  • Port of the newer, faster, implementation.
  • This port is now written in ES6 instead of ES5 [breaking change].

1.0.0 (2016-10-14)

  • Change and freeze the public API (with iteration support).
  • First publication on NPM.

License

MIT

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].