Convert Figma logo to code with AI

plattysoft logoLeonids

A Particle System for standard Android UI: http://plattysoft.github.io/Leonids/

2,277
398
2,277
44

Top Related Projects

It's a cool animation which can use in splash or somewhere else.

Bubbles for Android is an Android library to provide chat heads capabilities on your apps. With a fast way to integrate with your development.

2,710

Configurable animations based on points

一个用粒子动画显示文字的 Android 自定义 View

Quick Overview

Leonids is an Android library for creating particle systems and animations. It allows developers to easily add visually appealing particle effects to their Android applications, such as explosions, fireworks, or other dynamic visual elements.

Pros

  • Easy to use and integrate into existing Android projects
  • Highly customizable, allowing for a wide range of particle effects
  • Lightweight and efficient, with minimal impact on app performance
  • Supports both one-shot and continuous particle animations

Cons

  • Limited documentation and examples available
  • Not actively maintained (last update was in 2019)
  • May require additional work to adapt to newer Android versions
  • Lacks advanced features found in some commercial particle system libraries

Code Examples

  1. Creating a simple particle system:
val particleSystem = ParticleSystem(this, 80, R.drawable.star_pink, 10000)
particleSystem.setScaleRange(0.7f, 1.3f)
particleSystem.setSpeedRange(0.1f, 0.25f)
particleSystem.oneShot(anchor, 100)
  1. Creating a confetti effect:
val confetti = ParticleSystem(this, 80, R.drawable.confetti, 10000)
confetti.setSpeedRange(0.1f, 0.25f)
confetti.setRotationSpeedRange(90f, 180f)
confetti.setScaleRange(0.7f, 1.3f)
confetti.oneShot(anchor, 100)
  1. Creating a continuous emission:
val emitter = ParticleSystem(this, 100, R.drawable.star_white, 3000)
emitter.setSpeedRange(0.1f, 0.25f)
emitter.setAcceleration(0.0001f, 90)
emitter.setRotationSpeedRange(90f, 180f)
emitter.setScaleRange(0.4f, 1.2f)
emitter.emit(anchor, 8)

Getting Started

  1. Add the Leonids dependency to your app's build.gradle file:
dependencies {
    implementation 'com.plattysoft.leonids:LeonidsLib:1.3.2'
}
  1. In your activity or fragment, create a ParticleSystem instance:
val particleSystem = ParticleSystem(this, 80, R.drawable.star_pink, 10000)
  1. Customize the particle system properties:
particleSystem.setScaleRange(0.7f, 1.3f)
particleSystem.setSpeedRange(0.1f, 0.25f)
  1. Trigger the particle animation:
particleSystem.oneShot(anchorView, 100)

Competitor Comparisons

It's a cool animation which can use in splash or somewhere else.

Pros of Particle

  • More customizable particle effects with various shapes and behaviors
  • Supports 3D particle animations
  • Includes pre-built effects like explosions and fireworks

Cons of Particle

  • Steeper learning curve due to more complex API
  • Potentially higher performance overhead for complex animations
  • Less frequent updates and maintenance

Code Comparison

Leonids:

new ParticleSystem(this, 80, R.drawable.star_pink, 10000)
    .setSpeedRange(0.1f, 0.25f)
    .oneShot(anchorView, 100);

Particle:

ParticleSystem ps = new ParticleSystem(this, 100, R.drawable.star, 800);
ps.setScaleRange(0.7f, 1.3f);
ps.setSpeedRange(0.1f, 0.25f);
ps.setRotationSpeedRange(90, 180);
ps.setFadeOut(200, new AccelerateInterpolator());
ps.oneShot(button, 100);

Both libraries offer particle system functionality for Android applications, but Particle provides more advanced features and customization options. Leonids, on the other hand, offers a simpler API and may be easier to implement for basic particle effects. The code comparison shows that Particle requires more configuration to achieve similar results, but also allows for more detailed control over particle behavior.

Bubbles for Android is an Android library to provide chat heads capabilities on your apps. With a fast way to integrate with your development.

Pros of bubbles-for-android

  • Focuses specifically on creating bubble-like animations
  • Provides a more customizable bubble animation system
  • Offers a simpler API for implementing bubble effects

Cons of bubbles-for-android

  • Limited to bubble animations, less versatile than Leonids
  • Less actively maintained (last update in 2017)
  • Fewer stars and forks on GitHub, indicating potentially less community support

Code Comparison

Leonids:

new ParticleSystem(this, 80, R.drawable.star_pink, 10000)
    .setSpeedRange(0.1f, 0.25f)
    .oneShot(anchor, 100);

bubbles-for-android:

BubbleLayout bubbleLayout = new BubbleLayout(this);
bubbleLayout.setBackground(ContextCompat.getDrawable(this, R.drawable.bubble_background));
bubbleLayout.setSizeRatio(0.3f);

Both libraries offer relatively simple APIs for creating particle-like effects, but Leonids provides more flexibility for different types of particles and animations, while bubbles-for-android is more focused on creating bubble-specific animations with customizable properties.

Leonids is more actively maintained and has a larger community following, making it potentially more suitable for long-term projects. However, if the specific goal is to create bubble animations, bubbles-for-android might offer a more tailored solution with its bubble-focused API.

2,710

Configurable animations based on points

Pros of Grav

  • More customizable particle animations with support for various shapes and behaviors
  • Offers a wider range of animation effects, including gravity and collision simulations
  • Provides a more modern and visually appealing particle system

Cons of Grav

  • Potentially higher performance overhead due to more complex animations
  • Steeper learning curve for implementation compared to Leonids
  • May require more configuration to achieve desired effects

Code Comparison

Leonids:

new ParticleSystem(this, numParticles, R.drawable.star_pink)
    .setSpeedRange(0.1f, 0.25f)
    .setRotationSpeedRange(90, 180)
    .oneShot(anchorView, numParticles);

Grav:

GravView gravView = new GravView(this);
gravView.setGenerator(new PointGenerator(100));
gravView.setParticle(new BallParticle());
gravView.addAnimator(new FadeOutAnimator());
setContentView(gravView);

Both libraries offer particle system animations for Android, but Grav provides more advanced features and customization options at the cost of increased complexity. Leonids is simpler to implement and may be more suitable for basic particle effects, while Grav excels in creating more sophisticated and visually striking animations.

一个用粒子动画显示文字的 Android 自定义 View

Pros of ParticleTextView

  • Focuses specifically on text-based particle effects
  • Provides more customization options for text animations
  • Offers smoother transitions between particle states

Cons of ParticleTextView

  • Limited to text-based particle effects, less versatile than Leonids
  • Requires more setup and configuration for basic particle effects
  • Less actively maintained, with fewer recent updates

Code Comparison

ParticleTextView:

ParticleTextView particleTextView = findViewById(R.id.particleTextView);
particleTextView.setTargetText("Hello, World!");
particleTextView.startAnimation();

Leonids:

new ParticleSystem(this, 80, R.drawable.star_pink, 10000)
    .setSpeedRange(0.1f, 0.25f)
    .oneShot(anchor, 100);

ParticleTextView is more focused on text-based particle effects, offering greater customization for text animations. However, it's less versatile and requires more setup than Leonids. Leonids provides a simpler API for general particle effects and is more actively maintained.

ParticleTextView's code example shows how to set up a text-based particle animation, while Leonids' example demonstrates creating a general particle system with customizable properties. Leonids offers a more straightforward approach for implementing various particle effects, making it easier to use for general purposes.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

Leonids

Badge

Leonids is a particle system library that works with the standard Android UI.

The library is extremely lightweight, LeonidsLib.jar is just 81Kb.

You can download Leonids Demo from Google Play to check out what can be done with it.

Setup

Leonids is available in jcenter as well as a jar file to fit both Android Studio and Eclipse.

Android Studio / gradle

Add the following dependency to the build.gradle of your project

dependencies {
    compile 'com.plattysoft.leonids:LeonidsLib:1.3.2'
}

Note: If you get an error, you may need to update the jcenter repository to:

repositories {
    jcenter{
        url "http://jcenter.bintray.com/"
    }
}

Eclipse / jar file

Just put LeonidsLib.jar into the libs folder of your app.

Why this library?

Particle systems are often used in games for a wide range of purposes: Explosions, fire, smoke, etc. This effects can also be used on normal apps to add an element of "juiciness" or Playful Design.

Precisely because its main use is games, all engines have support for particle systems, but there is no such thing for standard Android UI.

This means that if you are building an Android app and you want a particle system, you have to include a graphics engine and use OpenGL -which is quite an overkill- or you have to implement it yourself.

Leonids is made to fill this gap, bringing particle sytems to developers that use the standard Android UI.

Basic usage

Creating and firing a one-shot particle system is very easy, just 3 lines of code.

new ParticleSystem(this, numParticles, drawableResId, timeToLive)
.setSpeedRange(0.2f, 0.5f)
.oneShot(anchorView, numParticles);

Note that the ParticleSystem checks the position of the anchor view when oneShot (or emit) is called, so it requires the views to be measured. This means that ParticleSystem won't work properly if you call oneShot or emit during onCreate. For more information check the comments on issue #22.

When you create the particle system, you tell how many particles will it use as a maximum, the resourceId of the drawable you want to use for the particles and for how long the particles will live.

Then you configure the particle system. In this case we specify that the particles will have a speed between 0.2 and 0.5 pixels per milisecond (support for dips will be included in the future). Since we did not provide an angle range, it will be considered as "any angle".

Finally, we call oneShot, passing the view from which the particles will be launched and saying how many particles we want to be shot.

Emitters

You can configure emitters, which have a constant ratio of particles being emited per second. This is the code for the Confeti example:

new ParticleSystem(this, 80, R.drawable.confeti2, 10000)
.setSpeedModuleAndAngleRange(0f, 0.3f, 180, 180)
.setRotationSpeed(144)
.setAcceleration(0.00005f, 90)
.emit(findViewById(R.id.emiter_top_right), 8);

new ParticleSystem(this, 80, R.drawable.confeti3, 10000)
.setSpeedModuleAndAngleRange(0f, 0.3f, 0, 0)
.setRotationSpeed(144)
.setAcceleration(0.00005f, 90)
.emit(findViewById(R.id.emiter_top_left), 8);

It uses an initializer for the Speed as module and angle ranges, a fixed speed rotaion and extenal acceleration.

Available Methods

List of the methods available on the class ParticleSystem.

Constructors

All constructors use the activity, the maximum number of particles and the time to live. The difference is in how the image for the particles is specified.

Supported drawables are: BitmapDrawable and AnimationDrawable.

  • ParticleSystem(Activity a, int maxParticles, int drawableRedId, long timeToLive)
  • ParticleSystem(Activity a, int maxParticles, Drawable drawable, long timeToLive)
  • ParticleSystem(Activity a, int maxParticles, Bitmap bitmap, long timeToLive)
  • ParticleSystem(Activity a, int maxParticles, AnimationDrawable animation, long timeToLive)

There are also constructors that recieve a view id to use as the parent so you can put the particle system on the background (or between any two views)

  • ParticleSystem(Activity a, int maxParticles, int drawableRedId, long timeToLive, int parentViewId)
  • ParticleSystem(Activity a, int maxParticles, Drawable drawable, long timeToLive, int parentViewId)
  • ParticleSystem(Activity a, int maxParticles, Bitmap bitmap, long timeToLive, int parentViewId)
  • ParticleSystem(Activity a, int maxParticles, AnimationDrawable animation, long timeToLive, int parentViewId)

And another constructor that receives a parent viewgroup and drawable for use in places where it is not practical to pass a reference to an Activity

  • ParticleSystem(ViewGroup parentView, int maxParticles, Drawable drawable, long timeToLive)

Configuration

Available methods on the Particle system for configuration are:

  • setSpeedRange(float speedMin, float speedMax): Uses 0-360 as the angle range
  • setSpeedModuleAndAngleRange(float speedMin, float speedMax, int minAngle, int maxAngle)
  • setSpeedByComponentsRange(float speedMinX, float speedMaxX, float speedMinY, float speedMaxY)
  • setInitialRotationRange (int minAngle, int maxAngle)
  • setScaleRange(float minScale, float maxScale)
  • setRotationSpeed(float rotationSpeed)
  • setRotationSpeedRange(float minRotationSpeed, float maxRotationSpeed)
  • setAcceleration(float acceleration, float angle)
  • setFadeOut(long milisecondsBeforeEnd, Interpolator interpolator): Utility method for a simple fade out effect using an interpolator
  • setFadeOut(long duration):Utility method for a simple fade out

You can start the particle system "in the future" if you want to have the particles already created and moving using

setStartTime(int time)

For more complex modifiers, you can use the method addModifier(ParticleModifier modifier). Available modifiers are:

  • AlphaModifier (int initialValue, int finalValue, long startMilis, long endMilis)
  • AlphaModifier (int initialValue, int finalValue, long startMilis, long endMilis, Interpolator interpolator)
  • ScaleModifier (float initialValue, float finalValue, long startMilis, long endMilis)
  • ScaleModifier (float initialValue, float finalValue, long startMilis, long endMilis, Interpolator interpolator)

One shot

Make one shot using from the anchor view using the number of particles specified, an interpolator is optional

  • oneShot(View anchor, int numParticles)
  • oneShot(View anchor, int numParticles, Interpolator interpolator)

Emitters

Emits the number of particles per second from the emitter. If emittingTime is set, the emitter stops after that time, otherwise it is continuous.

Basic emitters

  • emit (View emitter, int particlesPerSecond)
  • emit (View emitter, int particlesPerSecond, int emittingTime)

Emit based on (x,y) coordinates

  • emit (int emitterX, int emitterY, int particlesPerSecond)
  • emit (int emitterX, int emitterY, int particlesPerSecond, int emitingTime)

Emit with Gravity

  • emitWithGravity (View emiter, int gravity, int particlesPerSecond)
  • emitWithGravity (View emiter, int gravity, int particlesPerSecond, int emitingTime)

Update, stop, and cancel

  • updateEmitPoint (int emitterX, int emitterY) Updates dynamically the point of emission.
  • updateEmitPoint (View emiter, int gravity) Updates dynamically the point of emission using gravity.
  • stopEmitting () Stops the emission of new particles, but the active ones are updated.
  • cancel () Stops the emission of new particles and cancles the active ones.

Other details

Leonids requires minSDK 11 because it uses ValueAnimators. It should be very easy, however to use nineoldandroids and make it work on Gingerbread.

The library is Free Software, you can use it, extended with no requirement to open source your changes. You can also make paid apps using it.

Each Particle System only uses one image for the particles. If you want different particles to be emitted, you need to create a Particle System for each one of them.