All Projects → CuriousNikhil → compose-particle-system

CuriousNikhil / compose-particle-system

Licence: Apache-2.0 License
A lightweight particle system for Jetpack Compose - Quarks

Programming Languages

kotlin
9241 projects

Projects that are alternatives of or similar to compose-particle-system

MovieBox
TMDb + Kotlin + Coroutines + Retrofit2 + Moshi + Clean Architecture + Koin 2 + Glide
Stars: ✭ 46 (+53.33%)
Mutual labels:  jetpack-compose
Zoomable
Easy zoom in and out with drag support for Jetpack Compose
Stars: ✭ 35 (+16.67%)
Mutual labels:  jetpack-compose
ComposedBarcodes
No description or website provided.
Stars: ✭ 44 (+46.67%)
Mutual labels:  jetpack-compose
bitcoin-market-android
Bitcoin Market app shows you the current Bitcoin market price and price chart of different time intervals 💰
Stars: ✭ 284 (+846.67%)
Mutual labels:  jetpack-compose
TelegramExample
A telegram client for android created using tdlib library and built with Jetpack Compose
Stars: ✭ 35 (+16.67%)
Mutual labels:  jetpack-compose
breakout-compose
Breakout clone built with Compose
Stars: ✭ 27 (-10%)
Mutual labels:  jetpack-compose
ToDometer Multiplatform
WIP Kotlin Multiplatform project: A meter to-do list built with Android Jetpack, Compose UI Multiplatform, Wear Compose, SQLDelight, Koin Multiplatform, SwiftUI, Ktor Server / Client, Exposed...
Stars: ✭ 145 (+383.33%)
Mutual labels:  jetpack-compose
navigation-with-animated-transitions-using-jetpack-compose
DEPRECATED - Demonstates how to create animated transitions to and from screens using Jetpack Compose.
Stars: ✭ 31 (+3.33%)
Mutual labels:  jetpack-compose
Lastik
Kotlin Multiplatform + Jetpack Compose pet project, based on www.last.fm/api (in development)
Stars: ✭ 37 (+23.33%)
Mutual labels:  jetpack-compose
Doom-Compose
An implementation of the DOOM fire effect using Jetpack Compose
Stars: ✭ 84 (+180%)
Mutual labels:  jetpack-compose
Capturable
🚀Jetpack Compose utility library for capturing Composable content and transforming it into Bitmap Image🖼️
Stars: ✭ 365 (+1116.67%)
Mutual labels:  jetpack-compose
OtakuWorld
Anime Watcher, Manga Reader, and Novel Reader as three separate apps, same UI
Stars: ✭ 123 (+310%)
Mutual labels:  jetpack-compose
Gear-VPN
A VPN client for Android based on OpenVPN made with Jetpack Compose.
Stars: ✭ 55 (+83.33%)
Mutual labels:  jetpack-compose
XAutoDaily
一个基于QQ的全自动签到模块
Stars: ✭ 115 (+283.33%)
Mutual labels:  jetpack-compose
PlantShopUI-Android
Check out the new style for App Design aims for the Online Plant Shop Service using jetpack compose...😉😀😁😎
Stars: ✭ 29 (-3.33%)
Mutual labels:  jetpack-compose
JsonPlaceholderApp
This was originally a code challenge for a company, but now is an example of MVI on Android.
Stars: ✭ 26 (-13.33%)
Mutual labels:  jetpack-compose
Monthly-App-Challenge-2022
Retos mensuales de la comunidad MoureDev para crear pequeñas aplicaciones en base a requisitos
Stars: ✭ 153 (+410%)
Mutual labels:  jetpack-compose
Compose-BreakingBad
🧪 ☠︎ Jetpack Compose - Breaking Bad ☢︎
Stars: ✭ 26 (-13.33%)
Mutual labels:  jetpack-compose
butterfly
🦋 Butterfly helps you to build adaptive and responsive UIs for Android with Jetpack WindowManager.
Stars: ✭ 169 (+463.33%)
Mutual labels:  jetpack-compose
chip-8
Jetpack Compose and SwiftUI based Kotlin Multiplatform fork of https://github.com/cbeust/chip-8 (Chip-8 Emulator)
Stars: ✭ 36 (+20%)
Mutual labels:  jetpack-compose

compose-particle-system

Quarks is a lightweight particle system for Jetpack Compose. There are endless possibilities for creating generative art with this particle system. Here are few examples -

Fountain Meteor Confetti Explosion Snowfall
fountain meteor confetti explosion snowfall

Getting started

  1. Add the following dependencies in your build.gradle file
implementation "me.nikhilchaudhari:quarks:{latest-release-version}"
  1. Call CreateParticles(...) composable function
 Box(
    modifier = Modifier
        .fillMaxSize()
        .background(Color.Black)
) {
    CreateParticles(
        modifier = Modifier.fillMaxSize(),
        // Set the initial position particles (From where do you want to shoot/generate particles)
        x = 500f, y = 1000f,
        // Set the velocity of particle in x and y direction
        velocity = Velocity(xDirection = 1f, yDirection = 1f),
        // Set the force acting on particle
        force = Force.Gravity(0f),
        // set acceleration on both x and y direction
        acceleration = Acceleration(0f, 0f),
        // set the desired size of particle that you want
        particleSize = ParticleSize.RandomSizes(25..100),
        // set particle colors or color
        particleColor = ParticleColor.RandomColors(listOf(Color.White, Color.Yellow, Color.Red, Color.Blue)),
        // set the max lifetime and aging factor of a particle
        lifeTime = LifeTime(255f, 0.2f),
        // set the emission type - how do you want to generate particle - as a flow/stream, as a explosion/blast
        emissionType = EmissionType.ExplodeEmission(numberOfParticles = 100),
        // duration of animation 
        durationMillis = 10 * 1000
    )
}
  1. That's it. You're done. Check the configuration section to apply the required configs to your particle system.

Configuration

This Particle system (or any other particle system) runs on basic physics principles like velocity, force, acceleration etc. Also the emission of particle can be done in two ways 1. A continuous stream/flow of particle or 2. Explosion/Bursting of particles. To apply various configuration to particle system, here are the things you can configure for a particle and as well as for a system -

Position

Set the initial position of particle emitter, from where do you want to start the emission. Set position x = 500f and y = 500f. This is canvas, coordinate system starts from top left corner. Horizontal - right direction is positive x axis and vertical-downwards is positive y axis.

 CreateParticles(
   //...
    x = 500f, y = 1000f,
  //...
)

Emission Type

Set emission type to set particle emission as flow/stream of steady particles or as explosion at once.

EmissionType.ExplodeEmission 🎊

If you want to explode/burst particles at once, you can set emission type to emissionType = EmissionType.ExplodeEmission(numberOfParticles = 100). Pass the number of particles that you want at the time of explosion.

EmissionType.FlowEmission 💧

Definite Emission

If you want a slow and steady stream/flow of constant number of particles, set emissionType = EmissionType.FlowEmission(maxParticlesCount = 500, emissionRate = 0.6f).

Pass the maximum number of particles you want for ex, maxParticlesCount = 500. This will create a steady flow of 500 particles.

Indefinite Emission

If you want an indefinite stream/flow of particles you can set maxParticlesCount = EmissionType.FlowEmission.INDEFINITE. This will create an indefinite steady flow of infinite number of particles.

⚠️ durationMillis = 10000 config does not work for indefinite emission. It'll run continuously, so make sure you only use it whenever needed. The stopping mechanism is yet to be added in the code.

Duration

Set the duration value durationMillis = 10000 for how long do you want to run the animation. Your animation of particle will run for the given number of milliseconds. Duration won't work for indefinte emission of particles.

Default value = 10000

Velocity 🚤

You can define the particle velocity in both directions. Set velocity = Velocity(xDirection = 1f, yDirection = 1f, angle = TWO_PI, randomize = true).

  1. Angle -

    By default, the angle is used to compute the sin and cos components of velocity over x and y direction. And the supplied values of xDirection and yDirection acts as magnitude. Default valye of angle is TWO_PI (in radians). You can set angle value in radians.

  2. Randomizing velocities -

    By default, random velocities are applied to each particles but you can configure to keep it single value. Change the randomize=false flag to false.

Default value = Velocity(xDirection = 1f, yDirection = 1f, angle = TWO_PI, randomize = true)

Force 🏋️

Force can be applied on each particle. Two types of force options are available.

  1. Force.Gravity -

    You can apply gravitational force on particle by setting force = Force.Gravity(magnitude = 2f). This way particle will experience a downward force If you pass the negative value in the magnitude then it'll become an anti-gravity and particle will experience an upward force.

  2. Force.Wind - 🎐

    You can apply Wind force on each particle in both directions. force = Force.Wind(1.5f, 0.3f). Wind will move particle in the specified direction.

Default value = Force.Gravity(0.0f)

Acceleration 🏃

You can apply acceleration by setting acceleration = Acceleration(xComponent = 1f, yComponent = 1f). Acceleration (x and y component) will be applied uniformly on each frame of animation to a particle.

Default value = Acceleration(0f, 0f)

Particle Size 🌏

You can configure particle size in two ways.

  1. Setting random size of particles

    particleSize = ParticleSize.RandomSizes(25..100) Set range of sizes and a random size will be applied to each particle.

  2. Setting fixed size

    particleSize = ParticleSize.ConstantSize(25f) sets the constant size to each particle.

Default value = ParticleSize.ConstantSize(25f)

Particle Color 🔶

You can configure random colors or single color to a particle.

  1. Random colors -

    particleColor = ParticleColor.RandomColors(listOf(Color.White, Color.Yellow, Color.Red, Color.Blue)) pass the list of colors and a random value will be selected and applied to different particles.

  2. Single color -

    particleColor = ParticleColor.SingleColor(Color.Yellow) sets the single color to each particle.

Default value = ParticleColor.SingleColor(Color.Yellow)

Lifetime & Aging factor 🧝‍♂️

Set the lifetime of a particle to a value and an aging factor by which the life of particle is reduced in each frame.

lifeTime = LifeTime(maxLife = 255f, agingFactor = 1f)

Here at each frame the againgFactor will be removed from the maxlife value of particle.

Default value = LifeTime(maxLife = 255f, agingFactor = 1f)

TODOs

  • Add angular velocity
  • Add stopping mechanism for infinite flow
  • Add a custom onDraw() config to let user draw anything as a particle shape.

License

Licensed under Apache License, Version 2.0 here

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].