0.0.4 • Published 8 months ago

physixels v0.0.4

Weekly downloads
-
License
MIT
Repository
github
Last release
8 months ago

Physixels

A small pixel based physics library that's really only one function

Installing

Install this module with yarn add physixels or npm i physixels.

Getting Started

Import using ES6 Modules

import { step } from "physixels";

Create Multidimensional Array of Data

const data = [
    [0, 0, 0, 2, 0, 0, 0],
    [0, 0, 0, 1, 0, 0, 0],
    [0, 0, 0, 0, 0, 0, 0],
    [0, 0, 1, 0, 1, 0, 0],
    [0, 0, 0, 0, 0, 0, 0],
    [0, 1, 0, 1, 0, 1, 0],
];

Run Physixels

const newData = step(data);
// Output:
/* newData = 
    [
        [0, 0, 0, 0, 0, 0, 0],
        [0, 0, 2, 1, 0, 0, 0],
        [0, 0, 0, 0, 0, 0, 0],
        [0, 0, 1, 0, 1, 0, 0],
        [0, 0, 0, 0, 0, 0, 0],
        [0, 1, 0, 1, 0, 1, 0],
    ];
*/

Reference

type Options = {
    // Bias for pixel's drop direction
    // Default: 'random'
    bias: 'left' | 'right' | 'random';
    
    // Seed for if bias is 'random'
    // Default: null
    seed: string | null;
    
    // Skip to state after running X + 1 times
    // Default: 0
    skip: number;
    
    // If pixels can pass through blocks diagonally 
    // Default: true
    diagonalPassthrough: boolean;

    // A list of cell behaviors based on number
    // Default: 
    /* [
        { id: 0, behavior: 'empty' },
        { id: 1, behavior: 'static' },
        { id: 2, behavior: 'dynamic' }
    ] */
    cellTypes: {
        id: number;
        behavior: 'empty' | 'static' | 'dynamic';
    }[]
}

function step(data: number[][], options?: Partial<Options>): number[][]
0.0.4

8 months ago

0.0.3

8 months ago

0.0.2

8 months ago

0.0.1

8 months ago