Bézier Trails

Controls

Move cursor / drag on device to leave a trail.

Overview

This is based on an answer about how to draw a smooth curve through user defined points. We maintain an array of points and every frame the coordinates of point [i] are set to the coordinates of point [i-1]. The first element of the array tracks user input and the rest of the points follow it, thereby creating a snaking body. We approximate a smooth line through the points by drawing a quadratic curve using the midpoints between the array elements as control points.