Skip to content

Commit

Permalink
update handwriting anim
Browse files Browse the repository at this point in the history
  • Loading branch information
nhancv committed Apr 12, 2018
1 parent 9fe7159 commit 2e1ff1c
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 16 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,8 @@ Flutter curves simulation: https://medium.com/p/f935bb225ad2
Flutter simple particle motion: https://medium.com/p/3b48fd1f182

![Preview](demo/demo3/particle_motion.gif)

### Handwriting animation
Funny handwriting animation: https://medium.com/p/1183029b825b

![Preview](demo/beesight/full.gif)
Binary file added demo/beesight/full.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added demo/beesight/full.mp4
Binary file not shown.
Binary file added images/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
44 changes: 29 additions & 15 deletions lib/beesight.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'dart:math';
import 'dart:ui' as ui;
import 'dart:async';
import 'package:flutter/foundation.dart';
import 'package:flutter/widgets.dart';
import 'package:flutter/animation.dart';
Expand Down Expand Up @@ -41,23 +42,30 @@ class DemoBody extends StatefulWidget {
class _DemoBodyState extends State<DemoBody> with TickerProviderStateMixin {
AnimationController animationController;
CharacterFactory characterFactory;
bool drawChar = true;

@override
void initState() {
super.initState();
animationController = new AnimationController(
vsync: this, duration: new Duration(seconds: 2));
vsync: this, duration: new Duration(seconds: 1));

characterFactory = new CharacterFactory();

animationController.addListener(() {
characterFactory.addPoint(animationController.value);
if (drawChar) {
characterFactory.addPoint(animationController.value);
}
});

animationController.addStatusListener((status) {
if (status == AnimationStatus.completed) {
if (characterFactory.step != -1) {
characterFactory.step++;
if (drawChar) {
if (characterFactory.step != -1) {
characterFactory.step++;
} else {
drawChar = false;
}
animationController.reset();
animationController.forward();
}
Expand All @@ -81,10 +89,17 @@ class _DemoBodyState extends State<DemoBody> with TickerProviderStateMixin {
parent: animationController,
curve: Curves.easeInOut,
),
builder: (context, child) => new CustomPaint(
size: widget.screenSize,
painter: new _DemoPainter(widget.screenSize,
characterFactory.offsetPoint, characterFactory.path),
builder: (context, child) => new Container(
child: drawChar
? new CustomPaint(
size: widget.screenSize,
painter: new _DemoPainter(widget.screenSize,
characterFactory.offsetPoint, characterFactory.path),
)
: new Container(
width: animationController.value * 200,
child: new Image.asset('images/icon.png'),
),
),
),
);
Expand All @@ -109,9 +124,9 @@ class _DemoPainter extends CustomPainter {
canvas.drawPath(path, painter);
canvas.drawCircle(offsetPoint, 10.0, painter);

canvas.drawLine(new Offset(0.0, 100.0), new Offset(600.0, 100.0), painter);
canvas.drawLine(new Offset(0.0, 150.0), new Offset(600.0, 150.0), painter);
canvas.drawLine(new Offset(0.0, 200.0), new Offset(600.0, 200.0), painter);
canvas.drawLine(new Offset(0.0, 100.0), new Offset(550.0, 100.0), painter);
canvas.drawLine(new Offset(0.0, 150.0), new Offset(550.0, 150.0), painter);
canvas.drawLine(new Offset(0.0, 200.0), new Offset(550.0, 200.0), painter);
}

@override
Expand Down Expand Up @@ -149,8 +164,8 @@ class CharacterFactory {
tChar(time, 330.0, 15);
sChar(time, 380.0, 18);
oChar(time, 430.0, 19);
fChar(time, 490.0, 20);
finish = tChar(time, 520.0, 22);
fChar(time, 480.0, 20);
finish = tChar(time, 510.0, 22);

if (finish) {
step = -1;
Expand Down Expand Up @@ -247,7 +262,7 @@ class CharacterFactory {
new Offset(20.0 + xOffset, 135.0),
new Offset(20.0 + xOffset, 140.0),
], time);
} else if (step > stepOffset +2) {
} else if (step > stepOffset + 2) {
return true;
}
path.addRect(new Rect.fromCircle(center: offsetPoint, radius: 2.0));
Expand Down Expand Up @@ -376,5 +391,4 @@ class CharacterFactory {
path.addRect(new Rect.fromCircle(center: offsetPoint, radius: 2.0));
return false;
}

}
3 changes: 2 additions & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ flutter:
# included with your application, so that you can use the icons in
# the material Icons class.
uses-material-design: true

assets:
- images/icon.png
# To add assets to your application, add an assets section, like this:
# assets:
# - images/a_dot_burr.jpeg
Expand Down

0 comments on commit 2e1ff1c

Please sign in to comment.