This was inspired by @mpilgrem’s post on Bézier curves with his petals, and here is my code

```
function setup()
points = {}
for i = 1, math.random(3, 7) do
table.insert(points, vec2(math.random(WIDTH), math.random(HEIGHT)))
end
t = 0 -- time
q = 100 -- quality
P = {} -- points of the bezier
parameter("speed", .1, 2, .75)
end
function draw()
background(0, 0, 0, 255)
stroke(127, 127, 127, 255)
t = t + speed
if t > q then
t = 0
P = {}
end
table.insert(P, drawBezier(points, t, q))
stroke(255, 255, 255, 255)
for i = 1, #P - 1 do
line(P[i], P[i + 1])
end
end
function drawBezier(p)
local len = #p
local lines = {}
if len > 2 then
strokeWidth(len)
for i = 1, #p - 1 do
table.insert(lines, p[i + 1] - p[i])
line(p[i], p[i + 1])
end
local newP = {}
for i, l in ipairs(lines) do
table.insert(newP, p[i] + (l / q) * t)
end
return drawBezier(newP)
end
line(p[1], p[2])
return p[1] + (p[2] - p[1]) / q * t
end
local l = line
line = { f = l }
function line:__call(x, y, a, b)
if type(y) == "userdata" then
self.f(x.x, x.y, y.x, y.y)
elseif type(x) == "userdata" then
self.f(x.x, x.y, y, a)
elseif type(a) == "userdata" then
self.f(x, y, a.x, a.y)
else
self.f(x, y, a, b)
end
end
setmetatable(line, line)
```