Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
nhancv committed Apr 12, 2018
1 parent 084e12e commit 71a5622
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 8 deletions.
Binary file added demo/beesight/b.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
85 changes: 81 additions & 4 deletions lib/beesight.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import 'dart:math';
import 'dart:ui' as ui;
import 'package:flutter/foundation.dart';
import 'package:flutter/widgets.dart';
import 'package:flutter/animation.dart';
Expand All @@ -18,7 +19,10 @@ class _DemoPageState extends State<DemoPage> {
@override
Widget build(BuildContext context) {
return new Scaffold(
body: new DemoBody(screenSize: MediaQuery.of(context).size),
body: new Container(
margin: const EdgeInsets.all(50.0),
child: new DemoBody(screenSize: MediaQuery.of(context).size),
),
);
}
}
Expand All @@ -36,12 +40,30 @@ class DemoBody extends StatefulWidget {

class _DemoBodyState extends State<DemoBody> with TickerProviderStateMixin {
AnimationController animationController;
CharacterFactory characterFactory;

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

characterFactory = new CharacterFactory();

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

animationController.addStatusListener((status) {
if (status == AnimationStatus.completed) {
characterFactory.step++;
animationController.reverse();
} else if (status == AnimationStatus.dismissed) {
characterFactory.step++;
animationController.forward();
}
});
animationController.forward();
}

@override
Expand All @@ -61,7 +83,10 @@ class _DemoBodyState extends State<DemoBody> with TickerProviderStateMixin {
),
builder: (context, child) => new CustomPaint(
size: widget.screenSize,
painter: new _DemoPainter(widget.screenSize),
painter: new _DemoPainter(
widget.screenSize,
characterFactory.offsetPoints,
),
),
),
);
Expand All @@ -70,18 +95,70 @@ class _DemoBodyState extends State<DemoBody> with TickerProviderStateMixin {

class _DemoPainter extends CustomPainter {
final Size screenSize;
final List<Offset> offsetPoints;
Paint painter;

_DemoPainter(this.screenSize) {
_DemoPainter(this.screenSize, this.offsetPoints) {
painter = new Paint()
..strokeWidth = 1.0
..color = Colors.red
..style = PaintingStyle.stroke;
}

@override
void paint(Canvas canvas, Size size) {}
void paint(Canvas canvas, Size size) {
canvas.drawPoints(ui.PointMode.polygon, offsetPoints, painter);
if (offsetPoints.length > 0) {
canvas.drawCircle(offsetPoints[offsetPoints.length - 1], 10.0, painter);
}
}

@override
bool shouldRepaint(_DemoPainter oldDelegate) => true;
}

class CharacterFactory {
List<Offset> offsetPoints = [];
int step = 0;

Offset getQuadraticBezier(List<Offset> offsetList, double t) {
return getQuadraticBezier2(offsetList, t, 0, offsetList.length - 1);
}

Offset getQuadraticBezier2(List<Offset> offsetList, double t, int i, int j) {
if (i == j) return offsetList[i];

Offset b0 = getQuadraticBezier2(offsetList, t, i, j - 1);
Offset b1 = getQuadraticBezier2(offsetList, t, i + 1, j);
Offset res =
new Offset((1 - t) * b0.dx + t * b1.dx, (1 - t) * b0.dy + t * b1.dy);
return res;
}

void addPoint(double time) {
if (step == 0) {
offsetPoints.add(bCharStep1(time));
} else if (step == 1) {
offsetPoints.add(bCharStep2(time));
} else {
step = 0;
offsetPoints.clear();
}
}

Offset bCharStep1(double time) {
return getQuadraticBezier([
new Offset(0.0, 100.0),
new Offset(0.0, 200.0),
], time);
}

Offset bCharStep2(double time) {
return getQuadraticBezier([
new Offset(0.0, 175.0),
new Offset(35.0, 112.0),
new Offset(100.0, 212.0),
new Offset(0.0, 200.0),
], time);
}
}
4 changes: 0 additions & 4 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,10 @@ import 'package:flutter/material.dart';
//import 'demo2.dart';
//import 'demo3.dart';
import 'beesight.dart';
import 'dartpros.dart';

void main() => runApp(new MyApp());

class MyApp extends StatelessWidget {
MyApp() {
new April.origin()..getOdd()..printString();
}

@override
Widget build(BuildContext context) {
Expand Down

0 comments on commit 71a5622

Please sign in to comment.