CanvasEmitterConfig

data class CanvasEmitterConfig(val particlePerSecond: Int, val emitterCenter: DpOffset, val startRegionShape: CanvasEmitterConfig.Shape, val startRegionSize: DpSize, val particleShapes: List<ParticleShape>, val lifespanRange: IntRange, val fadeOutTime: IntRange, val scaleTime: IntRange, val colors: List<Color>, val particleSizes: List<DpSize>, val spread: IntRange = IntRange(-180, 180), val blendMode: BlendMode = BlendMode.SrcOver, val alphaEasing: Easing = LinearEasing, val scaleEasing: Easing = LinearEasing, val initialForce: IntRange = IntRange(10, 100), val rotationRange: IntRange = IntRange(-180, 180), val startScaleRange: IntRange = IntRange(0,1), val targetScaleRange: IntRange = IntRange(1,2), val gravityStrength: Float = 0.0f, val gravityAngle: Int = 0, val edgeBehavior: EdgeBehavior = EdgeBehavior.None, val hideInStartRegion: Boolean = false)(source)

Configuration for CanvasParticleEmitter — describes how many particles to emit, where and in what shape they originate, how they look, and the physics that governs their motion.

Ranges (such as lifespanRange, fadeOutTime, or spread) and list properties (such as colors, particleShapes, or particleSizes) are sampled randomly per particle, so a single config can produce a varied, natural-looking effect. All defaults are tuned for a gentle upward burst with no gravity; override gravityStrength/gravityAngle for confetti, rain, or bubbles, and edgeBehavior to make particles bounce, stick, or wrap at the emitter bounds.

Parameters

particlePerSecond

is number of particles emitted by this source in 1sec. The emission happens every 100ms = 0,1s, so value less then 10 will be neglected.

emitterCenter

is DpOffset for the center of Emitter

startRegionShape

is the shape(path) for emitter. For example Point means every particle will be created at the same place emitterCenter

startRegionSize

is DpSize of region where emission happens. The source for each particle will be picked randomly from circumference of the startRegionShape

particleShapes
  • list of shapes for particles. The emitter will pick randomly from the list of available shapes

lifespanRange
  • duration of one particle. It is an IntRange to randomize the particle life

fadeOutTime
  • duration of fadeOut animation. Each particle can have random fadeOut time, so it is IntRange

scaleTime
  • duration of scaling animation. Use startScaleRange and targetScaleRange to control the parameters of particle scale

colors
  • a list of colors that each particle will randomly pick from

particleSizes
  • a list of sizes in DpSize for each particle. It will be picked randomly from available sizes. The size can be also manipulated using startScaleRange and targetScaleRange

spread
  • range of angles (in degrees) that describe the direction of path for each particle. 0 degrees points upward (top of the screen)

blendMode
alphaEasing
  • an easing curve that is applied for alpha animation on each particle

scaleEasing
  • an easing curve that is applied for scale animation on each particle

initialForce
  • initial velocity magnitude for each particle. Higher values make particles move faster from the emission point. The value is picked randomly from the provided range.

rotationRange
  • range of angles (in degrees) that each particle will rotate during translation

targetScaleRange
  • end scale for each particle

startScaleRange
  • start scale for each particle

gravityStrength
  • strength of gravitational force applied to particles in Dp/s². A value of 0 means no gravity. Higher values create stronger pull.

gravityAngle
  • direction of gravity in degrees. 0 degrees points downward (bottom of the screen), 90 degrees points left, -90 degrees points right, 180 degrees points upward.

edgeBehavior
hideInStartRegion
  • when true, particles whose current position falls inside the start region (as defined by startRegionShape and startRegionSize) are not drawn. Useful for ring emitters with 360° spread where particles crossing the interior would otherwise clutter the center. Default is false.

Constructors

Link copied to clipboard
constructor(particlePerSecond: Int, emitterCenter: DpOffset, startRegionShape: CanvasEmitterConfig.Shape, startRegionSize: DpSize, particleShapes: List<ParticleShape>, lifespanRange: IntRange, fadeOutTime: IntRange, scaleTime: IntRange, colors: List<Color>, particleSizes: List<DpSize>, spread: IntRange = IntRange(-180, 180), blendMode: BlendMode = BlendMode.SrcOver, alphaEasing: Easing = LinearEasing, scaleEasing: Easing = LinearEasing, initialForce: IntRange = IntRange(10, 100), rotationRange: IntRange = IntRange(-180, 180), startScaleRange: IntRange = IntRange(0,1), targetScaleRange: IntRange = IntRange(1,2), gravityStrength: Float = 0.0f, gravityAngle: Int = 0, edgeBehavior: EdgeBehavior = EdgeBehavior.None, hideInStartRegion: Boolean = false)

Types

Link copied to clipboard

The geometry of the emitter's start region — the locus from which particles originate.

Properties

Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard

A fresh emission point for the next particle, sampled from the perimeter of the start region. For Shape.POINT this is always emitterCenter; for the other shapes it is a random point along the region's circumference, so reading this property repeatedly yields a spread of origins across the shape.

Link copied to clipboard
Link copied to clipboard
Link copied to clipboard

Functions

Link copied to clipboard

Returns true if pos currently falls inside the start region described by startRegionShape and startRegionSize, centered on emitterCenter. Used by the emitter to honor hideInStartRegion. Shape.POINT, Shape.H_LINE, and Shape.V_LINE have no interior, so this always returns false for them.