This is an example of rendering a simple tree-like structure via recursion. The branching angle is calculated as a function of the horizontal mouse location. Move the mouse left and right to change the angle. ]
Recursive Tree: Based on Dan Shiffman's Recursive Tree Example. Revised by Darren Kessner. From 2024 onwards, edited and maintained by p5.js Contributors and Processing Foundation. Licensed under CC BY-NC-SA 4.0.
You can find the code history of these examples here: pre-2023 example, 2023 code. You can suggest improvements by contributing to the current website!
Related Examples

Horizontal stripes fading between light green at the top and dark blue at the bottom.
Color Interpolation
Fade between two colors.

Small circles, each with a different color, arranged in a circular path, displaying hues across the color spectrum.
Color Wheel
Create a visualization of the color spectrum.

Ten rainbow-colored lines in a bezier curve formation.
Bezier
Draw a set of curves.

Dark grey canvas that reflects the lines drawn within it in symmetrical sections.
Kaleidoscope
Draw mirrored designs with the mouse.

Black and white abstract noise texture.
Noise
Generate naturalistic textures using Perlin noise.

A rainbow fractal tree on a black background.
Recursive Tree
Draw a tree using a function that calls itself.