All Projects → kchapelier → convchain

kchapelier / convchain

Licence: MIT license
Javascript port of https://github.com/mxgmn/ConvChain

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to convchain

vengi
Home of a voxel game engine and its tools (like a voxel editor)
Stars: ✭ 800 (+1718.18%)
Mutual labels:  procedural-generation
world
This is a fantasy world generation API and set of Go packages for the same.
Stars: ✭ 42 (-4.55%)
Mutual labels:  procedural-generation
WaveCollapseFunction
Unity project that uses Wave Collapse Function to procedurally generate buildings
Stars: ✭ 20 (-54.55%)
Mutual labels:  procedural-generation
MagicaVoxel File Writer
MagicaVoxel File Writer dependency free cpp class
Stars: ✭ 26 (-40.91%)
Mutual labels:  procedural-generation
CubicNoise
1D & 2D Random noise with bicubic interpolation
Stars: ✭ 76 (+72.73%)
Mutual labels:  procedural-generation
wfc
Go port of the Wave Function Collapse algorithm
Stars: ✭ 47 (+6.82%)
Mutual labels:  procedural-generation
landscape
Procedural landscape
Stars: ✭ 17 (-61.36%)
Mutual labels:  procedural-generation
gemini
Sci-Fi galaxy simulation with heavy procedural generation focus
Stars: ✭ 25 (-43.18%)
Mutual labels:  procedural-generation
VR audioscape
Google Summer of Code 2017 project - VR application built with processing-android
Stars: ✭ 32 (-27.27%)
Mutual labels:  procedural-generation
procedural-art
🌌 Procedural art with vanilla JavaScript
Stars: ✭ 83 (+88.64%)
Mutual labels:  procedural-generation
Recursive-Tile-Map-Growth
Tile based level growth algorithm used in Procedural Dungeon Toolkit
Stars: ✭ 40 (-9.09%)
Mutual labels:  procedural-generation
SpaceProject
A top-down 2D, procedurally generated space exploration and shooter game using libGDX. Kinda like Asteroids, only a little bigger.
Stars: ✭ 28 (-36.36%)
Mutual labels:  procedural-generation
unity-shadergraph-sketches
🎨 Sketches made with ShaderGraph in Unity.
Stars: ✭ 47 (+6.82%)
Mutual labels:  procedural-generation
zeo
Multiplayer WebVR worlds made out of npm modules.
Stars: ✭ 47 (+6.82%)
Mutual labels:  procedural-generation
SimpleErosion
Simple C++ implementatoin of particle-based hydraulic erosion on a square grid
Stars: ✭ 64 (+45.45%)
Mutual labels:  procedural-generation
aframe-lsystem-component
L-System/LSystem component for A-Frame to draw 3D turtle graphics. Using Lindenmayer as backend.
Stars: ✭ 33 (-25%)
Mutual labels:  procedural-generation
blackout
Procedurally generated blackout poetry
Stars: ✭ 56 (+27.27%)
Mutual labels:  procedural-generation
camp
Building generative VR worlds on the Web
Stars: ✭ 16 (-63.64%)
Mutual labels:  procedural-generation
flowing-terrain
Algorithm for creating 3 dimensional terrain maps and their likely watercourses.
Stars: ✭ 27 (-38.64%)
Mutual labels:  procedural-generation
calder
Interactive constraints for controlling the growth of procedural models.
Stars: ✭ 17 (-61.36%)
Mutual labels:  procedural-generation

convchain

Vanilla javascript port of ConvChain.

Interactive demo

Installing and testing

With npm do:

npm install convchain

Basic example

var ConvChain = require('convchain');

var samplePattern = Uint8Array.from([
    1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
    1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
    1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
    1, 1, 1, 0, 0, 0, 0, 1, 1, 1,
    0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
    0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
    1, 1, 1, 0, 0, 0, 0, 1, 1, 1,
    1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
    1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
    1, 1, 1, 1, 1, 1, 1, 1, 1, 1
]);

var width = 45,
    height = 20;

var convChain = new ConvChain(samplePattern);

var generatedPattern = convChain.generate([width, height], 3, 0.5, 4); // a flat Uint8Array

// some code to display the result
for (var y = 0; y < height; y++) {
    var s = '';
    for (var x = 0; x < width; x++) {
        s += ' ' + generatedPattern[x + y * width];
    }
    console.log(s);
}

Public API

Constructor

new ConvChain(sample[, sampleSize])

  • sample : Sample pattern as a flat array or a 2D array.
  • sampleSize : Indicate the width and height of the sample when used with a flat array, if omitted the sample pattern is assumed to be a square.
var testSample = Uint8Array.from([
    1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
    1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
    1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
    1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1,
    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
    1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1,
    1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
    1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
    1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1
]); //flat array

var convChain = new ConvChain(testSample, [14, 10]);
var testSample = [
    [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
    [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
    [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
    [1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1],
    [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
    [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
    [1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1],
    [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
    [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
    [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]
]; //2D array

var convChain = new ConvChain(testSample);

Methods

convChain.setSample(sample[, sampleSize])

Same arguments as the constructor.

convChain.generate(resultSize, n, temperature, iterations[, rng])

Generate a new pattern based on the sample pattern. The generated pattern is returned as a flat Uin8Array.

  • resultSize : Width and height of the generated pattern.
  • n : Receptor size, an integer greater than 0.
  • temperature : Temperature, a float.
  • iterations : Number of iterations.
  • rng : A function to use as random number generator, defaults to Math.random.
var result = convChain.generate([100, 50], 3, 0.5, 4);

convChain.iterate(field, resultSize, n, temperature[, tries[, rng]])

Execute a specific number of operations on a given pattern.

  • field : An existing pattern given as a flat Uint8Array. If null is given, a noisy pattern will be used instead.
  • resultSize : Width and height of the generated pattern.
  • n : Receptor size, an integer greater than 0.
  • temperature : Temperature, a float.
  • tries : Number of operations to execute, default to the result's width multiplied by the result's height
  • rng : A function to use as random number generator, defaults to Math.random.
var field = null;

for (var i = 0; i < 32; i++) {
    field = convChain.iterate(field, [64, 64], 3, 0.2, 128);

    // ... do something with the return pattern here
}

Changelog

1.1.0 (2016-08-25)

  • Implement the iterate method.

1.0.0 (2016-08-21)

  • First implementation.

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