# confetti
**Repository Path**: chinasoft4_ohos/confetti
## Basic Information
- **Project Name**: confetti
- **Description**: 雪花动画
- **Primary Language**: Java
- **License**: Apache-2.0
- **Default Branch**: master
- **Homepage**: None
- **GVP Project**: No
## Statistics
- **Stars**: 1
- **Forks**: 2
- **Created**: 2021-06-15
- **Last Updated**: 2024-01-12
## Categories & Tags
**Categories**: harmonyos-animate
**Tags**: None
## README
# confetti
#### 项目介绍
- 项目名称:confetti
- 所属系列:openharmony的第三方组件适配移植
- 功能:一个高性能,易于配置粒子系统库,可以通过空间动画任何一组物体
- 项目移植状态:主功能完成
- 调用差异:无
- 开发版本:sdk6,DevEco Studio2.2 Beta1
- 基线版本:release 1.1.1
#### 效果演示
#### 安装教程
1.在项目根目录下的build.gradle文件中,
```gradle
allprojects {
repositories {
maven {
url 'https://s01.oss.sonatype.org/content/repositories/releases/'
}
}
}
```
2.在entry模块的build.gradle文件中,
```gradle
dependencies {
implementation('com.gitee.chinasoft_ohos:Confetti:1.0.0')
......
}
```
在sdk6,DevEco Studio 2.2 Beta1下项目可直接运行
如无法运行,删除项目.gradle,.idea,build,gradle,build.gradle文件,
并依据自己的版本创建新项目,将新项目的对应文件复制到根目录下
#### 使用说明
每次调用GenerateConfetto都必须生成一个全新的。
Confetto对象(ConfettiManager将根据需要回收生成的五彩纸屑,可能会看到对GenerateConfetto的调用越来越少)。我们传入一个。
Random给GenerateConfetto,如果您想从列表中随机生成五彩纸屑,请将其转换为GenerateConfetto。
```java
final List allPossibleConfetti = constructBitmapsForConfetti();
final int numConfetti = allPossibleConfetti.size();
final ConfettoGenerator confettoGenerator = new ConfettoGenerator() {
@Override
public Confetto generateConfetto(Random random) {
final Bitmap bitmap = allPossibleConfetti.get(random.nextInt(numConfetti));
return new BitmapConfetto(bitmap);
}
}
```
一旦我们有了我们的ConfettoGenerator,我们就需要定义一个‘ConfettiSource`,其中的五彩纸屑。
会出现在。此源可以是任何任意点或线。
```java
final int containerMiddleX = container.getWidth() / 2;
final int containerMiddleY = container.getHeight() / 2;
final ConfettiSource confettiSource = new ConfettiSource(containerMiddleX, containerMiddleY);
```
使用animate()开始,将根据需要创建和配置各种Confetto对象,创建一个新的ConfettiView,初始化所有组件的正确状态,开始动画。
ConfettiView将自动分离自己一次所有的纸屑都结束了,从屏幕上消失了。
```java
new ConfettiManager(context, confettoGenerator, confettiSource, container)
.setEmissionDuration(1000)
.setEmissionRate(100)
.setVelocityX(20, 10)
.setVelocityY(100)
.setRotationalVelocity(180, 180)
.animate();
```
ConfettiManager易于配置。为了简单起见,所有的速度和。加速属性以每秒像素数或每秒像素数^2为单位,而所有原始。时间属性(如ttl、emastDuration)以毫秒为单位。
您将注意到大多数物理属性的设置器(例如,速度、加速度、旋转)可以接受一个参数作为实际值,也可以接受两个参数。参数允许您指定一个随机偏差,如果您希望将行为随机化,所有生成的五彩纸屑。
```java
confettiManager.setVelocityX(200f, 50f);
```
您可以允许用户触摸并拖动屏幕上的纸屑。当用户放开纸屑时,纸屑将从该位置开始,用户启动速度和预先配置的加速并从那里恢复动画。
```java
confettiManager.setTouchEnabled(true)
```
#### 测试信息
CodeCheck代码测试无异常
CloudTest代码测试无异常
病毒安全检测通过
当前版本demo功能与原组件基本无差异
#### 版本迭代
- 1.0.0
#### 版权和许可信息
Copyright 2016 Robinhood Markets, Inc.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.