When dealing with circles (or closed loops, or donuts or…), this avoids the start or end of the led strand from being an edge/end and calculates the distance as if it wasn’t…
It finds the shortest distance between two points, when there is more than one direction you could go.
oh cool! This is my first time coding for pixelblaze, I’ll play around with triangle() - not that this pattern needs to be performant, but are there speed differences that mean I should use internal functions vs doing it myself?
alas, I couldn’t figure out a way to use triangle() to make this wrap around behavior. I think it’s possible, somehow stretching the triangle, but I couldn’t think of it last night, so it’ll stay with the if statement for now.
Yeah, I racked my brain to convert your code to it. I believe (and hopefully @wizard will correct me if I’m wrong) triangle() will (in essence) convert 0-0.5 values to 0-1 (effectively multiply by 2), and convert .5-1 values to 1-0 (= 2 - value x2)
Your code says “if distance is greater than .5, distance is equal to 1 - distance” so you’re have to divide triangle(distance) by two to get your desired result.
@danner your version is great! I didn’t mean that as a criticism, I think its awesome that you figured out how to get the effect you were looking for!
I wanted to share that triangle does that same kind of thing – ramps up, then back down (just scaled to 0-1) – in case it comes in handy for you later. I use that kind of thing so often it became one of the original Pixelblaze animation tools / APIs.
You can see a similar thing in “fast pulse,” which will wrap, the core if that pattern (for 1D) is this:
v = triangle(2 * wave(t1) + index / pixelCount)
The base structure of the triangle is triangle(index/pixelCount) which would start low, go high toward the middle, and back down.
It animates that back and forth by adding this offset: 2 * wave(t1), which is like changing the spotlight’s position with a slider but animates based on the t1 timer. The * 2 causes to to spin twice over before returning, and triangle() wraps values to the 0-1 range so you can keep adding in components.