当前位置:网站首页>Custom animation (simulated win10 loading animation) - Optimization
Custom animation (simulated win10 loading animation) - Optimization
2022-06-25 00:26:00 【a10615】
This is a Previous article Imitation of writing Win10 Load the optimized version of the animation
Source code
Updated to github
Optimization analysis
| Native | Custom high imitation (v1 edition ) |
|---|---|
![]() | ![]() |
I always feel that what I write is different from what I write , After careful comparison and observation , Find out :
- The starting positions of the original dots are not all at the bottom , But the first one at the bottom , The next one is followed by the first one , Like a ball in a pipe
- The end of the dot is the beginning of the dot
- After comparison , The time to find a cycle is 7500ms, Not 7000ms
Optimized comparison :
| Native | Custom high imitation (v1.1 edition ) |
|---|---|
![]() | ![]() |
Optimized time correction chart : 
Core code
Undeniable? , Primordial is more natural . For nature , Tried to remove the top of the two uniform motion , Directly use four segments of third-order Bessel curve , It works in principle . But tested N multi-parameter , Later, I still felt that it was not natural , To give up . Finally, I choose the original method .
Calculation of starting angle
The first dot is at the bottom , The angle of the second dot to the center of rotation is one point away from the first , It is also the same with the dot at the back , This angle is different from the previous dot . This angle can be calculated from the radius of the dot and the radius of the track :
// Calculate the angle of the dot to the center of rotation
float trackR = halfSize - dotR;
dotDegree = (float) Math.toDegrees(2 * Math.asin(dotR / trackR));Parameters compared with the previous , A lot of adjustment ( The most important is the parameter , It took countless times to tune it out ……):
/** * Create animation * * @param view Control to be executed * @param index The order in which the control is executed * @return Animation of the control */
private Animator createViewAnim(final View view, final int index) {
long duration = 7500; // A cycle (2 circle ) A total of 7500ms, Fixed value
// Minimum execution unit time
final float minRunUnit = duration / 100f;
// The proportion of the minimum execution unit time to the total time
double minRunPer = minRunUnit / duration;
// Actual value in interpolator (Y Coordinate value ), common 8 Group
final double[] trueRunInOne = new double[]{
0,
0,
160 / 720d,
190 / 720d,
360 / 720d,
520 / 720d,
550 / 720d,
1
};
// The animation start time is greater than the offset . The rest of the time is divided among the dots
final float offset = (float) (index * (100 - 86) * minRunPer / (mDotViews.length - 1));
// The theoretical value in the differentiator (X Coordinate value ), And realRunInOne Corresponding
final double[] rawRunInOne = new double[]{
0,
offset + 0,
offset + 11 * minRunPer,
offset + 32 * minRunPer,
offset + 43 * minRunPer,
offset + 54 * minRunPer,
offset + 75 * minRunPer,
offset + 86 * minRunPer
};
logI("minRunUnit=%f, minRunPer=%f, offset=%f", minRunUnit, minRunPer, offset);
// Of the control points of each Bezier curve Y coordinate
final float p1_2 = calculateLineY(rawRunInOne[2], trueRunInOne[2], rawRunInOne[3], trueRunInOne[3], rawRunInOne[1]);
final float p1_4 = calculateLineY(rawRunInOne[2], trueRunInOne[2], rawRunInOne[3], trueRunInOne[3], rawRunInOne[4]);
final float p1_5 = calculateLineY(rawRunInOne[5], trueRunInOne[5], rawRunInOne[6], trueRunInOne[6], rawRunInOne[4]);
final float p1_7 = calculateLineY(rawRunInOne[5], trueRunInOne[5], rawRunInOne[6], trueRunInOne[6], rawRunInOne[7]);
// A Create attribute animation : Rotate around the center point 2 circle
ObjectAnimator objAnim = ObjectAnimator.ofFloat(view, "rotation", -dotDegree * index, 720 - dotDegree * index);
// B Set the execution time of a cycle
objAnim.setDuration(duration);
// C Set the number of repetitions : It can be repeated indefinitely
objAnim.setRepeatCount(ValueAnimator.INFINITE);
// D Set the differentiator
objAnim.setInterpolator(new TimeInterpolator() {
@Override
public float getInterpolation(float input) {
if (input < rawRunInOne[1]) {
// 1 Waiting to start
if (view.getVisibility() != INVISIBLE) {
view.setVisibility(INVISIBLE);
}
return 0;
} else if (input < rawRunInOne[2]) {
if (view.getVisibility() != VISIBLE) {
view.setVisibility(VISIBLE);
}
// 2 Bottom → top left corner : Bessel curve 1
// First convert to [0, 1] Range
input = calculateNewPercent(rawRunInOne[1], rawRunInOne[2], 0, 1, input);
return calculateBezierQuadratic(trueRunInOne[1], p1_2, trueRunInOne[2], input);
} else if (input < rawRunInOne[3]) {
// 3 top left corner → Top : A straight line
return calculateLineY(rawRunInOne[2], trueRunInOne[2], rawRunInOne[3], trueRunInOne[3], input);
} else if (input < rawRunInOne[4]) {
// 4 Top → Bottom : Bessel curve 2
input = calculateNewPercent(rawRunInOne[3], rawRunInOne[4], 0, 1, input);
return calculateBezierQuadratic(trueRunInOne[3], p1_4, trueRunInOne[4], input);
} else if (input < rawRunInOne[5]) {
// 5 Bottom → top left corner : Bessel curve 3
input = calculateNewPercent(rawRunInOne[4], rawRunInOne[5], 0, 1, input);
return calculateBezierQuadratic(trueRunInOne[4], p1_5, trueRunInOne[5], input);
} else if (input < rawRunInOne[6]) {
// 6 top left corner → Top : A straight line
return calculateLineY(rawRunInOne[5], trueRunInOne[5], rawRunInOne[6], trueRunInOne[6], input);
} else if (input < rawRunInOne[7]) {
// 7 Top → Bottom : Bessel curve 4
input = calculateNewPercent(rawRunInOne[6], rawRunInOne[7], 0, 1, input);
return calculateBezierQuadratic(trueRunInOne[6], p1_7, trueRunInOne[7], input);
} else {
// 8 disappear
if (view.getVisibility() != INVISIBLE) {
view.setVisibility(INVISIBLE);
}
return 1;
}
}
});
return objAnim;
}边栏推荐
- 部门新来的00后真是卷王,工作没两年,跳槽到我们公司起薪18K都快接近我了
- The picture of wechat official account can not be displayed normally
- [issue 25] face to face experience of golang Engineer in the rightmost social recruitment
- Difficult and miscellaneous problems: A Study on the phenomenon of text fuzziness caused by transform
- Is it so difficult to calculate the REM size of the web page according to the design draft?
- 在企业级开发过程中我发现有位同事用select * from where 条件 for update
- Signal integrity (SI) power integrity (PI) learning notes (I) introduction to signal integrity analysis
- 【面试题】什么是事务,什么是脏读、不可重复读、幻读,以及MySQL的几种事务隔离级别的应对方法
- 无需显示屏的VNC Viewer远程连接树莓派
- iNFTnews | 国内NFT发展仅限于数字藏品吗?
猜你喜欢

Technology sharing | wvp+zlmediakit realizes streaming playback of camera gb28181

融合模型权限管理设计方案

不重要的token可以提前停止计算!英伟达提出自适应token的高效视觉Transformer网络A-ViT,提高模型的吞吐量!...

无需显示屏的VNC Viewer远程连接树莓派

Use coordinatorlayout+appbarlayout+collapsingtoolbarlayout to create a collapsed status bar

Discrete mathematics and its application detailed explanation of exercises in the final exam of spring and summer semester of 2018-2019 academic year

人体改造 VS 数字化身

Related operations of ansible and Playbook
More pictures | explain the Nacos parameters in detail!

Infotnews | is the development of domestic NFT limited to digital collections?
随机推荐
Intensive reading of thinking about markdown
傳輸層 以字節為單比特的滑動窗口技術
Collection of software testing and game testing articles
[leaderboard] Carla leaderboard leaderboard leaderboard operation and participation in hands-on teaching
Several ways for wechat applet to jump to the page are worth collecting
Sliding window technology based on byte in transport layer
VNC viewer remote connection raspberry pie without display
JS dynamically generates variable names and assigns values
Time unified system
Related operations of ansible and Playbook
@mysql
Go crawler framework -colly actual combat (I)
What is test development? Can you find a job at this stage?
The drawableleft of the custom textview in kotlin is displayed in the center together with the text
ros(25):rqt_image_view报错Unable to load plugin for transport ‘compressed‘, error string
Report on operation pattern and future prospect of global and Chinese propyl isovalerate industry from 2022 to 2028
在企业级开发过程中我发现有位同事用select * from where 条件 for update
Meta&伯克利基于池化自注意力机制提出通用多尺度视觉Transformer,在ImageNet分类准确率达88.8%!开源...
Eliminate duplicate dependencies
December 6, 2019 what happens after the browser enters a URL


