Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for Confetti modifiers #257

Open
teobaranga opened this issue Mar 3, 2021 · 1 comment
Open

Add support for Confetti modifiers #257

teobaranga opened this issue Mar 3, 2021 · 1 comment
Labels

Comments

@teobaranga
Copy link

Hi! I've recently started using this library and it works great! I did come across a scenario which currently isn't supported by the library but which could be a great addition. I am trying to add a fade in effect to each particle and, while this could be implemented specifically, I believe a more generic approach may be better. What I had in mind is adding support for confetti modifiers, which is essentially behaviour that is applied to each confetti individually right before it is drawn on the Canvas.

This would involve adding an interface such as

interface ConfettiModifier {
    fun apply(confetti: Confetti)
}

A list of such modifiers can be provided by consumers when building the ParticleSystem which can then be propagated down to the Confetti level.

The modifiers would then be applied before the shape is drawn, following something like

class Confetti(
    ...
    val modifiers: List<ConfettiModifier> = emptyList(),
) {
    ...
    private fun display(canvas: Canvas) {
        ...
        for (modifier in modifiers) {
            modifier.apply(confetti = this)
        }
        shape.draw(canvas, paint, width)
        ...
    }
}

The modifiers themselves would need access to properties that are currently private so that constraint would need to be relaxed. For this particular fading in scenario, the paint property would need to be public.

The above code sample is simply a suggestion but I am happy to open a PR or discuss this further if this is something of interest!

Thanks!

@DanielMartinus
Copy link
Owner

DanielMartinus commented Apr 8, 2021

Interesting idea @teobaranga! The use case you give with modifying the alpha sounds like a good one indeed. Though it would become complex when doing any internal modifications later and the unforeseen complications it will have on everyone who's using Modifiers. I.e. the alpha value is currently tightly coupled with lifetime, that should in some way act in a separate way.
If in the future anything changes on the alpha calculations it will be hard to test what it will do with anyone who's implementing modifications, what do you think?

I love the idea though for having a way to alter the deeply nested properties for own use by an abstraction like you suggested.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants