Skip to content

Commit 2e1ff1c

Browse files
committed
update handwriting anim
1 parent 9fe7159 commit 2e1ff1c

File tree

6 files changed

+36
-16
lines changed

6 files changed

+36
-16
lines changed

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,8 @@ Flutter curves simulation: https://medium.com/p/f935bb225ad2
2323
Flutter simple particle motion: https://medium.com/p/3b48fd1f182
2424

2525
![Preview](demo/demo3/particle_motion.gif)
26+
27+
### Handwriting animation
28+
Funny handwriting animation: https://medium.com/p/1183029b825b
29+
30+
![Preview](demo/beesight/full.gif)

demo/beesight/full.gif

1.42 MB
Loading

demo/beesight/full.mp4

1.96 MB
Binary file not shown.

images/icon.png

28.2 KB
Loading

lib/beesight.dart

Lines changed: 29 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import 'dart:math';
22
import 'dart:ui' as ui;
3+
import 'dart:async';
34
import 'package:flutter/foundation.dart';
45
import 'package:flutter/widgets.dart';
56
import 'package:flutter/animation.dart';
@@ -41,23 +42,30 @@ class DemoBody extends StatefulWidget {
4142
class _DemoBodyState extends State<DemoBody> with TickerProviderStateMixin {
4243
AnimationController animationController;
4344
CharacterFactory characterFactory;
45+
bool drawChar = true;
4446

4547
@override
4648
void initState() {
4749
super.initState();
4850
animationController = new AnimationController(
49-
vsync: this, duration: new Duration(seconds: 2));
51+
vsync: this, duration: new Duration(seconds: 1));
5052

5153
characterFactory = new CharacterFactory();
5254

5355
animationController.addListener(() {
54-
characterFactory.addPoint(animationController.value);
56+
if (drawChar) {
57+
characterFactory.addPoint(animationController.value);
58+
}
5559
});
5660

5761
animationController.addStatusListener((status) {
5862
if (status == AnimationStatus.completed) {
59-
if (characterFactory.step != -1) {
60-
characterFactory.step++;
63+
if (drawChar) {
64+
if (characterFactory.step != -1) {
65+
characterFactory.step++;
66+
} else {
67+
drawChar = false;
68+
}
6169
animationController.reset();
6270
animationController.forward();
6371
}
@@ -81,10 +89,17 @@ class _DemoBodyState extends State<DemoBody> with TickerProviderStateMixin {
8189
parent: animationController,
8290
curve: Curves.easeInOut,
8391
),
84-
builder: (context, child) => new CustomPaint(
85-
size: widget.screenSize,
86-
painter: new _DemoPainter(widget.screenSize,
87-
characterFactory.offsetPoint, characterFactory.path),
92+
builder: (context, child) => new Container(
93+
child: drawChar
94+
? new CustomPaint(
95+
size: widget.screenSize,
96+
painter: new _DemoPainter(widget.screenSize,
97+
characterFactory.offsetPoint, characterFactory.path),
98+
)
99+
: new Container(
100+
width: animationController.value * 200,
101+
child: new Image.asset('images/icon.png'),
102+
),
88103
),
89104
),
90105
);
@@ -109,9 +124,9 @@ class _DemoPainter extends CustomPainter {
109124
canvas.drawPath(path, painter);
110125
canvas.drawCircle(offsetPoint, 10.0, painter);
111126

112-
canvas.drawLine(new Offset(0.0, 100.0), new Offset(600.0, 100.0), painter);
113-
canvas.drawLine(new Offset(0.0, 150.0), new Offset(600.0, 150.0), painter);
114-
canvas.drawLine(new Offset(0.0, 200.0), new Offset(600.0, 200.0), painter);
127+
canvas.drawLine(new Offset(0.0, 100.0), new Offset(550.0, 100.0), painter);
128+
canvas.drawLine(new Offset(0.0, 150.0), new Offset(550.0, 150.0), painter);
129+
canvas.drawLine(new Offset(0.0, 200.0), new Offset(550.0, 200.0), painter);
115130
}
116131

117132
@override
@@ -149,8 +164,8 @@ class CharacterFactory {
149164
tChar(time, 330.0, 15);
150165
sChar(time, 380.0, 18);
151166
oChar(time, 430.0, 19);
152-
fChar(time, 490.0, 20);
153-
finish = tChar(time, 520.0, 22);
167+
fChar(time, 480.0, 20);
168+
finish = tChar(time, 510.0, 22);
154169

155170
if (finish) {
156171
step = -1;
@@ -247,7 +262,7 @@ class CharacterFactory {
247262
new Offset(20.0 + xOffset, 135.0),
248263
new Offset(20.0 + xOffset, 140.0),
249264
], time);
250-
} else if (step > stepOffset +2) {
265+
} else if (step > stepOffset + 2) {
251266
return true;
252267
}
253268
path.addRect(new Rect.fromCircle(center: offsetPoint, radius: 2.0));
@@ -376,5 +391,4 @@ class CharacterFactory {
376391
path.addRect(new Rect.fromCircle(center: offsetPoint, radius: 2.0));
377392
return false;
378393
}
379-
380394
}

pubspec.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ flutter:
2424
# included with your application, so that you can use the icons in
2525
# the material Icons class.
2626
uses-material-design: true
27-
27+
assets:
28+
- images/icon.png
2829
# To add assets to your application, add an assets section, like this:
2930
# assets:
3031
# - images/a_dot_burr.jpeg

0 commit comments

Comments
 (0)