Git Product home page Git Product logo

p5-image-bubbles's Introduction

Image Bubbles ๐Ÿ–ผ ๐Ÿงผ Build Status

This is a project based on p5.js and inspired by Daniel Shiffman's Coding Challenge on Circle Packing dealing with circle packing based on image edge detection with the help of the Sobel operator.

๐Ÿค– Demo ๐ŸŽจ

The sketch has been bootstrapped with the generator-p5-webpack for Yeoman.

Contents

How it works

The basic idea is to spawn bubbles randomly on a canvas and let them grow until they hit another bubble so they never overlap each other.

In this specific project an arbitrary image is loaded into the p5 environment and then analyzed by the sobel package on npm. The Sobel operator is then used to detect edges in the image. It results in a grayscale image emphasizing edges.

Each pixels value is then interpreted as a probability for a bubble to spwan at this specific pixel. When there is no change (edge) in the image at a specific pixel, it is very unlikely for a bubble to spawn there whereas it is very likely that a bubble will spawn at a pixel that lies on an edge in the image.

Each bubble has the exact same color of the pixel it originated at in the original image.

During initialization 1.000 bubbles are generated and 10 more are added in each animation frame. When there is not so much space left and the algorithm did not find a matching origin in 10.000 tries, the try to spawn a bubble is discarded. Therefore, the number of new bubbles spawned per frame is in effect lower that 10.

When clicking in a free spot, a new bubble is spawned regardless of the probability that pixel was assigned.

Parameters

Name Description
SEED_COUNT The number of bubbles that are trying to be generated during initialization.
PROBABILITY_THRESHOLD Offset of minimum and maximum probability of a bubble spawning at a certain pixel. E.g. when set to 0.05 the probability for a bubble to spawn at a specific pixel is in the range of 0.05 to 0.95. Tweaking this parameter has the effect that there might still be the possibility for a bubble to spawn in a specific spot although there is no edge.
BUBBLE_DISTANCE The minimum distance that two bubbles must be away from each other. May also be a negative value to allow overlapping.
BUBBLE_OPACITY Opacity of each bubble between 0 and 255. This has a nice effect when BUBBLE_DISTANCE is negative.
GROWTH_RATE The amount of size the radius of each bubble increases per animation frame.
IMAGE An image preset
BACKGROUND The sketche's background color. Either white or black.

Running the project locally

To run the project locally you have to perform the following steps:

  1. Clone the repository
  2. npm install
  3. npm start

License

GPL-3.0 ยฉ Jannik Portz

p5-image-bubbles's People

Contributors

janizde avatar dependabot[bot] avatar

Stargazers

Luka Kakia avatar

Watchers

James Cloos avatar

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.