Epicycloids and Hypocycloids

Epicycloids and hypocycloids are curves that can be defined by circles. Let a fixed circle (black) be given. A second, movable circle (blue) rolls on the outside (in the case of the epicycloid) or on the inside (in the case of the hypocycloid) of the fixed circle. By a point at the border of the moving circle the curve (red) is generated. If the radii of the two circles have an integer ratio, the curve is closed.

This browser doesn't support HTML5 canvas!
: