The most recognisable image under the topic of chaos theory. The butterfly figure produced by a Lorenz attractor.
The above image is rendered using p5.js. The simulation is done using the
Euler method.
The Lorenz system is described by the three equations that follow
In this simulation, the system is rendered by adding small time steps, calculating the values of the rates of changes and of the variables themselves, and hence computing and rendering the positions. The algorithm used (Euler's) is shown in the simplified pseudocode that follows
x <- 0.01
y <- 0
z <- 0
sigma <- 10
rho <- 28
beta <- 8/3
while true:
dx <- sigma*(x-y)
dy <- x*(rho-z)-y
dz <- x*y-beta*z;
x <- x+dx
y <- y+dx
z <- z+dx
build_line(x,y,z);
The above build_line(x,y,z) function appends onto a list of coordinates, and draws a
curve through those coordinates.