All Projects → mapbox → Potpack

mapbox / Potpack

Licence: isc
A tiny rectangle packing JavaScript library (for sprite layouts)

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Potpack

Cslearning
开源项目之「计算机编程自学之路」:计算机自学指南+面试大全+资源分享+技术文章
Stars: ✭ 107 (-6.96%)
Mutual labels:  algorithms
Acm Icpc Library
Stars: ✭ 111 (-3.48%)
Mutual labels:  algorithms
Competitive Programming
Hello Programmers 💻 , A one-stop Destination✏️✏️ for all your Competitive Programming Resources.📗📕 Refer CONTRIBUTING.md for contributions
Stars: ✭ 113 (-1.74%)
Mutual labels:  algorithms
Tlaplus
TLC is an explicit state model checker for specifications written in TLA+. The TLA+Toolbox is an IDE for TLA+.
Stars: ✭ 1,618 (+1306.96%)
Mutual labels:  algorithms
Sage
Mirror of the Sage source tree -- please do not submit PRs here -- everything must be submitted via https://trac.sagemath.org/
Stars: ✭ 1,656 (+1340%)
Mutual labels:  algorithms
Hackerrank
Efficient HackerRank solutions in JavaScript (⬡.js)
Stars: ✭ 111 (-3.48%)
Mutual labels:  algorithms
Java
All Algorithms implemented in Java
Stars: ✭ 42,893 (+37198.26%)
Mutual labels:  algorithms
Functional Way
Write small programs (eg -algorithms) in a functional way.
Stars: ✭ 115 (+0%)
Mutual labels:  algorithms
Graphav
A Graph Algorithms Visualizer built using React, Typescript and Styled Components.
Stars: ✭ 111 (-3.48%)
Mutual labels:  algorithms
Dailycodingproblem
Stars: ✭ 113 (-1.74%)
Mutual labels:  algorithms
Mygo
Leetcode、剑指offer(第二版)的Go实现😀 Come join us!🤝❤️👻
Stars: ✭ 109 (-5.22%)
Mutual labels:  algorithms
Index
Metarhia educational program index 📖
Stars: ✭ 2,045 (+1678.26%)
Mutual labels:  algorithms
Ultimate Go
This repo contains my notes on working with Go and computer systems.
Stars: ✭ 1,530 (+1230.43%)
Mutual labels:  algorithms
Indoor Navigation Algorithms
This is a public repository of a Navigine company that develops different kinds of indoor positioning algorithms with the main focus on indoor navigation. Here we will step by step publish the source code of our algorithm starting with trilateration.
Stars: ✭ 108 (-6.09%)
Mutual labels:  algorithms
Scriptsdump
The biggest dump of scripts ever!
Stars: ✭ 114 (-0.87%)
Mutual labels:  algorithms
Material Design Icons
Material Design icons by Google
Stars: ✭ 44,551 (+38640%)
Mutual labels:  sprites
Syntaxmeets
Syntaxmeets. Create rooms 🏠 Call your friends 👬🏼 Sip Chai, ☕ Chat, Create, and Code👨‍💻. A coding platform to code simultaneously 🚀 with your friends and design your algorithms on SyntaxPad.💫✨
Stars: ✭ 110 (-4.35%)
Mutual labels:  algorithms
Pydml
Distance Metric Learning Algorithms for Python
Stars: ✭ 115 (+0%)
Mutual labels:  algorithms
Foundational Knowledge For Programmers
List of resources about foundational knowledge for programmers (supposed to last a few decades)
Stars: ✭ 115 (+0%)
Mutual labels:  algorithms
Jortsort
the official website for jortSorting
Stars: ✭ 112 (-2.61%)
Mutual labels:  algorithms

potpack

A tiny JavaScript library for packing 2D rectangles into a near-square container, which is useful for generating CSS sprites and WebGL textures. Similar to shelf-pack, but static (you can't add items once a layout is generated), and aims for maximal space utilization.

A variation of algorithms used in rectpack2D and bin-pack, which are in turn based on this article by Blackpawn.

Demo

Example usage

import potpack from 'potpack';

const boxes = [
    {w: 300, h: 50},
    {w: 100, h: 200},
    ...
];

const {w, h, fill} = potpack(boxes);
// w and h are resulting container's width and height;
// fill is the space utilization value (0 to 1), higher is better

// potpack mutates the boxes array: it's sorted by height,
// and box objects are augmented with x, y coordinates:
boxes[0]; // {w: 300, h: 50,  x: 100, y: 0}
boxes[1]; // {w: 100, h: 200, x: 0,   y: 0}

Install

Install with NPM (npm install potpack) or Yarn (yarn add potpack), then:

// import as an ES module
import potpack from 'potpack';

// or require in Node / Browserify
const potpack = require('potpack');

Or use a browser build directly:

<script src="https://unpkg.com/[email protected]/index.js"></script>
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].