So I noticed it's my cake day. I wanted to put on a fireworks display for you all, but it's been a busy day and if I don't post something soon the cake will be a lie. Some leaping dots is all the entertainment I can offer you.
It's difficult to animate things smoothly on a 16x16 matrix. Sub-pixel positioning is pretty much essential. This code can display dots with 1/256th pixel resolution by smearing the light between 4 pixels, a technique devised by Xiaolin Wu. I implemented it using fixed-point arithmetic for speed.
As usual for me, the video looks terrible. You'll have to believe me when I say it doesn't look quite so ugly in real life.
This is amazing--I immediately got it working on my 8x32 flexible matrix. However, the "center" the fireworks launch from seems to be in the lower corner, (column 8) rather than the middle, for my very narrow display. I'm poking through the code, but can't see where to change the default "launch" position.
The reason you can't see it is because it ain't there.
They leap up from wherever they happen to be when they come to "rest". I'm imaging the problem is the horizontal leap velocity is too high, so they're rattling off the walls and bunching up in the corner.
Try changing the 1st non-comment line in restart_leaper() to l->xd = random8() / 3;
Who's bright idea was it to name a variable l? I worry about me sometimes...
You prompted me to dig out my largely neglected 8x32 matrix. This is the code I'm running on it now. I boosted the Y leap velocity to use the added height more effectively.
Yeah, I had already been playing with the variables before you directed me to the x-axis variable tweak. This is what I've ended up on for gravity/walls/etc.:
That's one crazy diffuser. I like it. Settled threshold is the maximum height they can bounce to before they are considered at rest. They immediately leap again when at rest.
NeoMatrix and your ArduinoOnPC powered SDL renderer look fantastic. I've been keen to play with them since you posted about them earlier this year, but hardware failure and various other demands have interfered.
Instead my attention was drawn to finishing what I had started: the opposite of NeoMatrix. I'm using multiple Nanos each driving a 256 LED panel as part of a larger matrix. They can render a couple of effects locally, or receive a 2 Mbaud serial stream from a Processing sketch to do GLSL shader live coding or stream videos. I get around 40 FPS for 1,024 LEDs, but I think my 10 year old PC's USB is the limitation there. I'll be making a post and sharing the code one day, but life is just too busy right now.
Haha, that sounds like a crazy project. So if you don't mind the question: why all this work if you can run 4096 pixels on a single ESP32 that costs less than $10 at 100fps?
One factor was having a drawer containing 5 $1.50 Nano clones and no ESP32. :D
I have a Teensy 4.1 with 16MiB PSRAM that I have barely touched. I guess I must enjoy the struggle to fit things in 2KiB RAM and get good performance out of 8-bit CPUs. I've never been a professional programmer, but two of my most cherished books are Programming Pearls and Hacker's Delight.
Have you ever been to a demoparty, Marc? After reading your blog, I think you may enjoy it. It's like a 3-day music festival, except everyone is a programmer or musician or graphic artist. Of course, we haven't been able to meet up this year, so the party venues are recreated in Unity instead.
Can't blame you for the 2KB challenge, as long as that's the fun part for you, carry on :)
Demo parties, well yes, but it's been a *long* time. I think last time was 1992 back in the days of Amstrad CPC, Atari ST(E), and Amiga 512. Cool to hear that they're still going on.
I would say the demoscene is stronger than ever (nVidia ran a party for while) and we're still using those same old computers, just with new techniques. Like 1,024 colours on the original CGA card.
Let me see if I get this right; In your sketch, your Leapers struct has the x,y coordinates of the leapers in 16bit ints. But the kMatrixHeight and width are in 8bit. So you use the bitshift >> and << to convert between them, right? (I"ve never used these operators :)
Because now of course I want to add this functionality to the sketch you helped me with the other day. And have it be able to turn really slowly and not be jumpy or glitchy, but smooth :) Going to see if I can convert it to 16bit coordinates.
I could store a length of 1.5 metres directly in a float or I could convert it to fixed-point and store it in an int as 1500 millimetres. The int holds the length in 1/1000ths of a metre; there is an imaginary decimal point 3-digits from the right.
To find the integer length in metres, you can just chop off the last 3 decimal digits. To find the fractional part in millimetres, you can read only the last 3 decimal digits.
To make it fast and easy on computers we use binary fractions rather than decimal. The Leapers position is stored in 1/256ths of a pixel; there is an imaginary binary point 8-digits from the right.
x >> 8 chops off the last 8 binary digits, giving the integer pixel position. x & 0xff reads only the last 8 binary digits, giving the fractional part in 1/256ths of a pixel.
I too wanted smoother and slower results from the XYmatrix demo. Originally
DrawOneFrame(..., yHueDelta32 / 32768, ...)
threw away 15-bits of precision at the outset. Instead, I keep full precision until the last moment:
ColorFromPalette(..., pixelHue >> 15, ...)
Wu has an algorithm for 1-pixel wide anti-aliased lines. With all that floating-point maths you'll need a powerful MCU.
Awesome. I'm definitely going to have to come back to this once I've had the chance to really dig in. Would you mind if I make a drag and drop version with your comments and post it on the sub in the future?
Question: you didn't use Wu's subpixel positioning in the scintillating_heatshrink right?
I've been trying to keep the xy array in 16bit too, so I can feed the 16 bit values to Wu's algo, and let it do the conversion to the 8bit coordinates. Does that seem like a right approach to you or not?
Nope. I only linked that to show how to increase the precision of the XYmatrix demo.
I've been trying to keep the xy array in 16bit too, so I can feed the 16 bit values to Wu's algo, and let it do the conversion to the 8bit coordinates. Does that seem like a right approach to you or not?
I'm not sure what you mean by 'XY array' (perhaps XY() function?) or what you are trying to achieve here. Could you explain a bit more please.
What I have been trying it keeping all the values, the startHue16, yHueDelta16, xHueDelta16 in 16bit, so I can feed them as 16 bit values to the wu_pixel(x, y, &color); function as 16bits and have it do the calculations to the 8bit position, as it is doing now.
Thank you so much for elaborating! Makes sense now. Between my post above and your answer I kinda figured it out. It's still glitching a bit so I'll have to take a good look at your code. And yea it makes so much sense to keep all precision until the last moment.
Thanks. It's worth being aware that it could look better. Using an appropriate gamma curve within wu_pixels() would improve the appearance. I tried earlier, but I really wanted the gamma table to be generated at compile time, but exist in progmem. That, as usual, descended into me losing another long argument with a compiler.
I just updated the gist with a bunch of bug fixes, and other polish. It runs at 100 FPS now too, even on my lowly Nano.
I'd appreciate it if you would take this new version for a test drive. There's a new XY() function, which is hopefully flexible enough to account for your matrix. If I remember your layout correctly, you'll want ArrangedByRows false and FlipMajorAxis true. Oh, and setting DRAG to 224 is the easiest way to scale the size of the leaps down to 10x10 kind of size.
Playing with animations on my DIY 13 x 45 pixel display using 30 pixel per meter WS2815 12V strip. I found your code and it works a treat! Running on ESP32 Dev board and Arduino IDE.
The ESP32 is normally running a web server and displays many animations . It also displays scrolling text from multiple directions. 10 phrases of 30 characters each. you can enter text in the website accessed Wifi using a mobile phone and it instantly changes on the display which is 1.5 meters or about 6 foot wide.
18
u/sutaburosu [stavros] Jun 12 '20
So I noticed it's my cake day. I wanted to put on a fireworks display for you all, but it's been a busy day and if I don't post something soon the cake will be a lie. Some leaping dots is all the entertainment I can offer you.
It's difficult to animate things smoothly on a 16x16 matrix. Sub-pixel positioning is pretty much essential. This code can display dots with 1/256th pixel resolution by smearing the light between 4 pixels, a technique devised by Xiaolin Wu. I implemented it using fixed-point arithmetic for speed.
As usual for me, the video looks terrible. You'll have to believe me when I say it doesn't look quite so ugly in real life.
Here's the code.
3
u/samguyer [Sam Guyer] Jun 13 '20
Very nice! It's so fun to watch.
Can I steal some of this code for use in my own project?
Also: I love fixed-point numbers. :-))
3
u/tomchaps Jun 25 '20
This is amazing--I immediately got it working on my 8x32 flexible matrix. However, the "center" the fireworks launch from seems to be in the lower corner, (column 8) rather than the middle, for my very narrow display. I'm poking through the code, but can't see where to change the default "launch" position.
3
u/marcmerlin Aug 27 '20
/u/sutaburosu
If you like fireworks, you should like this code that was floating around a while ago on the fastled group:
https://github.com/marcmerlin/FastLED_NeoMatrix_SmartMatrix_LEDMatrix_GFX_Demos/tree/master/FastLED/FireWorks2
It looks like this: https://youtu.be/WrSl1rnEOdA?t=30
Also, if you use NeoMatrix, no need to do your XY function anymore :)
3
u/costynvd Nov 30 '20
Going to resurrect this old post! :)
Let me see if I get this right; In your sketch, your Leapers struct has the x,y coordinates of the leapers in 16bit ints. But the kMatrixHeight and width are in 8bit. So you use the bitshift >> and << to convert between them, right? (I"ve never used these operators :)
Because now of course I want to add this functionality to the sketch you helped me with the other day. And have it be able to turn really slowly and not be jumpy or glitchy, but smooth :) Going to see if I can convert it to 16bit coordinates.
2
u/Preyy Ground Loops: Part of this balanced breakfast Jun 12 '20
Very cool implementation. I might have bake this in to future projects. Thanks for sharing.
2
u/ldirko Jun 14 '20
Cool! Very smooth. Where I can read in detail about this algorithm?
2
u/lgpcrevette Jun 15 '20
UwU very cool anim. How I can return the animation to be in the right way for me because it's up side down now ?
3
u/Marmilicious [Marc Miller] Jun 13 '20
Love this. Really fun! Thank you for sharing it.
3
u/KeithHirst Jan 04 '23
Playing with animations on my DIY 13 x 45 pixel display using 30 pixel per meter WS2815 12V strip. I found your code and it works a treat! Running on ESP32 Dev board and Arduino IDE.
https://youtu.be/nkdapbCeXhg
The ESP32 is normally running a web server and displays many animations . It also displays scrolling text from multiple directions. 10 phrases of 30 characters each. you can enter text in the website accessed Wifi using a mobile phone and it instantly changes on the display which is 1.5 meters or about 6 foot wide.
2
u/jazzFromMars Jun 12 '20
Nice. That's an impressive effect for such compact code.