1e41f4b71Sopenharmony_ci# Particle Animation (Particle) 2e41f4b71Sopenharmony_ci 3e41f4b71Sopenharmony_ciParticle animation is an animation composed of a multitude of particles randomly generated within a certain range. The particles can be points or images. By animating different aspects of the particles, such as color, opacity, scale, velocity, acceleration, and spin angle, you can create engaging and dynamic aesthetics. For example, you can create an impressive snowfall animation by animating the particles – snowflakes. 4e41f4b71Sopenharmony_ci 5e41f4b71Sopenharmony_ciThe component used for producing particle animations is **Particle**. 6e41f4b71Sopenharmony_ci 7e41f4b71Sopenharmony_ci 8e41f4b71Sopenharmony_ci> **NOTE** 9e41f4b71Sopenharmony_ci> 10e41f4b71Sopenharmony_ci> This component is supported since API version 10. Updates will be marked with a superscript to indicate their earliest API version. 11e41f4b71Sopenharmony_ci 12e41f4b71Sopenharmony_ci 13e41f4b71Sopenharmony_ci## Child Components 14e41f4b71Sopenharmony_ci 15e41f4b71Sopenharmony_ciNot supported 16e41f4b71Sopenharmony_ci 17e41f4b71Sopenharmony_ci 18e41f4b71Sopenharmony_ci## APIs 19e41f4b71Sopenharmony_ci 20e41f4b71Sopenharmony_ci```typescript 21e41f4b71Sopenharmony_ciinterface ParticleInterface { 22e41f4b71Sopenharmony_ci < 23e41f4b71Sopenharmony_ci PARTICLE extends ParticleType, 24e41f4b71Sopenharmony_ci COLOR_UPDATER extends ParticleUpdater, 25e41f4b71Sopenharmony_ci OPACITY_UPDATER extends ParticleUpdater, 26e41f4b71Sopenharmony_ci SCALE_UPDATER extends ParticleUpdater, 27e41f4b71Sopenharmony_ci ACC_SPEED_UPDATER extends ParticleUpdater, 28e41f4b71Sopenharmony_ci ACC_ANGLE_UPDATER extends ParticleUpdater, 29e41f4b71Sopenharmony_ci SPIN_UPDATER extends ParticleUpdater 30e41f4b71Sopenharmony_ci >(value: { 31e41f4b71Sopenharmony_ci particles: Array< 32e41f4b71Sopenharmony_ci ParticleOptions< 33e41f4b71Sopenharmony_ci PARTICLE, 34e41f4b71Sopenharmony_ci COLOR_UPDATER, 35e41f4b71Sopenharmony_ci OPACITY_UPDATER, 36e41f4b71Sopenharmony_ci SCALE_UPDATER, 37e41f4b71Sopenharmony_ci ACC_SPEED_UPDATER, 38e41f4b71Sopenharmony_ci ACC_ANGLE_UPDATER, 39e41f4b71Sopenharmony_ci SPIN_UPDATER 40e41f4b71Sopenharmony_ci > 41e41f4b71Sopenharmony_ci >; 42e41f4b71Sopenharmony_ci }): ParticleAttribute; 43e41f4b71Sopenharmony_ci} 44e41f4b71Sopenharmony_ci``` 45e41f4b71Sopenharmony_ci 46e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11. 47e41f4b71Sopenharmony_ci 48e41f4b71Sopenharmony_ci**Parameters** 49e41f4b71Sopenharmony_ci 50e41f4b71Sopenharmony_ci| Name| Type| Mandatory| Description| 51e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- | 52e41f4b71Sopenharmony_ci| value | {<br>particles:Array<[ParticleOptions](#particleoptions)<<br>[PARTICLE](#particletype), <br>[COLOR_UPDATER](#particleupdater),<br>[OPACITY_UPDATER](#particleupdater),<br>[SCALE_UPDATER](#particleupdater),<br>[ACC_SPEED_UPDATER](#particleupdater),<br> [ACC_ANGLE_UPDATER](#particleupdater),<br>[SPIN_UPDATER](#particleupdater)<br>>><br>} | Yes| An array of particle options, each of which covers the emitter, color, opacity, scale, velocity, acceleration, and spin speed of particles. For details, see [ParticleOptions](#particleoptions). 53e41f4b71Sopenharmony_ci 54e41f4b71Sopenharmony_ci## Attributes 55e41f4b71Sopenharmony_ci 56e41f4b71Sopenharmony_ciIn addition to the [universal attributes](ts-universal-attributes-size.md), the following attributes are supported. 57e41f4b71Sopenharmony_ci 58e41f4b71Sopenharmony_ci### disturbanceFields<sup>12+</sup> 59e41f4b71Sopenharmony_ci 60e41f4b71Sopenharmony_cidisturbanceFields(fields: Array<DisturbanceFieldOptions>) 61e41f4b71Sopenharmony_ci 62e41f4b71Sopenharmony_ciSets the disturbance fields. 63e41f4b71Sopenharmony_ci 64e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12. 65e41f4b71Sopenharmony_ci 66e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 67e41f4b71Sopenharmony_ci 68e41f4b71Sopenharmony_ci**Parameters** 69e41f4b71Sopenharmony_ci 70e41f4b71Sopenharmony_ci| Name| Type | Mandatory| Description | 71e41f4b71Sopenharmony_ci| ------ | ------- | ---- | ---------------------------- | 72e41f4b71Sopenharmony_ci| fields | Array<[DisturbanceFieldOptions](#disturbancefieldoptions12)> | Yes | Array of disturbance fields.| 73e41f4b71Sopenharmony_ci 74e41f4b71Sopenharmony_ci### emitter<sup>12+</sup> 75e41f4b71Sopenharmony_ciemitter(value: Array<EmitterProperty>) 76e41f4b71Sopenharmony_ci 77e41f4b71Sopenharmony_ciSets the emitter parameters. 78e41f4b71Sopenharmony_ci 79e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12. 80e41f4b71Sopenharmony_ci 81e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 82e41f4b71Sopenharmony_ci 83e41f4b71Sopenharmony_ci**Parameters** 84e41f4b71Sopenharmony_ci 85e41f4b71Sopenharmony_ci| Name| Type | Mandatory| Description | 86e41f4b71Sopenharmony_ci| ------ | ------- | ---- | ---------------------------- | 87e41f4b71Sopenharmony_ci| value | Array<[EmitterProperty](#emitterproperty12)> | Yes | Array of emitter parameters to set.| 88e41f4b71Sopenharmony_ci 89e41f4b71Sopenharmony_ci## Events 90e41f4b71Sopenharmony_ciThe [universal events](ts-universal-events-click.md) are supported. 91e41f4b71Sopenharmony_ci 92e41f4b71Sopenharmony_ci## ParticleOptions 93e41f4b71Sopenharmony_ci 94e41f4b71Sopenharmony_ci```typescript 95e41f4b71Sopenharmony_ciinterface ParticleOptions< 96e41f4b71Sopenharmony_ci PARTICLE extends ParticleType, 97e41f4b71Sopenharmony_ci COLOR_UPDATER extends ParticleUpdater, 98e41f4b71Sopenharmony_ci OPACITY_UPDATER extends ParticleUpdater, 99e41f4b71Sopenharmony_ci SCALE_UPDATER extends ParticleUpdater, 100e41f4b71Sopenharmony_ci ACC_SPEED_UPDATER extends ParticleUpdater, 101e41f4b71Sopenharmony_ci ACC_ANGLE_UPDATER extends ParticleUpdater, 102e41f4b71Sopenharmony_ci SPIN_UPDATER extends ParticleUpdater 103e41f4b71Sopenharmony_ci> { 104e41f4b71Sopenharmony_ci emitter: EmitterOptions<PARTICLE>; 105e41f4b71Sopenharmony_ci color?: ParticleColorPropertyOptions<COLOR_UPDATER>; 106e41f4b71Sopenharmony_ci opacity?: ParticlePropertyOptions<number, OPACITY_UPDATER>; 107e41f4b71Sopenharmony_ci scale?: ParticlePropertyOptions<number, SCALE_UPDATER>; 108e41f4b71Sopenharmony_ci velocity?: { 109e41f4b71Sopenharmony_ci speed: [number, number]; 110e41f4b71Sopenharmony_ci angle: [number, number]; 111e41f4b71Sopenharmony_ci }; 112e41f4b71Sopenharmony_ci acceleration?: { 113e41f4b71Sopenharmony_ci speed?: ParticlePropertyOptions<number, ACC_SPEED_UPDATER>; 114e41f4b71Sopenharmony_ci angle?: ParticlePropertyOptions<number, ACC_ANGLE_UPDATER>; 115e41f4b71Sopenharmony_ci }; 116e41f4b71Sopenharmony_ci spin?: ParticlePropertyOptions<number, SPIN_UPDATER>; 117e41f4b71Sopenharmony_ci} 118e41f4b71Sopenharmony_ci``` 119e41f4b71Sopenharmony_ci 120e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11. 121e41f4b71Sopenharmony_ci 122e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 123e41f4b71Sopenharmony_ci 124e41f4b71Sopenharmony_ci| Name| Type| Mandatory| Description| 125e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- | 126e41f4b71Sopenharmony_ci| emitter | [EmitterOptions](#emitteroptions)<[PARTICLE](#particletype)> | Yes| Particle emitter.| 127e41f4b71Sopenharmony_ci| color | [ParticleColorPropertyOptions](#particlecolorpropertyoptions)<[COLOR_UPDATER](#particleupdater)> | No| Particle color.<br>**NOTE**<br>Default value: **{ range:[Color.White,Color.White] }.** Colors cannot be set for image particles.| 128e41f4b71Sopenharmony_ci| opacity | [ParticlePropertyOptions](#particlepropertyoptions)\<number, [OPACITY_UPDATER](#particleupdater)> | No| Particle opacity.<br>Default value: **{ range:[1.0,1.0] }**| 129e41f4b71Sopenharmony_ci| scale | [ParticlePropertyOptions](#particlepropertyoptions)\<number, [SCALE_UPDATER](#particleupdater)> | No| Particle scale.<br>Default value: **{ range:[1.0,1.0] }**| 130e41f4b71Sopenharmony_ci| velocity | {<br>speed: [number, number];<br>angle: [number, number];<br>} |No| Particle velocity.<br>**NOTE**<br>**speed** indicates the time rate at which the particle moves. **angle** indicates the direction (in angles) in which the particle moves, with the geometric center of the element as the coordinate origin and the horizontal direction as the x-axis. A positive number indicates clockwise rotation.<br>Default value: **{speed: [0.0,0.0],angle: [0.0,0.0] }**| 131e41f4b71Sopenharmony_ci| acceleration | {<br>speed?: [ParticlePropertyOptions](#particlepropertyoptions)<number, [ACC_SPEED_UPDATER](#particleupdater)>;<br>angle?: [ParticlePropertyOptions](#particlepropertyoptions)<number, [ACC_ANGLE_UPDATER](#particleupdater)>;<br>} | No| Particle acceleration.<br>**NOTE**<br>**speed** indicates the acceleration speed, and **angle** indicates the acceleration direction (in angles).<br>Default value: **{ speed:{range:[0.0,0.0]},angle:{range:[0.0,0.0]} }**| 132e41f4b71Sopenharmony_ci| spin | [ParticlePropertyOptions](#particlepropertyoptions)<number, [SPIN_UPDATER](#particleupdater)> | No| Particle spin angle.<br>Default value: **{range:[0.0,0.0]}**<br>Direction: A positive number indicates clockwise spinning, and a negative number indicates anticlockwise spinning.| 133e41f4b71Sopenharmony_ci 134e41f4b71Sopenharmony_ci 135e41f4b71Sopenharmony_ci## EmitterOptions 136e41f4b71Sopenharmony_ciProvides particle emitter configuration. 137e41f4b71Sopenharmony_ci 138e41f4b71Sopenharmony_ci```typescript 139e41f4b71Sopenharmony_ciinterface EmitterOptions<PARTICLE extends ParticleType> { 140e41f4b71Sopenharmony_ci particle: { 141e41f4b71Sopenharmony_ci type: PARTICLE; 142e41f4b71Sopenharmony_ci config: ParticleConfigs[PARTICLE]; 143e41f4b71Sopenharmony_ci count: number; 144e41f4b71Sopenharmony_ci lifetime?: number; 145e41f4b71Sopenharmony_ci lifetimeRange?: number; 146e41f4b71Sopenharmony_ci }; 147e41f4b71Sopenharmony_ci emitRate?: number; 148e41f4b71Sopenharmony_ci shape?: ParticleEmitterShape; 149e41f4b71Sopenharmony_ci position?: [Dimension, Dimension]; 150e41f4b71Sopenharmony_ci size?: [Dimension, Dimension]; 151e41f4b71Sopenharmony_ci} 152e41f4b71Sopenharmony_ci``` 153e41f4b71Sopenharmony_ci 154e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11. 155e41f4b71Sopenharmony_ci 156e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 157e41f4b71Sopenharmony_ci 158e41f4b71Sopenharmony_ci| Name| Type| Mandatory| Description| 159e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- | 160e41f4b71Sopenharmony_ci| particle | {<br>type: [PARTICLE](#particletype),<br>config: [ParticleConfigs](#particleconfigs),<br>count: number,<br>lifetime?: number<br>lifeTimeRange?:number<sup>12+<sup><br>} | Yes| Particle configuration.<br>- **type**: particle type, which can be **IMAGE** or **POINT**.<br><br>**Atomic service API**: This API can be used in atomic services since API version 11.<br>- **config**: configuration of the particle type.<br>- The value type of **config** is subject to the value of **type**.<br>1. If **type** is **ParticleType.POINT**, the **config** type is [PointParticleParameters](#pointparticleparameters).<br>2. If **type** is **ParticleType.IMAGE**, the **config** type is [ImageParticleParameters](#imageparticleparameters).<br>**Atomic service API**: This API can be used in atomic services since API version 11.<br>- **count**: number of particles. The value is greater than or equal to -1. The value **-1** indicates that the number of particles is infinite.<br>**Atomic service API**: This API can be used in atomic services since API version 11.<br>- **lifetime**: lifetime of a single particle. The default value is **1000** (that is, 1000 ms, 1s). The value is greater than or equal to -1. The value **-1** indicates that the lifetime of the particle is infinite. If the value specified is less than **-1**, the default value is used.<br>**Atomic service API**: This API can be used in atomic services since API version 11.<br>- **lifeTimeRange**: range of particle lifetime values. After **lifeTimeRange** is set, the lifetime of a particle is a random integer between [lifetime – lifeTimeRange, lifetime + lifeTimeRange]. **lifeTimeRange** has a default value of 0, and its value range is from 0 to positive infinity. If it is set to a negative value, the default value is used.<br>**Atomic service API**: This API can be used in atomic services since API version 12.| 161e41f4b71Sopenharmony_ci| emitRate | number | No| Emit rate (that is, the number of particles emitted per second).<br> Default value: **5**. If the value specified is less than 0, the default value is used.<br> The **emitRate** value can significantly impact performance when it exceeds 5000; you are advised to set it to be less than 5000.| 162e41f4b71Sopenharmony_ci| shape | [ParticleEmitterShape](#particleemittershape) | No| Emitter shape.<br> Default value: **ParticleEmitterShape.RECTANGLE**| 163e41f4b71Sopenharmony_ci| position | \[[Dimension](ts-types.md#dimension10), [Dimension](ts-types.md#dimension10)\] | No| Emitter position (distance from the upper left corner of the component). The first parameter indicates the relative offset along the x-axis, and the second parameter indicates the relative offset along the y-axis.<br>Default value: **[0.0, 0.0]**| 164e41f4b71Sopenharmony_ci| size | \[[Dimension](ts-types.md#dimension10), [Dimension](ts-types.md#dimension10)\] |No| Size of the emit window. The first parameter indicates the emitter width, and the second parameter indicates the emitter height.<br>Default value: **['100%', '100%']** (that is, the emit window fully occupies the component).| 165e41f4b71Sopenharmony_ci 166e41f4b71Sopenharmony_ci## ParticleConfigs 167e41f4b71Sopenharmony_ci 168e41f4b71Sopenharmony_ci```typescript 169e41f4b71Sopenharmony_ciinterface ParticleConfigs { 170e41f4b71Sopenharmony_ci [ParticleType.POINT]: PointParticleParameters; 171e41f4b71Sopenharmony_ci [ParticleType.IMAGE]: ImageParticleParameters; 172e41f4b71Sopenharmony_ci} 173e41f4b71Sopenharmony_ci``` 174e41f4b71Sopenharmony_ci 175e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11. 176e41f4b71Sopenharmony_ci 177e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 178e41f4b71Sopenharmony_ci 179e41f4b71Sopenharmony_ci| Name | Type | Mandatory| Description| 180e41f4b71Sopenharmony_ci| -------- | -------------- | -------- | -------- | 181e41f4b71Sopenharmony_ci| [ParticleType.POINT] | [PointParticleParameters](#pointparticleparameters) | Yes | Point particle configuration.| 182e41f4b71Sopenharmony_ci| [ParticleType.IMAGE] | [ImageParticleParameters](#imageparticleparameters) | Yes | Image particle configuration.| 183e41f4b71Sopenharmony_ci 184e41f4b71Sopenharmony_ci## PointParticleParameters 185e41f4b71Sopenharmony_ci```typescript 186e41f4b71Sopenharmony_ciinterface PointParticleParameters { 187e41f4b71Sopenharmony_ci radius: VP; 188e41f4b71Sopenharmony_ci} 189e41f4b71Sopenharmony_ci``` 190e41f4b71Sopenharmony_ci 191e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11. 192e41f4b71Sopenharmony_ci 193e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 194e41f4b71Sopenharmony_ci 195e41f4b71Sopenharmony_ci| Name | Type | Mandatory| Description| 196e41f4b71Sopenharmony_ci| -------- | -------------- | -------- | -------- | 197e41f4b71Sopenharmony_ci| radius | [VP](ts-types.md#vp10)| Yes | Particle radius.| 198e41f4b71Sopenharmony_ci 199e41f4b71Sopenharmony_ci## ImageParticleParameters 200e41f4b71Sopenharmony_ci```typescript 201e41f4b71Sopenharmony_ciinterface ImageParticleParameters { 202e41f4b71Sopenharmony_ci src: ResourceStr; 203e41f4b71Sopenharmony_ci size: [Dimension, Dimension]; 204e41f4b71Sopenharmony_ci objectFit?: ImageFit; 205e41f4b71Sopenharmony_ci} 206e41f4b71Sopenharmony_ci``` 207e41f4b71Sopenharmony_ci 208e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11. 209e41f4b71Sopenharmony_ci 210e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 211e41f4b71Sopenharmony_ci 212e41f4b71Sopenharmony_ci| Name | Type | Mandatory| Description| 213e41f4b71Sopenharmony_ci| -------- | -------------- | -------- | -------- | 214e41f4b71Sopenharmony_ci| src | [ResourceStr](ts-types.md#resourcestr) | Yes | Image path. SVG images are not supported.| 215e41f4b71Sopenharmony_ci| size | \[[Dimension](ts-types.md#dimension10), [Dimension](ts-types.md#dimension10)\]| Yes | Image size.| 216e41f4b71Sopenharmony_ci| objectFit| [ImageFit](ts-appendix-enums.md#imagefit)| No | Image display mode.| 217e41f4b71Sopenharmony_ci 218e41f4b71Sopenharmony_ci## ParticleColorPropertyOptions 219e41f4b71Sopenharmony_ci 220e41f4b71Sopenharmony_ci```typescript 221e41f4b71Sopenharmony_ciinterface ParticleColorPropertyOptions<UPDATER extends ParticleUpdater> { 222e41f4b71Sopenharmony_ci range: [ResourceColor, ResourceColor]; 223e41f4b71Sopenharmony_ci distributionType?: DistributionType; 224e41f4b71Sopenharmony_ci updater?: { 225e41f4b71Sopenharmony_ci type: UPDATER; 226e41f4b71Sopenharmony_ci config: ParticleColorPropertyUpdaterConfigs[UPDATER]; 227e41f4b71Sopenharmony_ci }; 228e41f4b71Sopenharmony_ci} 229e41f4b71Sopenharmony_ci``` 230e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11. 231e41f4b71Sopenharmony_ci 232e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 233e41f4b71Sopenharmony_ci 234e41f4b71Sopenharmony_ci| Name| Type| Mandatory| Description| 235e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- | 236e41f4b71Sopenharmony_ci| range | \[[ResourceColor](ts-types.md#resourcecolor), [ResourceColor](ts-types.md#resourcecolor)\] | Yes| Initial color range of the particle. The initial color of particles generated by the particle emitter is randomly selected in this range.<br>Default value: **range:[Color.White,Color.White]**<br>**Atomic service API**: This API can be used in atomic services since API version 11. 237e41f4b71Sopenharmony_ci| distributionType<sup>12+<sup> | [DistributionType](#distributiontype12) | No| Type of random value distribution for the initial color of the particle. Both uniform distribution and normal (Gaussian) distribution are supported.<br>Default value: **DistributionType.UNIFORM**<br>**Atomic service API**: This API can be used in atomic services since API version 12. 238e41f4b71Sopenharmony_ci| updater | {<br>type: [UPDATER](#particleupdater);<br>config: [ParticleColorPropertyUpdaterConfigs](#particlecolorpropertyupdaterconfigs)[UPDATER];<br>} | No| How the color property is updated. The available options of **type** are as follows:<br>1. **ParticleUpdater.NONE**: The property does not change. In this case, the **config** type is [ParticleColorPropertyUpdaterConfigs](#particlecolorpropertyupdaterconfigs)[ParticleUpdater.NONE].<br>2. **ParticleUpdater.RANDOM**: The property changes randomly. In this case, the **config** type is [ParticleColorPropertyUpdaterConfigs](#particlecolorpropertyupdaterconfigs)[ParticleUpdater.RANDOM].<br>3. **ParticleUpdater.CURVE**: The property changes with the animation curve. In this case, the **config** type is [ParticleColorPropertyUpdaterConfigs](#particlecolorpropertyupdaterconfigs)[ParticleUpdater.CURVE].<br>The default value of **type** is **ParticleUpdater.NONE**.<br>**NOTE**<br>When **type** is set to **ParticleUpdater.RANDOM** or **ParticleUpdater.CURVE**, the color configuration in **updater** has higher priority than that in **range**. During the animation time period configured in **updater**, the color configuration from **updater** is used. Outside of the animation time period configured in **updater**, the color configuration from **range** is used.<br>**Atomic service API**: This API can be used in atomic services since API version 11.| 239e41f4b71Sopenharmony_ci 240e41f4b71Sopenharmony_ci 241e41f4b71Sopenharmony_ci## ParticleColorPropertyUpdaterConfigs 242e41f4b71Sopenharmony_ci```typescript 243e41f4b71Sopenharmony_ciinterface ParticleColorPropertyUpdaterConfigs { 244e41f4b71Sopenharmony_ci [ParticleUpdater.NONE]: void; 245e41f4b71Sopenharmony_ci [ParticleUpdater.RANDOM]: { 246e41f4b71Sopenharmony_ci r: [number, number]; 247e41f4b71Sopenharmony_ci g: [number, number]; 248e41f4b71Sopenharmony_ci b: [number, number]; 249e41f4b71Sopenharmony_ci a: [number, number]; 250e41f4b71Sopenharmony_ci }; 251e41f4b71Sopenharmony_ci [ParticleUpdater.CURVE]: Array<ParticlePropertyAnimation<ResourceColor>>; 252e41f4b71Sopenharmony_ci} 253e41f4b71Sopenharmony_ci``` 254e41f4b71Sopenharmony_ci 255e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11. 256e41f4b71Sopenharmony_ci 257e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 258e41f4b71Sopenharmony_ci 259e41f4b71Sopenharmony_ci| Name| Type| Mandatory| Description| 260e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- | 261e41f4b71Sopenharmony_ci|[ParticleUpdater.NONE]|void | Yes| The color does not change.| 262e41f4b71Sopenharmony_ci| [ParticleUpdater.RANDOM] | {<br> r: [number, number];<br> g: [number, number];<br> b: [number, number];<br> a: [number, number];<br>} | Yes| The color changes randomly, with the per-second change difference being a value randomly generated from the range. The target color is obtained by applying the change difference to the current color value of each of the R, G, B, A channels. | 263e41f4b71Sopenharmony_ci[ParticleUpdater.CURVE]|Array<[ParticlePropertyAnimation](#particlepropertyanimation)\<[ResourceColor](ts-types.md#resourcecolor)\>> | Yes| The color changes with the animation curve. The array type indicates that multiple animation segments can be set for the current property, for example, 0-3000 ms, 3000-5000 ms, and 5000-8000 ms.| 264e41f4b71Sopenharmony_ci 265e41f4b71Sopenharmony_ci## ParticlePropertyOptions 266e41f4b71Sopenharmony_ci```typescript 267e41f4b71Sopenharmony_ciinterface ParticlePropertyOptions<TYPE, UPDATER extends ParticleUpdater> { 268e41f4b71Sopenharmony_ci range: [TYPE, TYPE]; 269e41f4b71Sopenharmony_ci updater?: { 270e41f4b71Sopenharmony_ci type: UPDATER; 271e41f4b71Sopenharmony_ci config: ParticlePropertyUpdaterConfigs<TYPE>[UPDATER]; 272e41f4b71Sopenharmony_ci }; 273e41f4b71Sopenharmony_ci} 274e41f4b71Sopenharmony_ci``` 275e41f4b71Sopenharmony_ci 276e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11. 277e41f4b71Sopenharmony_ci 278e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 279e41f4b71Sopenharmony_ci 280e41f4b71Sopenharmony_ci| Name| Type| Mandatory| Description| 281e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- | 282e41f4b71Sopenharmony_ci| range | [TYPE, TYPE] | Yes| Initial property value range of the particle. The initial property value of particles generated by the particle emitter is randomly selected in this range.<br>**NOTE**<br>If a property is set to an invalid value, the default value will be used. If the maximum value is less than the minimum value, the default range will be used. **TYPE** is number.<br>The default value varies by property:<br>1. **opacity** property: **range:[1.0,1.0]**; the value ranges from 0 to 1; the default value is **0.0**.<br>2. **scale** property: **range:[1.0,1.0]**; the value is greater than or equal to 0; the default value is **1.0**.<br>3. **speed** property in **acceleration**: **range:[0.0,0.0]**; the value is greater than or equal to 0; the default value is **0.0**.<br>4. **angle** property in **acceleration**: **range:[0.0,0.0]**; the value range is (-∞, +∞); the default value is **0.0**.<br>5. **spin** property: **range:[0.0,0.0]**; the default value is **0.0**. 283e41f4b71Sopenharmony_ci| updater | {type: [UPDATER](#particleupdater);config: [ParticlePropertyUpdaterConfigs](#particlepropertyupdaterconfigs)[UPDATER];} | No| How the property is updated. The available options of **type** are as follows:<br>1. **ParticleUpdater.NONE**: The property does not change. In this case, the **config** type is [ParticlePropertyUpdaterConfigs](#particlepropertyupdaterconfigs)[ParticleUpdater.NONE].<br>2. **ParticleUpdater.RANDOM**: The property changes randomly. In this case, the **config** type is [ParticlePropertyUpdaterConfigs](#particlepropertyupdaterconfigs)[ParticleUpdater.RANDOM].<br>3. **ParticleUpdater.CURVE**: The property changes with the animation curve. In this case, the **config** type is [ParticlePropertyUpdaterConfigs](#particlepropertyupdaterconfigs)[ParticleUpdater.CURVE].<br>The default value of **type** is **ParticleUpdater.NONE**.| 284e41f4b71Sopenharmony_ci 285e41f4b71Sopenharmony_ci 286e41f4b71Sopenharmony_ci## ParticlePropertyUpdaterConfigs 287e41f4b71Sopenharmony_ci```typescript 288e41f4b71Sopenharmony_ciinterface ParticlePropertyUpdaterConfigs<T> { 289e41f4b71Sopenharmony_ci [ParticleUpdater.NONE]: void; 290e41f4b71Sopenharmony_ci [ParticleUpdater.RANDOM]: [T, T]; 291e41f4b71Sopenharmony_ci [ParticleUpdater.CURVE]: Array<ParticlePropertyAnimation<T>>; 292e41f4b71Sopenharmony_ci} 293e41f4b71Sopenharmony_ci``` 294e41f4b71Sopenharmony_ci 295e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11. 296e41f4b71Sopenharmony_ci 297e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 298e41f4b71Sopenharmony_ci 299e41f4b71Sopenharmony_ci| Name| Type| Mandatory| Description| 300e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- | 301e41f4b71Sopenharmony_ci[[ParticleUpdater.NONE]|void | Yes| The color does not change.| 302e41f4b71Sopenharmony_ci| [ParticleUpdater.RANDOM] | [T, T] | Yes| The property changes randomly, with the per-second change difference being a value randomly generated from the range.<br>The target property value is obtained by applying the change difference to the current property value. For example, if the current property value is **0.2** and **config** is set to **[0.1,1.0]**, then:<br>1. When the random change difference is 0.5, the target property value is 0.2 + 0.5 = 0.7.<br>2. The change difference may also be a negative value. For example, if the current property value is **0.2** and **config** is set to **[-3.0,2.0]**, then when the random change difference is **-2.0**, the target property value is 0.2 - 2.0 = -1.8.<br>**NOTE**<br>**config** sets the value range of the change difference. While the change difference does not have a maximum or minimum value limit, the target property value does. Therefore, if the target property value is greater than the maximum property value, the maximum property value will be used instead; if the target property value is less than the minimum property value, the minimum property value will be used instead. **T** represents a number.<br>For example, if the value range of **opacity** is **[0.0, 1.0]**, then if the target property value is greater than 1.0, **1.0** will be used instead.| 303e41f4b71Sopenharmony_ci|[ParticleUpdater.CURVE]|Array<[ParticlePropertyAnimation](#particlepropertyanimation)\<T\>> | Yes| The property changes with the animation curve. The array type indicates that multiple animation segments can be set for the current property, for example, 0-3000 ms, 3000-5000 ms, and 5000-8000 ms. **T** represents a number.| 304e41f4b71Sopenharmony_ci 305e41f4b71Sopenharmony_ci 306e41f4b71Sopenharmony_ci 307e41f4b71Sopenharmony_ci## ParticlePropertyAnimation 308e41f4b71Sopenharmony_ci```typescript 309e41f4b71Sopenharmony_ciinterface ParticlePropertyAnimation<T> { 310e41f4b71Sopenharmony_ci from: T; 311e41f4b71Sopenharmony_ci to: T; 312e41f4b71Sopenharmony_ci startMillis: number; 313e41f4b71Sopenharmony_ci endMillis: number; 314e41f4b71Sopenharmony_ci curve?: Curve | ICurve; 315e41f4b71Sopenharmony_ci} 316e41f4b71Sopenharmony_ci``` 317e41f4b71Sopenharmony_ci 318e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11. 319e41f4b71Sopenharmony_ci 320e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 321e41f4b71Sopenharmony_ci 322e41f4b71Sopenharmony_ci| Name| Type| Mandatory| Description| 323e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- | 324e41f4b71Sopenharmony_ci|from| T | Yes| Initial value of the property. If the value is invalid, the default value will be used.| 325e41f4b71Sopenharmony_ci| to | T | Yes| Target value of the property. If the value is invalid, the default value will be used.| 326e41f4b71Sopenharmony_ci|startMillis|number | Yes| Start time of the animation.| 327e41f4b71Sopenharmony_ci|endMillis|number | Yes| End time of the animation.| 328e41f4b71Sopenharmony_ci|curve|[Curve](ts-appendix-enums.md#curve) \| [ICurve](../js-apis-curve.md#icurve)| No| Animation curve.<br>Default value: **Curve.Linear**| 329e41f4b71Sopenharmony_ci 330e41f4b71Sopenharmony_ci 331e41f4b71Sopenharmony_ci## ParticleType 332e41f4b71Sopenharmony_ci```typescript 333e41f4b71Sopenharmony_cienum ParticleType { 334e41f4b71Sopenharmony_ci POINT = 'point', 335e41f4b71Sopenharmony_ci IMAGE = 'image', 336e41f4b71Sopenharmony_ci} 337e41f4b71Sopenharmony_ci``` 338e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11. 339e41f4b71Sopenharmony_ci 340e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 341e41f4b71Sopenharmony_ci 342e41f4b71Sopenharmony_ci| Name | Description| 343e41f4b71Sopenharmony_ci| -------- | -------- | 344e41f4b71Sopenharmony_ciPOINT |Point particle.| 345e41f4b71Sopenharmony_ciIMAGE | Image particle.| 346e41f4b71Sopenharmony_ci 347e41f4b71Sopenharmony_ci 348e41f4b71Sopenharmony_ci 349e41f4b71Sopenharmony_ci## ParticleEmitterShape 350e41f4b71Sopenharmony_ci```typescript 351e41f4b71Sopenharmony_cienum ParticleEmitterShape { 352e41f4b71Sopenharmony_ci RECTANGLE = 'rectangle', 353e41f4b71Sopenharmony_ci CIRCLE = 'circle', 354e41f4b71Sopenharmony_ci ELLIPSE = 'ellipse', 355e41f4b71Sopenharmony_ci} 356e41f4b71Sopenharmony_ci``` 357e41f4b71Sopenharmony_ci 358e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11. 359e41f4b71Sopenharmony_ci 360e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 361e41f4b71Sopenharmony_ci 362e41f4b71Sopenharmony_ci| Name | Description| 363e41f4b71Sopenharmony_ci| -------- | -------- | 364e41f4b71Sopenharmony_ciRECTANGLE |The particle emitter is rectangular.| 365e41f4b71Sopenharmony_ciCIRCLE | The particle emitter is circular.| 366e41f4b71Sopenharmony_ciELLIPSE |The particle emitter is elliptical.| 367e41f4b71Sopenharmony_ci 368e41f4b71Sopenharmony_ci## DistributionType<sup>12+<sup> 369e41f4b71Sopenharmony_ci```typescript 370e41f4b71Sopenharmony_cienum DistributionType { 371e41f4b71Sopenharmony_ci UNIFORM = 0, 372e41f4b71Sopenharmony_ci GAUSSIAN = 1, 373e41f4b71Sopenharmony_ci} 374e41f4b71Sopenharmony_ci``` 375e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12. 376e41f4b71Sopenharmony_ci 377e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 378e41f4b71Sopenharmony_ci 379e41f4b71Sopenharmony_ci| Name | Description| 380e41f4b71Sopenharmony_ci| -------- | -------- | 381e41f4b71Sopenharmony_ci| UNIFORM |The initial color random values are distributed uniformly.| 382e41f4b71Sopenharmony_ci| GAUSSIAN | The initial color random values are distributed according to a Gaussian distribution.| 383e41f4b71Sopenharmony_ci 384e41f4b71Sopenharmony_ci## ParticleUpdater 385e41f4b71Sopenharmony_ci```typescript 386e41f4b71Sopenharmony_cienum ParticleUpdater { 387e41f4b71Sopenharmony_ci NONE = 'none', 388e41f4b71Sopenharmony_ci RANDOM = 'random', 389e41f4b71Sopenharmony_ci CURVE = 'curve', 390e41f4b71Sopenharmony_ci} 391e41f4b71Sopenharmony_ci``` 392e41f4b71Sopenharmony_ci 393e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11. 394e41f4b71Sopenharmony_ci 395e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 396e41f4b71Sopenharmony_ci 397e41f4b71Sopenharmony_ci| Name | Description| 398e41f4b71Sopenharmony_ci| -------- | -------- | 399e41f4b71Sopenharmony_ci|NONE |No change.| 400e41f4b71Sopenharmony_ci|RANDOM | Random change.| 401e41f4b71Sopenharmony_ci|CURVE |Change with the animation curve.| 402e41f4b71Sopenharmony_ci 403e41f4b71Sopenharmony_ci## DisturbanceFieldOptions<sup>12+</sup> 404e41f4b71Sopenharmony_ci 405e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12. 406e41f4b71Sopenharmony_ci 407e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 408e41f4b71Sopenharmony_ci 409e41f4b71Sopenharmony_ci| Name| Type | Mandatory| Description | 410e41f4b71Sopenharmony_ci| ------ | ------- | ---- | ---------------------------- | 411e41f4b71Sopenharmony_ci| strength | number | No |Field strength, which indicates the intensity of the repulsive force from the center outward. The default value is **0**. Positive values indicate a repulsive force directed outward, while negative values indicate an attractive force directed inward.| 412e41f4b71Sopenharmony_ci| shape | [DisturbanceFieldShape](#disturbancefieldshape12) | No | Shape of the field.<br>Default value: **DisturbanceFieldShape.RECT**| 413e41f4b71Sopenharmony_ci| size | [SizeT](../js-apis-arkui-graphics.md#sizett12)<number>| No |Size of the field.<br>Default value: {width:0, height:0}| 414e41f4b71Sopenharmony_ci| position | [PositionT](../js-apis-arkui-graphics.md#positiont12)<number> | No |Position of the field.<br>Default value: {x:0, y:0}| 415e41f4b71Sopenharmony_ci| feather | number | No |Feather value, which represents the degree of attenuation from the center of the field to its edges. The value is an integer ranging from 0 to 100. A value of 0 indicates that the field is rigid, and all particles within its range are repelled. The higher the feather value, the more gradual the field becomes, resulting in more particles close to the center point appearing within the field's range.<br>Default value: **0**| 416e41f4b71Sopenharmony_ci| noiseScale | number | No |Noise scale, used to control the overall size of the noise pattern. The value is greater than or equal to 0.<br>Default value: **1**| 417e41f4b71Sopenharmony_ci| noiseFrequency | number | No |Noise frequency. The higher the frequency, the finer the noise. The value is greater than or equal to 0.<br> Default value: **1**| 418e41f4b71Sopenharmony_ci| noiseAmplitude | number | No |Noise amplitude, which indicates the range of noise fluctuations. The greater the amplitude, the greater the difference between the noises. The value is greater than or equal to 0.<br> Default value: **1**| 419e41f4b71Sopenharmony_ci 420e41f4b71Sopenharmony_ci## DisturbanceFieldShape<sup>12+</sup> 421e41f4b71Sopenharmony_ci 422e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12. 423e41f4b71Sopenharmony_ci 424e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 425e41f4b71Sopenharmony_ci 426e41f4b71Sopenharmony_ci| Name | Description | 427e41f4b71Sopenharmony_ci| --------| ----------| 428e41f4b71Sopenharmony_ci| RECT | Rectangle. | 429e41f4b71Sopenharmony_ci| CIRCLE | Circle. | 430e41f4b71Sopenharmony_ci| ELLIPSE | Ellipse. | 431e41f4b71Sopenharmony_ci 432e41f4b71Sopenharmony_ci## EmitterProperty<sup>12+</sup> 433e41f4b71Sopenharmony_ci 434e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12. 435e41f4b71Sopenharmony_ci 436e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 437e41f4b71Sopenharmony_ci 438e41f4b71Sopenharmony_ci| Name| Type | Mandatory| Description | 439e41f4b71Sopenharmony_ci| ------ | ------- | ---- | ---------------------------- | 440e41f4b71Sopenharmony_ci| index | number | Yes |Index of the emitter based on the index array of the emitters in the initialization parameters. The value is rounded to the nearest whole number. The default value **0** is used in case of exceptions.| 441e41f4b71Sopenharmony_ci| emitRate | number | No | Emit rate, that is, the number of particles emitted per second.<br>If no value is passed in, the current emit rate is retained. If a value less than 0 is passed in, the default value **5** is used. The **emitRate** value can significantly impact performance when it exceeds 5000; you are advised to set it to be less than 5000.| 442e41f4b71Sopenharmony_ci| position | [PositionT](../js-apis-arkui-graphics.md#positiont12)<number> | No |Array of emitter positions. Only the number type is supported.<br>If no value is passed in, the current emitter position is retained. Two valid values must be passed in; if either is an invalid value, **position** will not take effect.| 443e41f4b71Sopenharmony_ci| size | [SizeT](../js-apis-arkui-graphics.md#sizett12)<number>| No |Size of the emit window. Only the number type is supported.<br>If no value is passed in, the current emitter window size is retained. Two valid values greater than 0 must be passed in; if either is an invalid value, **size** will not take effect.| 444e41f4b71Sopenharmony_ci 445e41f4b71Sopenharmony_ci## Example 446e41f4b71Sopenharmony_ci 447e41f4b71Sopenharmony_ci### Example 1 448e41f4b71Sopenharmony_ci 449e41f4b71Sopenharmony_ciThis example demonstrates the basic usage of particle animation, initializing point particles. 450e41f4b71Sopenharmony_ci 451e41f4b71Sopenharmony_ci```ts 452e41f4b71Sopenharmony_ci// xxx.ets 453e41f4b71Sopenharmony_ci@Entry 454e41f4b71Sopenharmony_ci@Component 455e41f4b71Sopenharmony_cistruct ParticleExample { 456e41f4b71Sopenharmony_ci build() { 457e41f4b71Sopenharmony_ci Stack() { 458e41f4b71Sopenharmony_ci Text() 459e41f4b71Sopenharmony_ci .width(300).height(300).backgroundColor(Color.Black) 460e41f4b71Sopenharmony_ci Particle({particles:[ 461e41f4b71Sopenharmony_ci { 462e41f4b71Sopenharmony_ci emitter:{ 463e41f4b71Sopenharmony_ci particle:{ 464e41f4b71Sopenharmony_ci type:ParticleType.POINT,// Particle type. 465e41f4b71Sopenharmony_ci config:{ 466e41f4b71Sopenharmony_ci radius:10// Point radius. 467e41f4b71Sopenharmony_ci }, 468e41f4b71Sopenharmony_ci count: 500,// Total number of particles. 469e41f4b71Sopenharmony_ci lifetime:10000,// Particle lifetime, in ms. 470e41f4b71Sopenharmony_ci lifetimeRange:100// Range of particle lifetime values, in ms. 471e41f4b71Sopenharmony_ci }, 472e41f4b71Sopenharmony_ci emitRate:10,// Number of particles emitted per second. 473e41f4b71Sopenharmony_ci position:[0,0], 474e41f4b71Sopenharmony_ci shape:ParticleEmitterShape.RECTANGLE// Emitter shape. 475e41f4b71Sopenharmony_ci }, 476e41f4b71Sopenharmony_ci color:{ 477e41f4b71Sopenharmony_ci range:[Color.Red,Color.Yellow],// Initial color range. 478e41f4b71Sopenharmony_ci updater:{ 479e41f4b71Sopenharmony_ci type:ParticleUpdater.CURVE,// Change with the animation curve. 480e41f4b71Sopenharmony_ci config:[ 481e41f4b71Sopenharmony_ci { 482e41f4b71Sopenharmony_ci from:Color.White,// Initial value of the change. 483e41f4b71Sopenharmony_ci to:Color.Pink,// Target value of the change. 484e41f4b71Sopenharmony_ci startMillis:0,// Start time. 485e41f4b71Sopenharmony_ci endMillis:3000,// End time. 486e41f4b71Sopenharmony_ci curve:Curve.EaseIn// Animation curve. 487e41f4b71Sopenharmony_ci }, 488e41f4b71Sopenharmony_ci { 489e41f4b71Sopenharmony_ci from:Color.Pink, 490e41f4b71Sopenharmony_ci to:Color.Orange, 491e41f4b71Sopenharmony_ci startMillis:3000, 492e41f4b71Sopenharmony_ci endMillis:5000, 493e41f4b71Sopenharmony_ci curve:Curve.EaseIn 494e41f4b71Sopenharmony_ci }, 495e41f4b71Sopenharmony_ci { 496e41f4b71Sopenharmony_ci from:Color.Orange, 497e41f4b71Sopenharmony_ci to:Color.Pink, 498e41f4b71Sopenharmony_ci startMillis:5000, 499e41f4b71Sopenharmony_ci endMillis:8000, 500e41f4b71Sopenharmony_ci curve:Curve.EaseIn 501e41f4b71Sopenharmony_ci }, 502e41f4b71Sopenharmony_ci ] 503e41f4b71Sopenharmony_ci } 504e41f4b71Sopenharmony_ci }, 505e41f4b71Sopenharmony_ci opacity:{ 506e41f4b71Sopenharmony_ci range:[0.0,1.0],// The initial value of particle opacity is randomly generated from the [0.0, 1.0] range. 507e41f4b71Sopenharmony_ci updater:{ 508e41f4b71Sopenharmony_ci type:ParticleUpdater.CURVE, 509e41f4b71Sopenharmony_ci config:[ 510e41f4b71Sopenharmony_ci { 511e41f4b71Sopenharmony_ci from:0.0, 512e41f4b71Sopenharmony_ci to:1.0, 513e41f4b71Sopenharmony_ci startMillis:0, 514e41f4b71Sopenharmony_ci endMillis:3000, 515e41f4b71Sopenharmony_ci curve:Curve.EaseIn 516e41f4b71Sopenharmony_ci }, 517e41f4b71Sopenharmony_ci { 518e41f4b71Sopenharmony_ci from:1.0, 519e41f4b71Sopenharmony_ci to:0.0, 520e41f4b71Sopenharmony_ci startMillis:5000, 521e41f4b71Sopenharmony_ci endMillis:10000, 522e41f4b71Sopenharmony_ci curve:Curve.EaseIn 523e41f4b71Sopenharmony_ci } 524e41f4b71Sopenharmony_ci ] 525e41f4b71Sopenharmony_ci } 526e41f4b71Sopenharmony_ci }, 527e41f4b71Sopenharmony_ci scale:{ 528e41f4b71Sopenharmony_ci range:[0.0,0.0], 529e41f4b71Sopenharmony_ci updater:{ 530e41f4b71Sopenharmony_ci type:ParticleUpdater.CURVE, 531e41f4b71Sopenharmony_ci config:[ 532e41f4b71Sopenharmony_ci { 533e41f4b71Sopenharmony_ci from:0.0, 534e41f4b71Sopenharmony_ci to:0.5, 535e41f4b71Sopenharmony_ci startMillis:0, 536e41f4b71Sopenharmony_ci endMillis:3000, 537e41f4b71Sopenharmony_ci curve: Curve.EaseIn 538e41f4b71Sopenharmony_ci } 539e41f4b71Sopenharmony_ci ] 540e41f4b71Sopenharmony_ci } 541e41f4b71Sopenharmony_ci }, 542e41f4b71Sopenharmony_ci acceleration:{// Acceleration. speed indicates the acceleration speed, and angle indicates the acceleration direction. 543e41f4b71Sopenharmony_ci speed:{ 544e41f4b71Sopenharmony_ci range:[3,9], 545e41f4b71Sopenharmony_ci updater:{ 546e41f4b71Sopenharmony_ci type:ParticleUpdater.RANDOM,// The speed changes randomly. 547e41f4b71Sopenharmony_ci config:[1,20] 548e41f4b71Sopenharmony_ci } 549e41f4b71Sopenharmony_ci }, 550e41f4b71Sopenharmony_ci angle:{ 551e41f4b71Sopenharmony_ci range:[90,90] 552e41f4b71Sopenharmony_ci } 553e41f4b71Sopenharmony_ci } 554e41f4b71Sopenharmony_ci 555e41f4b71Sopenharmony_ci } 556e41f4b71Sopenharmony_ci ] 557e41f4b71Sopenharmony_ci }).width(300).height(300) 558e41f4b71Sopenharmony_ci }.width("100%").height("100%").align(Alignment.Center) 559e41f4b71Sopenharmony_ci } 560e41f4b71Sopenharmony_ci} 561e41f4b71Sopenharmony_ci``` 562e41f4b71Sopenharmony_ci 563e41f4b71Sopenharmony_ci 564e41f4b71Sopenharmony_ci 565e41f4b71Sopenharmony_ci### Example 2 566e41f4b71Sopenharmony_ci 567e41f4b71Sopenharmony_ciThis example demonstrates the basic usage of particle animation, initializing image particles. 568e41f4b71Sopenharmony_ci 569e41f4b71Sopenharmony_ci```ts 570e41f4b71Sopenharmony_ci@Entry 571e41f4b71Sopenharmony_ci@Component 572e41f4b71Sopenharmony_cistruct ParticleExample { 573e41f4b71Sopenharmony_ci @State 574e41f4b71Sopenharmony_ci myCount : number = 100 575e41f4b71Sopenharmony_ci flag : boolean = false; 576e41f4b71Sopenharmony_ci build() { 577e41f4b71Sopenharmony_ci Column(){ 578e41f4b71Sopenharmony_ci Stack() { 579e41f4b71Sopenharmony_ci Particle({particles:[ 580e41f4b71Sopenharmony_ci { 581e41f4b71Sopenharmony_ci emitter:{ 582e41f4b71Sopenharmony_ci particle:{ 583e41f4b71Sopenharmony_ci type:ParticleType.IMAGE, 584e41f4b71Sopenharmony_ci config:{ 585e41f4b71Sopenharmony_ci src:$r("app.media.book"), 586e41f4b71Sopenharmony_ci size:[10,10] 587e41f4b71Sopenharmony_ci }, 588e41f4b71Sopenharmony_ci count: this.myCount, 589e41f4b71Sopenharmony_ci lifetime:10000, 590e41f4b71Sopenharmony_ci lifetimeRange:100 591e41f4b71Sopenharmony_ci }, 592e41f4b71Sopenharmony_ci emitRate:3, 593e41f4b71Sopenharmony_ci shape:ParticleEmitterShape.CIRCLE 594e41f4b71Sopenharmony_ci }, 595e41f4b71Sopenharmony_ci color:{ 596e41f4b71Sopenharmony_ci range:[Color.White,Color.White] 597e41f4b71Sopenharmony_ci }, 598e41f4b71Sopenharmony_ci opacity:{ 599e41f4b71Sopenharmony_ci range:[1.0,1.0], 600e41f4b71Sopenharmony_ci updater:{ 601e41f4b71Sopenharmony_ci type:ParticleUpdater.CURVE, 602e41f4b71Sopenharmony_ci config:[ 603e41f4b71Sopenharmony_ci { 604e41f4b71Sopenharmony_ci from:0, 605e41f4b71Sopenharmony_ci to:1.0, 606e41f4b71Sopenharmony_ci startMillis:0, 607e41f4b71Sopenharmony_ci endMillis:6000 608e41f4b71Sopenharmony_ci }, 609e41f4b71Sopenharmony_ci { 610e41f4b71Sopenharmony_ci from:1.0, 611e41f4b71Sopenharmony_ci to:.0, 612e41f4b71Sopenharmony_ci startMillis:6000, 613e41f4b71Sopenharmony_ci endMillis:10000 614e41f4b71Sopenharmony_ci } 615e41f4b71Sopenharmony_ci ] 616e41f4b71Sopenharmony_ci } 617e41f4b71Sopenharmony_ci }, 618e41f4b71Sopenharmony_ci scale:{ 619e41f4b71Sopenharmony_ci range:[0.1,1.0], 620e41f4b71Sopenharmony_ci updater:{ 621e41f4b71Sopenharmony_ci type:ParticleUpdater.CURVE, 622e41f4b71Sopenharmony_ci config:[ 623e41f4b71Sopenharmony_ci { 624e41f4b71Sopenharmony_ci from: 0, 625e41f4b71Sopenharmony_ci to: 1.5, 626e41f4b71Sopenharmony_ci startMillis: 0, 627e41f4b71Sopenharmony_ci endMillis: 8000, 628e41f4b71Sopenharmony_ci curve: Curve.EaseIn 629e41f4b71Sopenharmony_ci } 630e41f4b71Sopenharmony_ci 631e41f4b71Sopenharmony_ci ] 632e41f4b71Sopenharmony_ci } 633e41f4b71Sopenharmony_ci }, 634e41f4b71Sopenharmony_ci acceleration:{ 635e41f4b71Sopenharmony_ci speed:{ 636e41f4b71Sopenharmony_ci range:[3,9], 637e41f4b71Sopenharmony_ci updater:{ 638e41f4b71Sopenharmony_ci type: ParticleUpdater.CURVE, 639e41f4b71Sopenharmony_ci config:[ 640e41f4b71Sopenharmony_ci { 641e41f4b71Sopenharmony_ci from:10, 642e41f4b71Sopenharmony_ci to:20, 643e41f4b71Sopenharmony_ci startMillis:0, 644e41f4b71Sopenharmony_ci endMillis:3000, 645e41f4b71Sopenharmony_ci curve:Curve.EaseIn 646e41f4b71Sopenharmony_ci }, 647e41f4b71Sopenharmony_ci { 648e41f4b71Sopenharmony_ci from:10, 649e41f4b71Sopenharmony_ci to:2, 650e41f4b71Sopenharmony_ci startMillis:3000, 651e41f4b71Sopenharmony_ci endMillis:8000, 652e41f4b71Sopenharmony_ci curve:Curve.EaseIn 653e41f4b71Sopenharmony_ci } 654e41f4b71Sopenharmony_ci ] 655e41f4b71Sopenharmony_ci } 656e41f4b71Sopenharmony_ci }, 657e41f4b71Sopenharmony_ci angle:{ 658e41f4b71Sopenharmony_ci range:[0,180], 659e41f4b71Sopenharmony_ci updater:{ 660e41f4b71Sopenharmony_ci type:ParticleUpdater.CURVE, 661e41f4b71Sopenharmony_ci config:[{ 662e41f4b71Sopenharmony_ci from:1, 663e41f4b71Sopenharmony_ci to:2, 664e41f4b71Sopenharmony_ci startMillis:0, 665e41f4b71Sopenharmony_ci endMillis:1000, 666e41f4b71Sopenharmony_ci curve:Curve.EaseIn 667e41f4b71Sopenharmony_ci }, 668e41f4b71Sopenharmony_ci { 669e41f4b71Sopenharmony_ci from:50, 670e41f4b71Sopenharmony_ci to:-50, 671e41f4b71Sopenharmony_ci startMillis:1000, 672e41f4b71Sopenharmony_ci endMillis:3000, 673e41f4b71Sopenharmony_ci curve:Curve.EaseIn 674e41f4b71Sopenharmony_ci }, 675e41f4b71Sopenharmony_ci { 676e41f4b71Sopenharmony_ci from:3, 677e41f4b71Sopenharmony_ci to:5, 678e41f4b71Sopenharmony_ci startMillis:3000, 679e41f4b71Sopenharmony_ci endMillis:8000, 680e41f4b71Sopenharmony_ci curve:Curve.EaseIn 681e41f4b71Sopenharmony_ci } 682e41f4b71Sopenharmony_ci ] 683e41f4b71Sopenharmony_ci } 684e41f4b71Sopenharmony_ci } 685e41f4b71Sopenharmony_ci }, 686e41f4b71Sopenharmony_ci spin:{ 687e41f4b71Sopenharmony_ci range:[0.1,1.0], 688e41f4b71Sopenharmony_ci updater:{ 689e41f4b71Sopenharmony_ci type:ParticleUpdater.CURVE, 690e41f4b71Sopenharmony_ci config:[ 691e41f4b71Sopenharmony_ci { 692e41f4b71Sopenharmony_ci from: 0, 693e41f4b71Sopenharmony_ci to: 360, 694e41f4b71Sopenharmony_ci startMillis: 0, 695e41f4b71Sopenharmony_ci endMillis: 8000, 696e41f4b71Sopenharmony_ci curve: Curve.EaseIn 697e41f4b71Sopenharmony_ci } 698e41f4b71Sopenharmony_ci ] 699e41f4b71Sopenharmony_ci } 700e41f4b71Sopenharmony_ci }, 701e41f4b71Sopenharmony_ci } 702e41f4b71Sopenharmony_ci ,{ 703e41f4b71Sopenharmony_ci emitter:{ 704e41f4b71Sopenharmony_ci particle:{ 705e41f4b71Sopenharmony_ci type:ParticleType.IMAGE, 706e41f4b71Sopenharmony_ci config:{ 707e41f4b71Sopenharmony_ci src:$r('app.media.heart'), 708e41f4b71Sopenharmony_ci size:[10,10] 709e41f4b71Sopenharmony_ci }, 710e41f4b71Sopenharmony_ci count: this.myCount, 711e41f4b71Sopenharmony_ci lifetime:10000, 712e41f4b71Sopenharmony_ci lifetimeRange:100 713e41f4b71Sopenharmony_ci }, 714e41f4b71Sopenharmony_ci emitRate:3, 715e41f4b71Sopenharmony_ci shape:ParticleEmitterShape.CIRCLE 716e41f4b71Sopenharmony_ci }, 717e41f4b71Sopenharmony_ci color:{ 718e41f4b71Sopenharmony_ci range:[Color.White,Color.White] 719e41f4b71Sopenharmony_ci }, 720e41f4b71Sopenharmony_ci opacity:{ 721e41f4b71Sopenharmony_ci range:[1.0,1.0], 722e41f4b71Sopenharmony_ci updater:{ 723e41f4b71Sopenharmony_ci type:ParticleUpdater.CURVE, 724e41f4b71Sopenharmony_ci config:[ 725e41f4b71Sopenharmony_ci { 726e41f4b71Sopenharmony_ci from:0, 727e41f4b71Sopenharmony_ci to:1.0, 728e41f4b71Sopenharmony_ci startMillis:0, 729e41f4b71Sopenharmony_ci endMillis:6000 730e41f4b71Sopenharmony_ci }, 731e41f4b71Sopenharmony_ci { 732e41f4b71Sopenharmony_ci from:1.0, 733e41f4b71Sopenharmony_ci to:.0, 734e41f4b71Sopenharmony_ci startMillis:6000, 735e41f4b71Sopenharmony_ci endMillis:10000 736e41f4b71Sopenharmony_ci } 737e41f4b71Sopenharmony_ci ] 738e41f4b71Sopenharmony_ci } 739e41f4b71Sopenharmony_ci }, 740e41f4b71Sopenharmony_ci scale:{ 741e41f4b71Sopenharmony_ci range:[0.1,1.0], 742e41f4b71Sopenharmony_ci updater:{ 743e41f4b71Sopenharmony_ci type:ParticleUpdater.CURVE, 744e41f4b71Sopenharmony_ci config:[ 745e41f4b71Sopenharmony_ci { 746e41f4b71Sopenharmony_ci from: 0, 747e41f4b71Sopenharmony_ci to: 2.0, 748e41f4b71Sopenharmony_ci startMillis: 0, 749e41f4b71Sopenharmony_ci endMillis: 10000, 750e41f4b71Sopenharmony_ci curve: Curve.EaseIn 751e41f4b71Sopenharmony_ci } 752e41f4b71Sopenharmony_ci 753e41f4b71Sopenharmony_ci ] 754e41f4b71Sopenharmony_ci } 755e41f4b71Sopenharmony_ci }, 756e41f4b71Sopenharmony_ci acceleration:{ 757e41f4b71Sopenharmony_ci speed:{ 758e41f4b71Sopenharmony_ci range:[3,9], 759e41f4b71Sopenharmony_ci updater:{ 760e41f4b71Sopenharmony_ci type: ParticleUpdater.CURVE, 761e41f4b71Sopenharmony_ci config:[ 762e41f4b71Sopenharmony_ci { 763e41f4b71Sopenharmony_ci from:10, 764e41f4b71Sopenharmony_ci to:20, 765e41f4b71Sopenharmony_ci startMillis:0, 766e41f4b71Sopenharmony_ci endMillis:3000, 767e41f4b71Sopenharmony_ci curve:Curve.EaseIn 768e41f4b71Sopenharmony_ci }, 769e41f4b71Sopenharmony_ci { 770e41f4b71Sopenharmony_ci from:10, 771e41f4b71Sopenharmony_ci to:2, 772e41f4b71Sopenharmony_ci startMillis:3000, 773e41f4b71Sopenharmony_ci endMillis:8000, 774e41f4b71Sopenharmony_ci curve:Curve.EaseIn 775e41f4b71Sopenharmony_ci } 776e41f4b71Sopenharmony_ci ] 777e41f4b71Sopenharmony_ci } 778e41f4b71Sopenharmony_ci }, 779e41f4b71Sopenharmony_ci angle:{ 780e41f4b71Sopenharmony_ci range:[0,180], 781e41f4b71Sopenharmony_ci updater:{ 782e41f4b71Sopenharmony_ci type:ParticleUpdater.CURVE, 783e41f4b71Sopenharmony_ci config:[{ 784e41f4b71Sopenharmony_ci from:1, 785e41f4b71Sopenharmony_ci to:2, 786e41f4b71Sopenharmony_ci startMillis:0, 787e41f4b71Sopenharmony_ci endMillis:1000, 788e41f4b71Sopenharmony_ci curve:Curve.EaseIn 789e41f4b71Sopenharmony_ci }, 790e41f4b71Sopenharmony_ci { 791e41f4b71Sopenharmony_ci from:50, 792e41f4b71Sopenharmony_ci to:-50, 793e41f4b71Sopenharmony_ci startMillis:0, 794e41f4b71Sopenharmony_ci endMillis:3000, 795e41f4b71Sopenharmony_ci curve:Curve.EaseIn 796e41f4b71Sopenharmony_ci }, 797e41f4b71Sopenharmony_ci { 798e41f4b71Sopenharmony_ci from:3, 799e41f4b71Sopenharmony_ci to:5, 800e41f4b71Sopenharmony_ci startMillis:3000, 801e41f4b71Sopenharmony_ci endMillis:10000, 802e41f4b71Sopenharmony_ci curve:Curve.EaseIn 803e41f4b71Sopenharmony_ci } 804e41f4b71Sopenharmony_ci ] 805e41f4b71Sopenharmony_ci } 806e41f4b71Sopenharmony_ci } 807e41f4b71Sopenharmony_ci }, 808e41f4b71Sopenharmony_ci spin:{ 809e41f4b71Sopenharmony_ci range:[0.1,1.0], 810e41f4b71Sopenharmony_ci updater:{ 811e41f4b71Sopenharmony_ci type:ParticleUpdater.CURVE, 812e41f4b71Sopenharmony_ci config:[ 813e41f4b71Sopenharmony_ci { 814e41f4b71Sopenharmony_ci from: 0, 815e41f4b71Sopenharmony_ci to: 360, 816e41f4b71Sopenharmony_ci startMillis: 0, 817e41f4b71Sopenharmony_ci endMillis: 10000, 818e41f4b71Sopenharmony_ci curve: Curve.EaseIn 819e41f4b71Sopenharmony_ci } 820e41f4b71Sopenharmony_ci ] 821e41f4b71Sopenharmony_ci } 822e41f4b71Sopenharmony_ci }, 823e41f4b71Sopenharmony_ci },{ 824e41f4b71Sopenharmony_ci emitter:{ 825e41f4b71Sopenharmony_ci particle:{ 826e41f4b71Sopenharmony_ci type:ParticleType.IMAGE, 827e41f4b71Sopenharmony_ci config:{ 828e41f4b71Sopenharmony_ci src:$r('app.media.sun'), 829e41f4b71Sopenharmony_ci size:[10,10] 830e41f4b71Sopenharmony_ci }, 831e41f4b71Sopenharmony_ci count: this.myCount, 832e41f4b71Sopenharmony_ci lifetime:10000, 833e41f4b71Sopenharmony_ci lifetimeRange:100 834e41f4b71Sopenharmony_ci }, 835e41f4b71Sopenharmony_ci emitRate:3, 836e41f4b71Sopenharmony_ci shape:ParticleEmitterShape.CIRCLE 837e41f4b71Sopenharmony_ci }, 838e41f4b71Sopenharmony_ci color:{ 839e41f4b71Sopenharmony_ci range:[Color.White,Color.White] 840e41f4b71Sopenharmony_ci }, 841e41f4b71Sopenharmony_ci opacity:{ 842e41f4b71Sopenharmony_ci range:[1.0,1.0], 843e41f4b71Sopenharmony_ci updater:{ 844e41f4b71Sopenharmony_ci type:ParticleUpdater.CURVE, 845e41f4b71Sopenharmony_ci config:[ 846e41f4b71Sopenharmony_ci { 847e41f4b71Sopenharmony_ci from:0, 848e41f4b71Sopenharmony_ci to:1.0, 849e41f4b71Sopenharmony_ci startMillis:0, 850e41f4b71Sopenharmony_ci endMillis:6000 851e41f4b71Sopenharmony_ci }, 852e41f4b71Sopenharmony_ci { 853e41f4b71Sopenharmony_ci from:1.0, 854e41f4b71Sopenharmony_ci to:.0, 855e41f4b71Sopenharmony_ci startMillis:6000, 856e41f4b71Sopenharmony_ci endMillis:10000 857e41f4b71Sopenharmony_ci } 858e41f4b71Sopenharmony_ci ] 859e41f4b71Sopenharmony_ci } 860e41f4b71Sopenharmony_ci }, 861e41f4b71Sopenharmony_ci scale:{ 862e41f4b71Sopenharmony_ci range:[0.1,1.0], 863e41f4b71Sopenharmony_ci updater:{ 864e41f4b71Sopenharmony_ci type:ParticleUpdater.CURVE, 865e41f4b71Sopenharmony_ci config:[ 866e41f4b71Sopenharmony_ci { 867e41f4b71Sopenharmony_ci from: 0, 868e41f4b71Sopenharmony_ci to: 2.0, 869e41f4b71Sopenharmony_ci startMillis: 0, 870e41f4b71Sopenharmony_ci endMillis: 10000, 871e41f4b71Sopenharmony_ci curve: Curve.EaseIn 872e41f4b71Sopenharmony_ci } 873e41f4b71Sopenharmony_ci 874e41f4b71Sopenharmony_ci ] 875e41f4b71Sopenharmony_ci } 876e41f4b71Sopenharmony_ci }, 877e41f4b71Sopenharmony_ci acceleration:{ 878e41f4b71Sopenharmony_ci speed:{ 879e41f4b71Sopenharmony_ci range:[3,9], 880e41f4b71Sopenharmony_ci updater:{ 881e41f4b71Sopenharmony_ci type: ParticleUpdater.CURVE, 882e41f4b71Sopenharmony_ci config:[ 883e41f4b71Sopenharmony_ci { 884e41f4b71Sopenharmony_ci from:10, 885e41f4b71Sopenharmony_ci to:20, 886e41f4b71Sopenharmony_ci startMillis:0, 887e41f4b71Sopenharmony_ci endMillis:3000, 888e41f4b71Sopenharmony_ci curve:Curve.EaseIn 889e41f4b71Sopenharmony_ci }, 890e41f4b71Sopenharmony_ci { 891e41f4b71Sopenharmony_ci from:10, 892e41f4b71Sopenharmony_ci to:2, 893e41f4b71Sopenharmony_ci startMillis:3000, 894e41f4b71Sopenharmony_ci endMillis:8000, 895e41f4b71Sopenharmony_ci curve:Curve.EaseIn 896e41f4b71Sopenharmony_ci } 897e41f4b71Sopenharmony_ci ] 898e41f4b71Sopenharmony_ci } 899e41f4b71Sopenharmony_ci }, 900e41f4b71Sopenharmony_ci angle:{ 901e41f4b71Sopenharmony_ci range:[0,180], 902e41f4b71Sopenharmony_ci updater:{ 903e41f4b71Sopenharmony_ci type:ParticleUpdater.CURVE, 904e41f4b71Sopenharmony_ci config:[{ 905e41f4b71Sopenharmony_ci from:1, 906e41f4b71Sopenharmony_ci to:2, 907e41f4b71Sopenharmony_ci startMillis:0, 908e41f4b71Sopenharmony_ci endMillis:1000, 909e41f4b71Sopenharmony_ci curve:Curve.EaseIn 910e41f4b71Sopenharmony_ci }, 911e41f4b71Sopenharmony_ci { 912e41f4b71Sopenharmony_ci from:50, 913e41f4b71Sopenharmony_ci to:-50, 914e41f4b71Sopenharmony_ci startMillis:1000, 915e41f4b71Sopenharmony_ci endMillis:3000, 916e41f4b71Sopenharmony_ci curve:Curve.EaseIn 917e41f4b71Sopenharmony_ci }, 918e41f4b71Sopenharmony_ci { 919e41f4b71Sopenharmony_ci from:3, 920e41f4b71Sopenharmony_ci to:5, 921e41f4b71Sopenharmony_ci startMillis:3000, 922e41f4b71Sopenharmony_ci endMillis:8000, 923e41f4b71Sopenharmony_ci curve:Curve.EaseIn 924e41f4b71Sopenharmony_ci } 925e41f4b71Sopenharmony_ci ] 926e41f4b71Sopenharmony_ci } 927e41f4b71Sopenharmony_ci } 928e41f4b71Sopenharmony_ci }, 929e41f4b71Sopenharmony_ci spin:{ 930e41f4b71Sopenharmony_ci range:[0.1,1.0], 931e41f4b71Sopenharmony_ci updater:{ 932e41f4b71Sopenharmony_ci type:ParticleUpdater.CURVE, 933e41f4b71Sopenharmony_ci config:[ 934e41f4b71Sopenharmony_ci { 935e41f4b71Sopenharmony_ci from: 0, 936e41f4b71Sopenharmony_ci to: 360, 937e41f4b71Sopenharmony_ci startMillis: 0, 938e41f4b71Sopenharmony_ci endMillis: 10000, 939e41f4b71Sopenharmony_ci curve: Curve.EaseIn 940e41f4b71Sopenharmony_ci } 941e41f4b71Sopenharmony_ci ] 942e41f4b71Sopenharmony_ci } 943e41f4b71Sopenharmony_ci }, 944e41f4b71Sopenharmony_ci } 945e41f4b71Sopenharmony_ci ] 946e41f4b71Sopenharmony_ci }).width(300).height(300) 947e41f4b71Sopenharmony_ci 948e41f4b71Sopenharmony_ci }.width(500).height(500).align(Alignment.Center) 949e41f4b71Sopenharmony_ci }.width("100%").height("100%") 950e41f4b71Sopenharmony_ci 951e41f4b71Sopenharmony_ci } 952e41f4b71Sopenharmony_ci} 953e41f4b71Sopenharmony_ci``` 954e41f4b71Sopenharmony_ci 955e41f4b71Sopenharmony_ci 956e41f4b71Sopenharmony_ci### Example 3 957e41f4b71Sopenharmony_ci 958e41f4b71Sopenharmony_ciThis example demonstrates how particles' trajectories change under the influence of a particle disturbance field. 959e41f4b71Sopenharmony_ci``` 960e41f4b71Sopenharmony_ci@Entry 961e41f4b71Sopenharmony_ci@Component 962e41f4b71Sopenharmony_cistruct ParticleExample { 963e41f4b71Sopenharmony_ci build() { 964e41f4b71Sopenharmony_ci Stack() { 965e41f4b71Sopenharmony_ci Text() 966e41f4b71Sopenharmony_ci .width(300).height(300).backgroundColor(Color.Black) 967e41f4b71Sopenharmony_ci Particle({particles:[ 968e41f4b71Sopenharmony_ci { 969e41f4b71Sopenharmony_ci emitter:{ 970e41f4b71Sopenharmony_ci particle:{ 971e41f4b71Sopenharmony_ci type:ParticleType.POINT,// Particle type. 972e41f4b71Sopenharmony_ci config:{ 973e41f4b71Sopenharmony_ci radius:10// Point radius. 974e41f4b71Sopenharmony_ci }, 975e41f4b71Sopenharmony_ci count: 500,// Total number of particles. 976e41f4b71Sopenharmony_ci lifetime:10000// Particle lifetime, in ms. 977e41f4b71Sopenharmony_ci }, 978e41f4b71Sopenharmony_ci emitRate:10,// Number of particles emitted per second. 979e41f4b71Sopenharmony_ci position:[0,0], 980e41f4b71Sopenharmony_ci shape:ParticleEmitterShape.RECTANGLE// Emitter shape. 981e41f4b71Sopenharmony_ci }, 982e41f4b71Sopenharmony_ci color:{ 983e41f4b71Sopenharmony_ci range:[Color.Red,Color.Yellow],// Initial color range. 984e41f4b71Sopenharmony_ci updater:{ 985e41f4b71Sopenharmony_ci type:ParticleUpdater.CURVE,// Change with the animation curve. 986e41f4b71Sopenharmony_ci config:[ 987e41f4b71Sopenharmony_ci { 988e41f4b71Sopenharmony_ci from:Color.White,// Initial value of the change. 989e41f4b71Sopenharmony_ci to:Color.Pink,// Target value of the change. 990e41f4b71Sopenharmony_ci startMillis:0,// Start time. 991e41f4b71Sopenharmony_ci endMillis:3000,// End time. 992e41f4b71Sopenharmony_ci curve:Curve.EaseIn// Animation curve. 993e41f4b71Sopenharmony_ci }, 994e41f4b71Sopenharmony_ci { 995e41f4b71Sopenharmony_ci from:Color.Pink, 996e41f4b71Sopenharmony_ci to:Color.Orange, 997e41f4b71Sopenharmony_ci startMillis:3000, 998e41f4b71Sopenharmony_ci endMillis:5000, 999e41f4b71Sopenharmony_ci curve:Curve.EaseIn 1000e41f4b71Sopenharmony_ci }, 1001e41f4b71Sopenharmony_ci { 1002e41f4b71Sopenharmony_ci from:Color.Orange, 1003e41f4b71Sopenharmony_ci to:Color.Pink, 1004e41f4b71Sopenharmony_ci startMillis:5000, 1005e41f4b71Sopenharmony_ci endMillis:8000, 1006e41f4b71Sopenharmony_ci curve:Curve.EaseIn 1007e41f4b71Sopenharmony_ci }, 1008e41f4b71Sopenharmony_ci ] 1009e41f4b71Sopenharmony_ci } 1010e41f4b71Sopenharmony_ci }, 1011e41f4b71Sopenharmony_ci opacity:{ 1012e41f4b71Sopenharmony_ci range:[0.0,1.0],// The initial value of particle opacity is randomly generated from the [0.0, 1.0] range. 1013e41f4b71Sopenharmony_ci updater:{ 1014e41f4b71Sopenharmony_ci type:ParticleUpdater.CURVE, 1015e41f4b71Sopenharmony_ci config:[ 1016e41f4b71Sopenharmony_ci { 1017e41f4b71Sopenharmony_ci from:0.0, 1018e41f4b71Sopenharmony_ci to:1.0, 1019e41f4b71Sopenharmony_ci startMillis:0, 1020e41f4b71Sopenharmony_ci endMillis:3000, 1021e41f4b71Sopenharmony_ci curve:Curve.EaseIn 1022e41f4b71Sopenharmony_ci }, 1023e41f4b71Sopenharmony_ci { 1024e41f4b71Sopenharmony_ci from:1.0, 1025e41f4b71Sopenharmony_ci to:0.0, 1026e41f4b71Sopenharmony_ci startMillis:5000, 1027e41f4b71Sopenharmony_ci endMillis:10000, 1028e41f4b71Sopenharmony_ci curve:Curve.EaseIn 1029e41f4b71Sopenharmony_ci } 1030e41f4b71Sopenharmony_ci ] 1031e41f4b71Sopenharmony_ci } 1032e41f4b71Sopenharmony_ci }, 1033e41f4b71Sopenharmony_ci scale:{ 1034e41f4b71Sopenharmony_ci range:[0.0,0.0], 1035e41f4b71Sopenharmony_ci updater:{ 1036e41f4b71Sopenharmony_ci type:ParticleUpdater.CURVE, 1037e41f4b71Sopenharmony_ci config:[ 1038e41f4b71Sopenharmony_ci { 1039e41f4b71Sopenharmony_ci from:0.0, 1040e41f4b71Sopenharmony_ci to:0.5, 1041e41f4b71Sopenharmony_ci startMillis:0, 1042e41f4b71Sopenharmony_ci endMillis:3000, 1043e41f4b71Sopenharmony_ci curve: Curve.EaseIn 1044e41f4b71Sopenharmony_ci } 1045e41f4b71Sopenharmony_ci ] 1046e41f4b71Sopenharmony_ci } 1047e41f4b71Sopenharmony_ci }, 1048e41f4b71Sopenharmony_ci acceleration:{// Acceleration. speed indicates the acceleration speed, and angle indicates the acceleration direction. 1049e41f4b71Sopenharmony_ci speed:{ 1050e41f4b71Sopenharmony_ci range:[3,9], 1051e41f4b71Sopenharmony_ci updater:{ 1052e41f4b71Sopenharmony_ci type:ParticleUpdater.RANDOM, 1053e41f4b71Sopenharmony_ci config:[1,20] 1054e41f4b71Sopenharmony_ci } 1055e41f4b71Sopenharmony_ci }, 1056e41f4b71Sopenharmony_ci angle:{ 1057e41f4b71Sopenharmony_ci range:[90,90] 1058e41f4b71Sopenharmony_ci } 1059e41f4b71Sopenharmony_ci } 1060e41f4b71Sopenharmony_ci 1061e41f4b71Sopenharmony_ci } 1062e41f4b71Sopenharmony_ci ] 1063e41f4b71Sopenharmony_ci }).width(300).height(300).disturbanceFields([{ 1064e41f4b71Sopenharmony_ci strength:10, 1065e41f4b71Sopenharmony_ci shape:DisturbanceFieldShape.RECT, 1066e41f4b71Sopenharmony_ci size:{width:100,height:100}, 1067e41f4b71Sopenharmony_ci position:{x:100,y:100}, 1068e41f4b71Sopenharmony_ci feather:15, 1069e41f4b71Sopenharmony_ci noiseScale:10, 1070e41f4b71Sopenharmony_ci noiseFrequency:15, 1071e41f4b71Sopenharmony_ci noiseAmplitude:5 1072e41f4b71Sopenharmony_ci }]) 1073e41f4b71Sopenharmony_ci }.width("100%").height("100%").align(Alignment.Center) 1074e41f4b71Sopenharmony_ci } 1075e41f4b71Sopenharmony_ci} 1076e41f4b71Sopenharmony_ci 1077e41f4b71Sopenharmony_ci``` 1078e41f4b71Sopenharmony_ci 1079e41f4b71Sopenharmony_ci 1080e41f4b71Sopenharmony_ci### Example 4 1081e41f4b71Sopenharmony_ciThis example demonstrates how to adjust the position of the particle emitter through **emitter()**. 1082e41f4b71Sopenharmony_ci```ts 1083e41f4b71Sopenharmony_ci@Entry 1084e41f4b71Sopenharmony_ci@Component 1085e41f4b71Sopenharmony_cistruct ParticleExample { 1086e41f4b71Sopenharmony_ci @State emitterProperties: Array<EmitterProperty> = [ 1087e41f4b71Sopenharmony_ci { 1088e41f4b71Sopenharmony_ci index: 0, 1089e41f4b71Sopenharmony_ci emitRate: 100, 1090e41f4b71Sopenharmony_ci position: { x: 60, y: 80 }, 1091e41f4b71Sopenharmony_ci size: { width: 200, height: 200 } 1092e41f4b71Sopenharmony_ci } 1093e41f4b71Sopenharmony_ci ] 1094e41f4b71Sopenharmony_ci 1095e41f4b71Sopenharmony_ci build() { 1096e41f4b71Sopenharmony_ci Stack() { 1097e41f4b71Sopenharmony_ci Text() 1098e41f4b71Sopenharmony_ci .width(300).height(300).backgroundColor(Color.Black) 1099e41f4b71Sopenharmony_ci Particle({ particles: [ 1100e41f4b71Sopenharmony_ci { 1101e41f4b71Sopenharmony_ci emitter: { 1102e41f4b71Sopenharmony_ci particle: { 1103e41f4b71Sopenharmony_ci type: ParticleType.POINT, // Particle type. 1104e41f4b71Sopenharmony_ci config: { 1105e41f4b71Sopenharmony_ci radius: 5// Point radius. 1106e41f4b71Sopenharmony_ci }, 1107e41f4b71Sopenharmony_ci count: 400, // Total number of particles. 1108e41f4b71Sopenharmony_ci lifetime: -1// Particle lifetime. The value -1 indicates that the lifetime of the particle is infinite. 1109e41f4b71Sopenharmony_ci }, 1110e41f4b71Sopenharmony_ci emitRate: 10, // Number of particles emitted per second. 1111e41f4b71Sopenharmony_ci position: [0, 0], // Emitter position. 1112e41f4b71Sopenharmony_ci shape: ParticleEmitterShape.CIRCLE// Emitter shape. 1113e41f4b71Sopenharmony_ci }, 1114e41f4b71Sopenharmony_ci color: { 1115e41f4b71Sopenharmony_ci range: [Color.Red, Color.Yellow], // Initial color range. 1116e41f4b71Sopenharmony_ci updater: { 1117e41f4b71Sopenharmony_ci type: ParticleUpdater.CURVE, // Change with the animation curve. 1118e41f4b71Sopenharmony_ci config: [ 1119e41f4b71Sopenharmony_ci { 1120e41f4b71Sopenharmony_ci from: Color.White, 1121e41f4b71Sopenharmony_ci to: Color.Pink, 1122e41f4b71Sopenharmony_ci startMillis: 0, 1123e41f4b71Sopenharmony_ci endMillis: 3000, 1124e41f4b71Sopenharmony_ci curve: Curve.EaseIn 1125e41f4b71Sopenharmony_ci }, 1126e41f4b71Sopenharmony_ci { 1127e41f4b71Sopenharmony_ci from: Color.Pink, 1128e41f4b71Sopenharmony_ci to: Color.Orange, 1129e41f4b71Sopenharmony_ci startMillis: 3000, 1130e41f4b71Sopenharmony_ci endMillis: 5000, 1131e41f4b71Sopenharmony_ci curve: Curve.EaseIn 1132e41f4b71Sopenharmony_ci }, 1133e41f4b71Sopenharmony_ci { 1134e41f4b71Sopenharmony_ci from: Color.Orange, 1135e41f4b71Sopenharmony_ci to: Color.Pink, 1136e41f4b71Sopenharmony_ci startMillis: 5000, 1137e41f4b71Sopenharmony_ci endMillis: 8000, 1138e41f4b71Sopenharmony_ci curve: Curve.EaseIn 1139e41f4b71Sopenharmony_ci }, 1140e41f4b71Sopenharmony_ci ] 1141e41f4b71Sopenharmony_ci } 1142e41f4b71Sopenharmony_ci }, 1143e41f4b71Sopenharmony_ci }, 1144e41f4b71Sopenharmony_ci ] 1145e41f4b71Sopenharmony_ci }) 1146e41f4b71Sopenharmony_ci .width(300) 1147e41f4b71Sopenharmony_ci .height(300) 1148e41f4b71Sopenharmony_ci .emitter(this.emitterProperties) 1149e41f4b71Sopenharmony_ci }.width("100%").height("100%").align(Alignment.Center) 1150e41f4b71Sopenharmony_ci } 1151e41f4b71Sopenharmony_ci} 1152e41f4b71Sopenharmony_ci``` 1153e41f4b71Sopenharmony_ci 1154