-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAnimationUtil.cs
53 lines (47 loc) · 1.93 KB
/
AnimationUtil.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Drawing;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace listen2me
{
public static class AnimationUtil
{
public static void AnimateValueLinear(Point begin, Point end, int durationMS, Action<Point> onValueChange, Action onFinish)
{
new Task(() => {
Stopwatch stopWatch = new Stopwatch();
stopWatch.Start();
while (stopWatch.ElapsedMilliseconds < durationMS)
{
double timepoint = (double)stopWatch.ElapsedMilliseconds / (double)durationMS;
int currentPointX = (int)((end.X - begin.X) * timepoint + begin.X);
int currentPointY = (int)((end.Y - begin.Y) * timepoint + begin.Y);
Point currentPoint = new Point(currentPointX, currentPointY);
onValueChange(currentPoint);
}
onFinish?.Invoke();
}).Start();
}
public static void AnimateValueLowPass(Point begin, Point end, int slowness, Action<Point> onValueChange, Action onFinish)
{
new Task(() => {
Stopwatch stopWatch = new Stopwatch();
stopWatch.Start();
double currentPointX = begin.X;
double currentPointY = begin.Y;
while (stopWatch.ElapsedMilliseconds < 500)
{
currentPointX += ((double)end.X - (double)currentPointX) / (double)slowness;
currentPointY += ((double)end.Y - (double)currentPointY) / (double)slowness;
Point currentPoint = new Point((int)currentPointX, (int)currentPointY);
onValueChange(currentPoint);
}
onFinish?.Invoke();
}).Start();
}
}
}