Git Product home page Git Product logo

konfetti's Introduction

Konfetti ๐ŸŽŠ


License API level 16 API level 16 API level 16 Build Status

๐Ÿฅณ Celebrate more with this lightweight confetti particle system. Create realistic confetti by implementing this easy to use library.

Demo app

Sample app

Download on Google Play:

Android app on Google Play

Or download the APK here

Usage

XML

All you need in your layout is the KonfettiView to render the particles on:

<nl.dionsegijn.konfetti.KonfettiView
        android:id="@+id/viewKonfetti"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />

Example in Kotlin

viewKonfetti.build()
    .addColors(Color.YELLOW, Color.GREEN, Color.MAGENTA)
    .setDirection(0.0, 359.0)
    .setSpeed(1f, 5f)
    .setFadeOutEnabled(true)
    .setTimeToLive(2000L)
    .addShapes(Shape.Square, Shape.Circle)
    .addSizes(Size(12))
    .setPosition(-50f, viewKonfetti.width + 50f, -50f, -50f)
    .streamFor(300, 5000L)

Example in Java

final KonfettiView konfettiView = findViewById(R.id.konfettiView);
konfettiView.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(final View view) {
        konfettiView.build()
                .addColors(Color.YELLOW, Color.GREEN, Color.MAGENTA)
                .setDirection(0.0, 359.0)
                .setSpeed(1f, 5f)
                .setFadeOutEnabled(true)
                .setTimeToLive(2000L)
                .addShapes(Shape.Square.INSTANCE, Shape.Circle.INSTANCE)
                .addSizes(new Size(12, 5f))
                .setPosition(-50f, konfettiView.getWidth() + 50f, -50f, -50f)
                .streamFor(300, 5000L);
    }
});

See sample code here: https://github.com/DanielMartinus/Konfetti/blob/main/demo-simple-java/src/main/java/nl/dionsegijn/simple_demo/MainActivity.java

Custom shapes

Add a custom shape by using:

Shape.DrawableShape(drawable: Drawable)

The 3D flip effect works best for symmetrical shapes, for example a drawable with a width and a height of 24x24.

Indefinite streams

Stream for an indefinite amount of time using StreamEmitter.INDEFINITE

viewKonfetti.build()
    ...
    .streamFor(particlesPerSecond = 300, emittingTime = StreamEmitter.INDEFINITE)

The only way to stop streams that run for an indefinite amount of time is either by calling:

Reset

Call reset to immediately stop rendering all particles.

viewKonfetti.reset()

stopGracefully

Call this function to stop rendering new particles. The ones visible will live out their lifetime.

viewKonfetti.stopGracefully()

Download

Add the following dependency in your app's build.gradle

dependencies {
      implementation 'nl.dionsegijn:konfetti:1.3.2'
}

Download

Java project

If you haven't configured Kotlin for your Java only project, add the following to your project:

implementation 'org.jetbrains.kotlin:kotlin-stdlib-jdk7:$latest_version'

Read more about the latest version and kotlin via gradle here: https://kotlinlang.org/docs/reference/using-gradle.html

Community

Need help or want to receive the latest updates? Join the telegram groups:

Contribute

There is always room for improvement.

Report issue

Did you encounter bugs? Report them here. The more relevant information you provide the easier and faster it can be resolved.

Contribute

As mentioned, there is always room for improvement. Do you have any performance improvement ideas? Please suggest them here. Before submitting a large Pull Request, creating an issue to discuss your ideas would be the preferred way so we can be sure it is in line with other improvements currently being developed. Is it a simple improvement? Go ahead and submit a Pull Request! I very welcome any contributions.

Roadmap

In line with the previous contribute section there are some already known issues that could be resolved and are open for discussion.

  • Determining the size of the particles in the current implementation is not ideal. More here: #7 Confetti size system
  • A performance improvement to the library could for one be to implement a shared object pool amongst all particle systems instead of having them to handle confetti instances themselves.

License

Konfetti is released under the ISC license. See LICENSE for details.

konfetti's People

Contributors

danielmartinus avatar dependabot-preview[bot] avatar jurriaan avatar carlfindahl avatar mattprecious avatar konfetti-bot avatar alexbirkett avatar jaeheonshim avatar kevinrob avatar foxware00 avatar uwemaurer avatar benju69 avatar learnice avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.