# rectpack

> A very fast bin-packing algorithm. Good for creating sprite-sheets and texture-atlases.

Latest version **1.0.11** (published 2016-04-29) · ISC license · 0 weekly downloads

## Install

```sh
npm install rectpack
pnpm add rectpack
yarn add rectpack
bun add rectpack
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.11 |
| Published | 2016-04-29 |
| First published | 2015-07-23 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | felix deimling |
| Maintainers | felixdeimling |
| Keywords | bin-packing, spritesheet, atlas, js, algorithm |

## Links

- npm: https://www.npmjs.com/package/rectpack
- npm.io page: https://npm.io/package/rectpack

## Alternatives

- [@mapbox/jsonlint-lines-primitives](https://npm.io/package/@mapbox/jsonlint-lines-primitives.md) — 5.3M weekly downloads
- [reftools](https://npm.io/package/reftools.md) — 3.5M weekly downloads
- [@hey-api/openapi-ts](https://npm.io/package/@hey-api/openapi-ts.md) — 3.5M weekly downloads
- [@mapbox/geojson-rewind](https://npm.io/package/@mapbox/geojson-rewind.md) — 2.4M weekly downloads
- [turbo-stream](https://npm.io/package/turbo-stream.md) — 1.7M weekly downloads

## Recent versions

- 1.0.11 (latest) — 2016-04-29
- 1.0.10 — 2016-04-29
- 1.0.9 — 2015-07-23
- 1.0.8 — 2015-07-23
- 1.0.7 — 2015-07-23
- 1.0.6 — 2015-07-23
- 1.0.5 — 2015-07-23
- 1.0.4 — 2015-07-23
- 1.0.2 — 2015-07-23
- 1.0.1 — 2015-07-23
- 1.0.0 — 2015-07-23

## README

# Rectpack
a very fast implementation of a bin-packing algorithm. Good for spritesheets or atlastextures.
Its data-based not DOM-based, so you can use it for DOM-objects as well as for canvas ...

##Demo

[DEMO on Website](http://flexelektro.github.io/texture-packer/)

##Usage

Download the [minified library](https://raw.githubusercontent.com/flexelektro/texture-packer/master/dist/rectpack.min.js) and include it in your html.

```html
<script src="js/two.min.js"></script>
```

It can als be installed via `npm`

```js
npm install --save recter.js
```

Create a your, by calling the global Function **RP** :

```js
var rectdata = RP(objectsData,options);
```

where **objectsDatas** is basicaly an array of objects which have tow fields mandatory:
```js
singleObject = {
    width:  number
    height: number
    ownDataOrObjects: any 
}
```

you will get back the generated bin-packed-data, where elements are basically your inputElemnts with attached x (left) and y (top) values :


```js
{
    atlasSize:{
        height:number,
        width:number
    },
    elements:[
        {
            width:  number
            height: number
            ownDataOrObjects: any,
            x: number,
            y: number
        },
        {
            width:  number
            height: number
            ownDataOrObjects: any,
            x: number,
            y: number
        }
        ...
    ]
}
```

##example


```js 
    var elements = [];
    for(var i = 0; i < 600; i++){
       var el =  document.createElement("div");
            el.style.width = (3 +Math.random()*30)+"px";
            el.style.height = (3 +Math.random()*30)+"px";
            el.style.backgroundColor = "rgba("+makeRandom255()+")";
            el.style.position = "absolute";
        someHTMLElement.appendChild(el);
            elements.push({
                "el":el,
                "id":i,
                "width":el.style.width,
                "height":el.style.height
            });
        }
    var els = RP(elements,{
        padding:2
    });
    console.log(els);
    els.elements.forEach(function(obj){ 
        obj.el.style.top = obj.y + "px";
        obj.el.style.left = obj.x + "px";
    });
```

for a small Demo have a look here: [DEMO](http://flexelektro.github.io/texture-packer)

---
_Source: https://npm.io/package/rectpack · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
