Home /  Sketchbook /  p5.js - Meandering River
  • Info

Overview

This is a p5.js sketch that lays the foundation for exploring the modeling of meandering rivers (Wikipedia).

Specifically, this just establishes the data model and what I hope is a good initial state to explore actual meandering in subsequent sketches. The implementing PR includes diagrams of the data structures and smoothing approach.

Controls

Configuration:

(via the dat.gui control panel)

  • num_segments how many starting lines there are before smoothing takes place
  • wave_amplitude number of pixels above and below the centerline the sine wave used to place the points will swing.
  • wave_frequency the number of sine-wave oscillations before the end point.
  • source_heading the direction of flow for head of the river
  • smooth_curves toggles on/off the algorithmic smoothing of the curve.

Note: If you max out the num_segments you can see a clear depiction of the underlying sine-wave used for point generation. When the segment count is low, it is basically placing a point at the y coordinate along that wave for discrete x points (a sort of data-sampling effect).

References:

  • Wikipedia: Meandering

Links:

  • Live View
  • Source on Github
  • Primary Implementation

Screenshot:

screenshot