Log In  

2

Cart [#45029#] | Copy | Code | 2017-10-09 | Link
2

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:

  • Use the arrow buttons to move the currently selected control point. (the selected one is highlighted white, while un-selected ones are grey). You will see the curve move as the points of influence move. (Note that it's not really a proper Bezier curve unless all the control points stay still while it is being drawn, I just found it fun to be able to move control points while the curve was being drawn)
  • Press Z to select the next control point in the list. You can then move different points around the map to see how each one influences the curve.
  • Hold X to activate options. While holding X:
    -> tap up to add a new control point. This new control point will appear at a random point on the screen, and will be the new end point for the curve. It will become the selected control point. See how the curve changes based on each control point!
    -> tap down to remove the currently selected control point. The starting control point will become the selected control point.
    -> tap left to reduce the increment value. This means that from moving from the first point to the last point there will be more increments, resulting in a smoother curve. The way I programmed it I only draw one increment each frame, so this will make the drawing slower. If you keep reducing it the curve will stop, and if you go past there the curve will start moving backwards.
    -> Tap right to increase the increment value. This means that there will be less increments when drawing from the first point to the last point, so the curve will be less smooth.

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.

bezier curves smooth movement
P#44968 2017-10-07 10:49

::

Cool cart, welcome to PICO-8! Here are some suggestions for further development, which also serve as introductions to some lesser-known PICO-8 features:

  1. Since you're drawing 1 pixel per frame, use _update60 instead of _update as that makes the PICO-8 run at 60FPS instead of 30 (including calls to _draw)

  2. Print some text while holding down X to show what the arrow buttons will do. You can use print("\XXX") to print specific character codes, including the secret double-width characters and lowercase font. 131 is the down arrow, 139 is left, 145 is right and 148 is up. Details in this thread: https://www.lexaloffle.com/bbs/?tid=3217
P#44971 2017-10-07 21:02

::

Hey RhythmLynx, thanks for the tips! I've only just realised that uploading a cart here sticks it on splore as well, so I've just dumped a cart on splore with obscure controls and no explanation of controls, oops. I'll let you know if I update this, or do these things in my next cart!

P#44978 2017-10-08 03:22

::

Just be careful when using Update60 that the platforms you'll be running this on supports it. Maybe a tiny disclaimer when you post it.

P#44989 2017-10-08 09:55

Log in to post a comment

user:
password:

New User | Account Help
:: New User
X
About | Contact | Updates | Terms of Use
Follow Lexaloffle:        
Generated 2017-10-24 02:08 | 0.312s | 1572k | Q:20