npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

wavefunctioncollapse

v2.1.0

Published

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

Downloads

62

Readme

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.1.0 (2021-03-27)

  • Port of the latest changes (trivial symmetry support in SimpleTiledModel).
  • Update dev dependencies.

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