File Exchange

image thumbnail

Draw randomly centered circles of various sizes

version 2.3.0 (371 KB) by Adam Danz
Set the range of radii, density, and other parameters to create a plot that draws randomly centered polygons with or without overlap.


Updated 22 Jan 2021

View Version History

View License

Editor's Note: This file was selected as MATLAB Central Pick of the Week

bubblebath() plots circles or other polygons at random positions with varying radii. All input parameters are optional including frame size, range of radii, number of vertices per bubble (eg, polygon shape), density, the amount of space between bubbles or how much they can overlap, edge behavior, and other parameters. A figure is produced and there are four outputs that allow the user to make further changes to the plotted objects or to recreate the exact same plot using the same version of the code.

See the help section for a detailed description of each optional parameter and its default value.

bubblebath_examples.mlx contains many examples showing how to manipulate parameters and how to use the outputs to add color, calculated area of each circle, and other useful information.

Follow this page for updates.

Cite As

Adam Danz (2020). Bubblebath.m (, MATLAB Central File Exchange. Retrieved April 7, 2020.

Comments and Ratings (4)

ibrahim simsek

Mr. Danz

First of all, the code was perfect. Thank you for your effort. But I have a question on my mind. In a random system, will the ratio of the [(total area-area of ​​the all circles which are inside the rectangle)/(total area)] (porosity) be entered as input? Is it possible to create such a system in Matlab?

Have a nice day

Antoine Deblais

Adam Danz

@Guang Lu, the error you experienced was due to using an older version of Matlab prior to r2016b when explicit expansion was not allowed. Nevertheless, I updated the file so that it avoids explicit expansion errors in earlier versions of matlab.

Guang Lu

There is an error in line 131

MATLAB Release Compatibility
Created with R2020b
Compatible with R2016a and later releases
Platform Compatibility
Windows macOS Linux

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!