Bezier Curves Demonstration

Published 2023-06-12


Hey everyone! This is my first time publishing a PICO-8 cart, I'm excited to get involved!
To get myself used to the PICO-8 a bit I thought I'd make a cart that simulates Bezier Curves! To put it simply, Bezier Curves are smooth curves, the plotting of which is influenced by a collection of control points. To put it longform... https://en.wikipedia.org/wiki/B%C3%A9zier_curve

Controls:

This cart is intended to demo what Bezier curves look like and how you can manipulate them, although I've tried to write it so it will be as easy as possible for anyone to take the bezier curve code out of it for their own purposes! If you want to use Bezier curves in your own code, grab the CALXY(CPS,T) function, the DFOR(I,C,CPS,CPNO,T) and the BINOMIAL(N,K) functions. You should make a variable that calculates how far along the curve you want to find the point for (which my example code calls T). Calculate T however you want, then call CALXY(CPS,T) passing in a 2DArray of coordinates for CPS (ControlPointS) and your T value for T. This function will return the X and Y values at that point. You could use this code to make a game object move along the curve, for example.

Let me know what you think, and if I'm missing any obvious Lua tricks let me know! I'm pretty new to the language.

Updated to display controls at the beginning, and stop big white lines being drawn while moving control points.