Future of Gradient / Color Interpolation #218
Replies: 4 comments 9 replies
-
Thank you for this write-up! I agree completely regarding outsourcing anything more complex than linear gradients (or even just equidistant gradients). I would prefer it if this library can stay as focused on the color spaces and their direct operations as much possible, which is why I have had similar thoughts, and I'm open for scaling down the scope were possible. The Integrating with external crates seem to work through three methods:
What I want to say with that is that we need to decide if Palette should support the third party libraries or if the third party libraries have to support Palette integration. A model where Palette dictates the API could include a I think it would be neat if it would be possible to be compatible in both directions. If Palette could implement some common traits that make the colors usable in completely agnostic third party crates, but Palette could also provide some quality of life methods if the gradient type implements a particular gradient trait. That is, if third party gradients aren't already more feature rich, in which case I'm more than happy to leave it to them. |
Beta Was this translation helpful? Give feedback.
-
Hey, I saw your https://github.com/NicolasKlenert/enterpolation crate earlier and it looks really good! I would happily recommend it as sort of a "companion crate" that works well with Palette, and strip down or even remove the built-in gradient type. 😄 I may add implementations of |
Beta Was this translation helpful? Give feedback.
-
I have finally opened #301 to axe the gradient module. Let me know if I made any mistakes with |
Beta Was this translation helpful? Give feedback.
-
Hi, I just noticed that some code I had stopped compiling, and searched around for a while thinking that there might be a new feature flag, or that the crate had split into 2 parts. Would it be possible to add into the README a comment explaining this change, and possibly a reference to an example or 2 to recreate the original gradients... |
Beta Was this translation helpful? Give feedback.
-
Features
So I thought and learned a lot about interpolation methods recently and how the
Gradient
struct could be improved upon. To be on the same page, here are some features one could consider:Some of these are definitly overkill for this crate. Such a possible extern crate may be already necessary for specific use cases.
Example
Let's assume we want to implement a Bezier Curve. The algorithm itself and it's representation are rather easy to implement. However our curve may seem nice at first, but Bezier Curves don't have a "constant speed" over the curve. That is, our resulting gradient may change it's color drastically at some point and almost not at all at other points. The same would be true of the linear implementation of the
Gradient
right now if it wouldn't have customised positions (from now on I'll call them knots). However it's not possible to use the same technic for bezier curves (BSplines do have knots, but they don't solve our problem). To achieve a constant change over the curve one can do an approximation and create a lookup table. In the end, one generates a linear interpolation over many equidistant sample points. (This is also the reason the constant gradients we (and matlab) use are given as a linear interpolation, even though they are basically curves.)How would an extern crate work
For the usual interpolation methods and structures the elements which should be interpolated only have to have two traits:
Mix
trait)Such a good extern crate would only need these two traits to be implemented and then work out of the box. The only question left would be what happens to the constant gradients. I think the best option here would be to implement a linear interpolation for equidistant points/colors (if the extern crate is not used) and implement them that way. These would also have the benefit of a slight performance boost, as the implementation could create a color in
O(1)
instead ofO(log n)
, ifn
is the number of colors, as no binary search of the right knots would be necessary.Opinion
In my opinion, it seems like a good idea to outsource interpolation and point to an interpolation crate, as doing interpolation right can be rather hard and may blow the scope of this crate. However these are only my thoughts, so I would appreciate any discussion about it.
Beta Was this translation helpful? Give feedback.
All reactions