Algorithmic Art
We want to generate probabilistic artwork, efficiently. We are going to use random variables to make a picture filled with non-overlapping circles:
In our art, the circles are different sizes. Specifically, each circle's radius is drawn from a Pareto distribution (which is described below). The placement algorithm is greedy: we sample 1000 circle sizes. Sort them by size, largest to smallest. Loop over the circle sizes and place circles one by one.
To place a circle on the canvas, we sample the location of the center of the circle. Both the x and y coordinates are uniformly distributed over the dimensions of the canvas. Once we have selected a prospective location we then check if there would be a collision with a circle that has already been placed. If there is a collision we keep trying new locations until you find one that has no collisions.
The Pareto Distribution
Pareto Random Variable
Notation: | |
---|---|
Description: | A long tail distribution. Large values are rare and small values are common. |
Parameters: | Note there are other optional params. See wikipedia |
Support: | |
PDF equation: | |
CDF equation: |
Sampling from a Pareto Distribution
How can we draw samples from a pareto? In python its simple: stats.pareto.rvs(a)
however in JavaScript, or other languages, it might not be made transparent. We can use "inverse transform sampling". The simple idea is to choose a uniform random variable in the range (0, 1) and then select the value