Code Monkey home page Code Monkey logo

circle-packing's Introduction

circle-packing

Build Status codecov Clojars Project

tarbell-packing

A Clojure (script) library designed for circle packing.

[circle-packing "0.0.0"]

Usage

exposes gen-packed-circles which optionally takes a config map and returns list of circles having :center as 2d vec and :radius

Params

:min-radius a number or a 0-arity function returning a number

:max-radius a number or a 0-arity function returning a number

:radius-step a number or a 0-arity function returning a number

:max-circles number

:max-attempts number

:padding a number or a 0-arity function returning a number

:random-sampler a 0-arity function that return a 2d vec of random points

:in-bounds? a function that takes a circle as argument and return boolean based on bound checks where a circle has a :center as 2d vec and :radius

Default

{:min-radius 5
 :max-radius 10
 :max-circles 20
 :radius-step 1
 :max-attempts 100
 :padding 0
 :random-sampler #(random-in-rect random-range 0 0 100 100)
 :in-bounds? (partial in-bound-rect? 0 0 100 100)}

Utilities

A few handy utitlies functions are also provided

in-bound-rect? given start and end points of a reactangle returns true if the provided circle is in bound

in-bound-circle? given center as 2d vec and radius of circle checks if the provided circle is in bound

random-in-rect given a random number generator (taking min and max arguments), start and end points of a reactangle returns random points inside

random-in-circle given a random number generator, center as 2d vec and radius of a circle returns random points inside

Examples

Usage with random generator from quil

{:min-radius 5
 :max-radius #(q/random 20 30)
 :max-circles 100
 :padding 4
 :random-sampler #(random-in-rect q/random 0 0 150 100)
 :in-bounds? (partial in-bound-rect? 0 0 150 100)}

circles-in-rect

{:min-radius 5
 :max-radius #(q/random 20 30)
 :max-circles 100
 :padding 4
 :random-sampler #(random-in-circle q/random [50 50] 50)
 :in-bounds? (partial in-bound-circle? [50 50] 50)}

circles-in-circle

License

Copyright © 2020 shrynx

Distributed under the Eclipse Public License either version 1.0 or (at your option) any later version.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.