jakes-gordon-growing-packer
A javascript binary tree based algorithm for 2d bin-packing
Purpose
- Creating a spritesheet generator
Install
npm install jakes-gordon-growing-packer
How to use
See first the Original algorithm README
var GrowingPacker = var packer = //sortMethod: a sort method or a valid sort method name, default to maxside blocks: w: 100 h: 100 w: 100 h: 100 w: 80 h: 80 w: 80 h: 80 /* blocks is optional and can be passed directly to the pack method */; var pack = packer; // or var packer = ;var pack = packer; // then console; var rectangles = pack; //note that the rectangles method modify your original blocks array forvar i = 0 imax = rectangleslength ; i < imax ; i++ var rect = rectanglesi; //do something like : //DrawRectangle(rect.x, rect.y, rect.w, rect.h);
Valid sort methods
-
random
{return Math - 05;} -
w
{return bw - aw;} -
h
{return bh - ah;} -
a
{return barea - _aarea;} -
max
{return Math - Math;} -
min
{return Math - Math;} -
height
{return ;} -
width
{return ;} -
area
{return ;} -
maxside
{return ;}
Credits
The packing algorithm is from here
I just wrap it in a custom API (including the sort methods proposed by Jake Gordon ) and make it accesible via npm since that issue is still opened.