This repo finds all of the contours of a minimum population density and shows them on a map of either the world or most of North America. Data comes from https://sedac.ciesin.columbia.edu/data/collection/gpw-v4.
The contour.js file runs the contour finding algorithm with adjustable delay to see it in action. This file could be modified for other contour finding applications. It is fast enough for decent sized grids but it is not meant for maximum speed.
You can edit the HTML or JS to change some style, but there is not too much else to easily modify.
Read the blog post answering some population questions at https://triplelog.com/blog/what-is-the-population-of-that-region.html