Skip to content

Instantly share code, notes, and snippets.

@mritterhoff
mritterhoff / README.md
Last active November 28, 2015 06:09 — forked from mbostock/.block
Poisson-Disc II

This animation demonstrates how Bridson’s poisson-disc sampling algorithm works.

Red dots represent “active” samples. At each iteration, one is selected randomly from the set of all active samples. Then, up to k candidate samples (shown as hollow black dots), are randomly generated within an annulus surrounding the selected sample.

The annulus extends from radius r to 2r, where r is the minimum allowable distance between any two samples. Candidate samples within radius r from an existing sample are rejected; this “exclusion zone” is shown in gray, along with a black line connecting the rejected candidates with the existing sample that is too close. If the candidate is acceptable, it is added as a new active sample.

A background grid of size r/√2 is used to accelerate the distance check for each candidate. Because each cell can only contain at most one sample, only a fixed number of neighboring cells need to be inspected.

If none of the k candidates are accep

@mritterhoff
mritterhoff / README.md
Last active August 29, 2015 14:19
Rearranging President Names

Inspired by (and code lifted from) mbostock's General Update Pattern III. This example looks very similar, but is a bit more complex in that it will work well with arbirtary strings, rather than those that are garenteed to have unique characters, like the example I worked off of. This is accomplished by determining the incidence of each character, as it appeared, and then using that incidence and character to be returned in a key function. This insured that characters didn't try to go the same spot, as the result of my first naive attempt.

Check out out the live example at bl.ocks