-
Notifications
You must be signed in to change notification settings - Fork 47
/
Copy pathTestAnimation.dart
82 lines (68 loc) · 1.85 KB
/
TestAnimation.dart
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
//Sample Code: Test Animation
import 'dart:math';
import 'package:rikulo_ui/view.dart';
import 'package:rikulo_ui/event.dart';
import 'package:rikulo_ui/effect.dart';
View createCube(int size, String txt) {
View v = new View();
v.width = size;
v.height = size;
v.style.border = "2px solid #3D4C99";
v.style.borderRadius = "10px";
v.style.backgroundColor = "#5C73E5";
v.style.userSelect = "none";
v.style.zIndex = "10";
TextView txtv = new TextView(txt);
txtv.width = v.width;
txtv.style.lineHeight = "${v.height}px";
txtv.style.textAlign = "center";
txtv.style.color = "#EEEEEE";
txtv.style.fontFamily = "Arial";
txtv.style.fontWeight = "bold";
txtv.style.userSelect = "none";
v.addChild(txtv);
return v;
}
void main() {
final View mainView = new View()..addToDocument();
final View cube = createCube(100, "Catch Me");
cube.left = 300;
cube.top = 100;
final Motion motion = new EasingMotion((num x, MotionState state) {
cube.left = 300 + (150 * cos(x * 2 * PI)).toInt();
cube.top = 100 + (50 * sin(x * 4 * PI)).toInt();
}, period: (400 * PI).toInt(), repeat: -1);
/*
int pauseStart = 0;
int offset = 0;
bool paused = false;
*/
cube.on.mouseDown.listen((ViewEvent event) {
motion.pause();
/*
pauseStart = new DateTime.now().millisecondsSinceEpoch;
paused = true;
*/
});
mainView.on.mouseUp.listen((ViewEvent event) {
motion.run();
/*
if (paused) {
offset += new DateTime.now().millisecondsSinceEpoch - pauseStart;
paused = false;
}
*/
});
mainView.addChild(cube);
/*
Animator animator = new Animator();
animator.add((int time, int elapsed) {
if (!paused) {
cube.left = 300 + (150 * cos((time - offset) / 200)).toInt();
cube.top = 100 + (50 * sin((time - offset) / 100)).toInt();
}
return true;
});
*/
motion.run();
}