Inspired/derived from the very nice work of Jason Davies.
This is just a bit of archeology, i.e. an attempt at understanding how he got the formulas to do it...

Drag the endpoints!