box-circle-packer

0.1.7 • Public • Published

box-circle-packer

Circle Packing Alogrithm to pack Random Sized Circles in a Rectangle

Huge Credits to https://stackexchange.com/users/3544517/kuroi-neko for coding this Algorithm

Packer

import pack from 'box-circle-packer'
 
const width = window.innerWidth;
const height = window.innerHeight
const circles = 100
const min_r = 20;
const max_r = 80;
const radiuses = []
for (let i = 0; i !== circles; i++)
    radiuses.push(Math.random() * (max_r - min_r) + min_r);
const list = pack(radiuses, width, height)

packer

Installation

npm install box-circle-packer

Usage

Using NPM

1 . Require box-circle-packer after installation

import pack from 'box-circle-packer'

2 . Call pack with required Arguments

const packedCircles = pack(radiuses, width, height, spacingFactor)

Options

Arguments Type Description Default Value
radiuses Number[] Array of circles Radius []
width Number Width of Box 0
height Number Height of Box 0
spacingFactor Number Spacing Between Circles 0

Contributing

We welcome your contribution! Fork the repo, make some changes, submit a pull-request!.

License

none

Package Sidebar

Install

npm i box-circle-packer

Weekly Downloads

12

Version

0.1.7

License

none

Unpacked Size

5.68 kB

Total Files

3

Last publish

Collaborators

  • sadainiqrar