Conditional: smoke
Soft particles rise from an element while a condition is true.
Smoke puffs soft, rising particles from the top of the element. Use it for a hot or busy state, such as a device that is overheating or a task that is cooking.
Usage
The sample lets smoke rise from a pot while it is on the stove.
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.unit.dp
import com.jantursky.kapow.ConditionalEffect
import com.jantursky.kapow.conditionalEffect
@Composable
fun Pot(onStove: Boolean) {
Box(
Modifier
.size(80.dp)
.background(Color.DarkGray, RoundedCornerShape(12.dp))
.conditionalEffect(onStove, ConditionalEffect.smoke(color = Color(0xFFC2C2C2))),
)
}
Parameters
| Parameter | Default | Description |
|---|---|---|
color |
Color(0xFF8A8A8A) |
Color of the smoke. |
rate |
1f |
How often puffs come, as a factor: 2 is twice as many. Must be positive. |
size |
10.dp |
Radius of a puff at its start. Must be positive. |
opacity |
0.7f |
How opaque a puff gets at most, above 0 and up to 1. |
wind |
0f |
A sideways push in dp per second squared. Positive blows to the right. |
physics |
ParticlePhysics.Default |
How the particles launch and move: cone, speed, lifetime, gravity, drag, size, spin, fade, start and end scale and emission area. Parts left out keep the effect’s own values; blend mode and color pick are ignored. EmissionArea.Edge(...) moves the source to another edge. |
seed |
0 |
The start of the random numbers that place and shape the puffs. The same seed gives the same smoke. |
Reduced motion
No particles are emitted.
Notes
- Particles draw through a particle layer when one is above the element, so a clipping parent does not cut them off. Without one they draw around the element.
- Particles come out of the top of the element continuously while the condition is true.
- When the condition turns false, no new particles start and the ones in flight finish their life.
- Particles do not follow the element if it moves.