{"id":21173433,"url":"https://github.com/jinatonic/confetti","last_synced_at":"2025-04-08T13:04:18.576Z","repository":{"id":45243703,"uuid":"66060256","full_name":"jinatonic/confetti","owner":"jinatonic","description":"An Android particle system library for displaying confetti!","archived":false,"fork":false,"pushed_at":"2020-08-31T16:49:07.000Z","size":2467,"stargazers_count":1312,"open_issues_count":13,"forks_count":150,"subscribers_count":31,"default_branch":"master","last_synced_at":"2025-04-01T12:01:43.432Z","etag":null,"topics":["android","android-animation","android-ui","particle-system"],"latest_commit_sha":null,"homepage":"https://medium.com/@jinatonic/its-parfetti-time-f40634472608","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jinatonic.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-08-19T06:57:38.000Z","updated_at":"2025-03-16T04:06:36.000Z","dependencies_parsed_at":"2022-09-25T03:24:38.033Z","dependency_job_id":null,"html_url":"https://github.com/jinatonic/confetti","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jinatonic%2Fconfetti","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jinatonic%2Fconfetti/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jinatonic%2Fconfetti/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jinatonic%2Fconfetti/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jinatonic","download_url":"https://codeload.github.com/jinatonic/confetti/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247847607,"owners_count":21006099,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["android","android-animation","android-ui","particle-system"],"created_at":"2024-11-20T16:37:12.818Z","updated_at":"2025-04-08T13:04:18.527Z","avatar_url":"https://github.com/jinatonic.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"![](https://github.com/jinatonic/confetti/blob/master/assets/confetti_with_touch.gif)\n![](https://github.com/jinatonic/confetti/blob/master/assets/falling_confetti_top.gif)\n![](https://github.com/jinatonic/confetti/blob/master/assets/explosion_confetti.gif)\n![](https://github.com/jinatonic/confetti/blob/master/assets/falling_confetti_point.gif)\n\nWhat is Confetti?\n=================\n\n*Confetti (plural) vs confetto (singular)*\n\n[Confetti](https://en.wikipedia.org/wiki/Confetti) is a high-performance, easily-configurable\nparticle system library that can animate any set of objects through space. You can specify your\nstarting conditions and physical conditions (e.g. X and Y acceleration, boundaries, etc.),\nand let the confetti library take care of the rest.\n\n\nGetting started\n---------------\n\nAdd the confetti dependency to your `build.gradle`.\n\n```groovy\nimplementation 'com.github.jinatonic.confetti:confetti:1.1.2'\n```\n\n\nSimple usage\n------------\n\nThe only thing you need to get confetti on your screen is a parent view to host the `ConfettiView`\nand thus the confetti animation. From this point on, this parent view is referred to as `container`.\n\nPlease note that the library uses measurements from `container` to figure out how to best animate\nthe confetti. If the `container` is not measured when creating the confetti, then nothing will\nshow up on the screen. A common pitfall is creating confetti inside activity lifecycle as the views\nare most likely not measured at those points.\n\nYou can generate pre-configured confetti from `CommonConfetti`. You only need to provide it with\nthe parent `container`, a `ConfettiSource`, and an array of possible colors for the confetti.\nThe default confetti shapes are circle, triangle, and square.\n\n```java\nCommonConfetti.rainingConfetti(container, new int[] { Color.BLACK })\n        .infinite();\n```\n\n\nMore custom usage\n-----------------\n\nFirst, we need to define what our individual [confetto](http://www.dictionary.com/browse/confetto)\nis through the `ConfettoGenerator`. Each call of `generateConfetto` must generate a brand new\n`Confetto` object (the `ConfettiManager` will recycle the generated confetto as needed so you\nmight see fewer and fewer calls to `generateConfetto` as the animation goes on). We pass in a\n`Random` into `generateConfetto` in case you want to randomly generate a confetto from a list\nof possible confetti.\n\nA simple `ConfettoGenerator` might look like this:\n\n```java\nfinal List\u003cBitmap\u003e allPossibleConfetti = constructBitmapsForConfetti();\n// Alternatively, we provide some helper methods inside `Utils` to generate square, circle,\n// and triangle bitmaps.\n// Utils.generateConfettiBitmaps(new int[] { Color.BLACK }, 20 /* size */);\n\nfinal int numConfetti = allPossibleConfetti.size();\nfinal ConfettoGenerator confettoGenerator = new ConfettoGenerator() {\n    @Override\n    public Confetto generateConfetto(Random random) {\n        final Bitmap bitmap = allPossibleConfetti.get(random.nextInt(numConfetti));\n        return new BitmapConfetto(bitmap);\n    }\n}\n```\n\nOnce we have our `ConfettoGenerator`, we'll need to define a `ConfettiSource` from which confetti\nwill appear out of. This source can be any arbitrary point or line.\n\n```java\nfinal int containerMiddleX = container.getWidth() / 2;\nfinal int containerMiddleY = container.getHeight() / 2;\nfinal ConfettiSource confettiSource = new ConfettiSource(containerMiddleX, containerMiddleY);\n```\n\nNow you are ready! construct your `ConfettiManager`, configure the animation to your liking, and\nthen call `animate()`!\n\n```java\nnew ConfettiManager(context, confettoGenerator, confettiSource, container)\n        .setEmissionDuration(1000)\n        .setEmissionRate(100)\n        .setVelocityX(20, 10)\n        .setVelocityY(100)\n        .setRotationalVelocity(180, 180)\n        .animate();\n```\n\nThe `animate()` call will create and configure the various `Confetto` objects on demand,\ncreate a new `ConfettiView`, initialize the proper states for all of the components, attach the\nview to the `container` and start the animation. The `ConfettiView` will auto-detach itself once\nall of the confetti have terminated and are off the screen.\n\nFor more sample usage of the library, please check out the\n[confetti-sample](https://github.com/jinatonic/confetti/tree/master/confetti-sample) app that's\nincluded in this project.\n\n\nConfiguration\n-------------\n\nThe `ConfettiManager` is easily configurable. For simplicity's sake, all of the velocity and\nacceleration attributes are in pixels per second or pixels per second^2, whereas all of the raw\ntime attributes (such as `ttl` and `emissionDuration`) are in milliseconds.\n\nYou will notice that most of the setters for the physical attributes (e.g. velocity, acceleration,\nrotation) can take in either one argument for the actual value or two arguments. The second\nargument allows you to specify a random deviation if you want to randomize the behavior among\nall of the generated confetto.\n\nFor example:\n\n```java\nconfettiManager.setVelocityX(200f, 50f);\n```\n\nThe generated confetto will have an initial X velocity of anywhere between `200 - 50` or `150` and\n`200 + 50` or `250`, eventually distributed.\n\n`enableFadeOut(Interpolator fadeOutInterpolator)` is another interesting method. You can specify\nthat fade out occurs as a confetto nears its boundary (either reaching the physical boundary\nspecified in `bound` (this is either the entirety of `container` or set in `setBound`) or reaching\n`ttl`). The interpolator essentially takes in a value between 0 and 1 (0 means that the confetto\nis at its source, 1 means the confetto is at its bound) and outputs an alpha value between 0 and 1\n(0 is transparent and 1 is opaque). This way, we allow you to have the full power of specifying\nhow the fade out occurs.\n\nOr, if you are lazy, you can just use `Utils.getDefaultAlphaInterpolator()`.\n\n\nAdvanced usage\n==============\n\nEnable touch and drag\n---------------------\n\nIf you call `confettiManager.setTouchEnabled(true)`, you can allow the user to touch and drag\nthe confetti that are on the screen. When the user let go of the confetti, the confetti will\nstart at that location with the user initiated velocity and the pre-configured acceleration\nand resume animation from there.\n\n\nCustom Confetto\n---------------\n\nIt's very easy to define a custom `Confetto` (see `BitmapConfetto`). You simply need to extend\nfrom the `Confetto` class and implement `drawInternal`. The function will provide you with a\n`Canvas` to draw on as well as a work `Matrix` and `Paint` so you don't have to allocate objects\nin the draw path. You then need to essentially draw your confetto however you want onto the canvas\nusing the specified `x`, `y`, and `rotation`.\n\nThe cool part is that you can interpret `rotation` however you want. Instead of an angle in degrees,\nyou can choose to interpret rotation where each degree corresponds to a new shape or new image.\nThis way, you can achieve some cool animation effects as the confetti flow through the screen.\n\n\nChanging confetti configuration mid-animation\n---------------------------------------------\n\nIf you have a handle on the `ConfettiManager`, you can actually very easily change the configuration\nmid-animation for more unique experiences. For example:\n\n```java\nconfettiManager.setEmissionRate(100)\n        .animate();\n\nnew Handler().postDelayed(new Runnable() {\n    @Override public void run() {\n        confettiManager.setEmissionRate(20);\n    }\n}, 3000);\n```\n\nThe above snippet will configure the initial emission rate to be 100 confetti per second and start\nthe animation. After 3 seconds, it will reduce the emission rate to 20 confetti per second. This \napplies to all attributes (e.g. changing velocity or acceleration based on some outside condition).\n\n\nFuture development\n==================\n\n* Add more samples and pre-configured confetti into `CommonConfetti`.\n\n\nLicense\n=======\n\n    Copyright 2016 Robinhood Markets, Inc.\n\n    Licensed under the Apache License, Version 2.0 (the \"License\");\n    you may not use this file except in compliance with the License.\n    You may obtain a copy of the License at\n\n       http://www.apache.org/licenses/LICENSE-2.0\n\n    Unless required by applicable law or agreed to in writing, software\n    distributed under the License is distributed on an \"AS IS\" BASIS,\n    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n    See the License for the specific language governing permissions and\n    limitations under the License.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjinatonic%2Fconfetti","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjinatonic%2Fconfetti","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjinatonic%2Fconfetti/lists"}