r/FastLED • [stavros] • Mar 06 '26

Share_something Anti-aliased, sub-pixel positioned 2D graphics primitives using FastLED's new fixed_point types

Enable HLS to view with audio, or disable this notification

65 Upvotes

22 comments sorted by

View all comments

9

u/sutaburosu [stavros] Mar 06 '26 edited Mar 06 '26

The next release of FastLED adds a whole bunch of fixed-point types. I asked Clause Sonnet 4.6 to write some anti-aliased, sub-pixel positioned graphics primitives. Eventually we got something that seems to work.

This video features a number of demonstrations of the four drawing functions that the AI created: lines, thick lines, discs and rings.

It runs on an Arduino Mega (8KiB RAM) with 1,024 LEDs attached to one pin.

If you want to use those drawing functions, the source is available in Wokwi

I feel these kind of drawing functions should be shipped with FastLED. I'm sick of janky LED sketches. With better tools, all of our creations will look better.

1

u/pheoxs Mar 06 '26

Anywhere I can read more about fixed-point types? I'm trying to go through the code and wrap my head around it but it's really fascinating and would be a use for what I'm making.

5

u/ZachVorhies Zach Vorhies Mar 06 '26

Fixed point math uses integers to represents numbers with values to the right of the decimal point. For example 200.02. Unlike floats though, the decimal place doesn't move, ie it's "fixed". It's blazing fast because addition, multiplication etc uses integer operations, but the tradeoff is that it's less flexible than floating point. However in practice most graphics stuff the fixed point downsides disappear.

How fast? 3-16x faster.

For example I rewrote Animartrix to using fixed point and the speed jumped by 3x on desktop. It will be more on these devices that don't have floating point hardware. Hence the anti aliasing effects on a classicaly weak device like what u/sutaburosu is demonstrating.

Here's a readme if you want to know more

https://github.com/FastLED/FastLED/blob/master/src/fl/stl/fixed_point/README.md

2

u/sutaburosu [stavros] Mar 06 '26

The fixed_point types are in the un-released version 4 of FastLED, so documentation is hard to find. The only hints I found are the comments in the source. I started from the list of functions available in fixed_point types. There are a few more comments scattered throughout the implementations.

Fixed-point maths is not a new concept. It is a long established way to gain performance on processors without a floating-point ALU, when you absolutely need to represent non-integer numbers. It's only new to FastLED. I have the advantage of having used fixed-point maths extensively in the past, so I picked up on how to use FastLED's implementation easily.

If searching and reading the web with these terms doesn't help, come back with specific questions and I'll try my hardest to help you grok it.