Skip to content

Commit

Permalink
beesight draw
Browse files Browse the repository at this point in the history
  • Loading branch information
nhancv committed Apr 12, 2018
1 parent 71a5622 commit 9fe7159
Show file tree
Hide file tree
Showing 3 changed files with 256 additions and 47 deletions.
Binary file added demo/beesight/beesight.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
288 changes: 252 additions & 36 deletions lib/beesight.dart
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,11 @@ class _DemoBodyState extends State<DemoBody> with TickerProviderStateMixin {

animationController.addStatusListener((status) {
if (status == AnimationStatus.completed) {
characterFactory.step++;
animationController.reverse();
} else if (status == AnimationStatus.dismissed) {
characterFactory.step++;
animationController.forward();
if (characterFactory.step != -1) {
characterFactory.step++;
animationController.reset();
animationController.forward();
}
}
});
animationController.forward();
Expand All @@ -83,10 +83,8 @@ class _DemoBodyState extends State<DemoBody> with TickerProviderStateMixin {
),
builder: (context, child) => new CustomPaint(
size: widget.screenSize,
painter: new _DemoPainter(
widget.screenSize,
characterFactory.offsetPoints,
),
painter: new _DemoPainter(widget.screenSize,
characterFactory.offsetPoint, characterFactory.path),
),
),
);
Expand All @@ -95,30 +93,34 @@ class _DemoBodyState extends State<DemoBody> with TickerProviderStateMixin {

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

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

@override
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);
}
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);
}

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

class CharacterFactory {
List<Offset> offsetPoints = [];
Offset offsetPoint;
Path path = new Path();
int step = 0;

Offset getQuadraticBezier(List<Offset> offsetList, double t) {
Expand All @@ -136,29 +138,243 @@ class CharacterFactory {
}

void addPoint(double time) {
if (step == 0) {
offsetPoints.add(bCharStep1(time));
} else if (step == 1) {
offsetPoints.add(bCharStep2(time));
} else {
step = 0;
offsetPoints.clear();
bool finish = false;
bChar(time, 0.0, 0);
eChar(time, 50.0, 2);
eChar(time, 100.0, 4);
sChar(time, 150.0, 6);
iChar(time, 185.0, 7);
gChar(time, 230.0, 10);
hChar(time, 290.0, 13);
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);

if (finish) {
step = -1;
}
}

bool bChar(double time, [double xOffset = 0.0, int stepOffset = 0]) {
if (step == stepOffset) {
path.moveTo(0.0 + xOffset, 100.0);
offsetPoint = getQuadraticBezier([
new Offset(0.0 + xOffset, 100.0),
new Offset(0.0 + xOffset, 200.0),
], time);
} else if (step == stepOffset + 1) {
path.moveTo(0.0 + xOffset, 175.0);
offsetPoint = getQuadraticBezier([
new Offset(0.0 + xOffset, 175.0),
new Offset(35.0 + xOffset, 100.0),
new Offset(80.0 + xOffset, 212.0),
new Offset(0.0 + xOffset, 200.0),
], time);
} else if (step > stepOffset + 1) {
return true;
}
path.addRect(new Rect.fromCircle(center: offsetPoint, radius: 2.0));
return false;
}

bool eChar(double time, [double xOffset = 0.0, int stepOffset = 0]) {
if (step == stepOffset) {
path.moveTo(0.0 + xOffset, 185.0);
offsetPoint = getQuadraticBezier([
new Offset(0.0 + xOffset, 185.0),
new Offset(60.0 + xOffset, 165.0),
new Offset(45.0 + xOffset, 150.0),
new Offset(25.0 + xOffset, 150.0),
], time);
} else if (step == stepOffset + 1) {
path.moveTo(25.0 + xOffset, 150.0);
offsetPoint = getQuadraticBezier([
new Offset(25.0 + xOffset, 150.0),
new Offset(0.0 + xOffset, 155.0),
new Offset(-5.0 + xOffset, 200.0),
new Offset(5.0 + xOffset, 215.0),
new Offset(40.0 + xOffset, 185.0),
], time);
} else if (step > stepOffset + 1) {
return true;
}
path.addRect(new Rect.fromCircle(center: offsetPoint, radius: 2.0));
return false;
}

Offset bCharStep1(double time) {
return getQuadraticBezier([
new Offset(0.0, 100.0),
new Offset(0.0, 200.0),
], time);
bool sChar(double time, [double xOffset = 0.0, int stepOffset = 0]) {
if (step == stepOffset) {
path.moveTo(40.0 + xOffset, 165.0);
offsetPoint = getQuadraticBezier([
new Offset(40.0 + xOffset, 165.0),
new Offset(40.0 + xOffset, 135.0),
new Offset(0.0 + xOffset, 150.0),
new Offset(-20.0 + xOffset, 155.0),
new Offset(-20.0 + xOffset, 175.0),
new Offset(100.0 + xOffset, 180.0),
new Offset(50.0 + xOffset, 185.0),
new Offset(50.0 + xOffset, 215.0),
new Offset(25.0 + xOffset, 205.0),
new Offset(15.0 + xOffset, 200.0),
new Offset(0.0 + xOffset, 185.0),
], time);
} else if (step > stepOffset) {
return true;
}
path.addRect(new Rect.fromCircle(center: offsetPoint, radius: 2.0));
return false;
}

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);
bool iChar(double time, [double xOffset = 0.0, int stepOffset = 0]) {
if (step == stepOffset) {
path.moveTo(20.0 + xOffset, 150.0);
offsetPoint = getQuadraticBezier([
new Offset(20.0 + xOffset, 150.0),
new Offset(20.0 + xOffset, 195.0),
], time);
} else if (step == stepOffset + 1) {
path.moveTo(20.0 + xOffset, 195.0);
offsetPoint = getQuadraticBezier([
new Offset(20.0 + xOffset, 195.0),
new Offset(25.0 + xOffset, 205.0),
new Offset(35.0 + xOffset, 195.0),
], time);
} else if (step == stepOffset + 2) {
path.moveTo(20.0 + xOffset, 135.0);
offsetPoint = getQuadraticBezier([
new Offset(20.0 + xOffset, 135.0),
new Offset(20.0 + xOffset, 140.0),
], time);
} else if (step > stepOffset +2) {
return true;
}
path.addRect(new Rect.fromCircle(center: offsetPoint, radius: 2.0));
return false;
}

bool gChar(double time, [double xOffset = 0.0, int stepOffset = 0]) {
if (step == stepOffset) {
path.moveTo(40.0 + xOffset, 150.0);
offsetPoint = getQuadraticBezier([
new Offset(40.0 + xOffset, 150.0),
new Offset(-5.0 + xOffset, 150.0),
new Offset(0.0 + xOffset, 200.0),
new Offset(0.0 + xOffset, 215.0),
new Offset(20.0 + xOffset, 200.0),
new Offset(40.0 + xOffset, 180.0),
], time);
} else if (step == stepOffset + 1) {
path.moveTo(40.0 + xOffset, 150.0);
offsetPoint = getQuadraticBezier([
new Offset(40.0 + xOffset, 150.0),
new Offset(40.0 + xOffset, 240.0),
], time);
} else if (step == stepOffset + 2) {
path.moveTo(40.0 + xOffset, 240.0);
offsetPoint = getQuadraticBezier([
new Offset(40.0 + xOffset, 240.0),
new Offset(35.0 + xOffset, 285.0),
new Offset(10.0 + xOffset, 285.0),
new Offset(-15.0 + xOffset, 250.0),
new Offset(45.0 + xOffset, 215.0),
], time);
} else if (step > stepOffset + 2) {
return true;
}
path.addRect(new Rect.fromCircle(center: offsetPoint, radius: 2.0));
return false;
}

bool hChar(double time, [double xOffset = 0.0, int stepOffset = 0]) {
if (step == stepOffset) {
path.moveTo(0.0 + xOffset, 100.0);
offsetPoint = getQuadraticBezier([
new Offset(0.0 + xOffset, 100.0),
new Offset(0.0 + xOffset, 200.0),
], time);
} else if (step == stepOffset + 1) {
path.moveTo(0.0 + xOffset, 175.0);
offsetPoint = getQuadraticBezier([
new Offset(0.0 + xOffset, 175.0),
new Offset(45.0 + xOffset, 120.0),
new Offset(45.0 + xOffset, 200.0),
], time);
} else if (step > stepOffset + 1) {
return true;
}
path.addRect(new Rect.fromCircle(center: offsetPoint, radius: 2.0));
return false;
}

bool tChar(double time, [double xOffset = 0.0, int stepOffset = 0]) {
if (step == stepOffset) {
path.moveTo(25.0 + xOffset, 100.0);
offsetPoint = getQuadraticBezier([
new Offset(25.0 + xOffset, 100.0),
new Offset(25.0 + xOffset, 195.0),
], time);
} else if (step == stepOffset + 1) {
path.moveTo(25.0 + xOffset, 195.0);
offsetPoint = getQuadraticBezier([
new Offset(25.0 + xOffset, 195.0),
new Offset(30.0 + xOffset, 205.0),
new Offset(45.0 + xOffset, 200.0),
], time);
} else if (step == stepOffset + 2) {
path.moveTo(10.0 + xOffset, 145.0);
offsetPoint = getQuadraticBezier([
new Offset(10.0 + xOffset, 145.0),
new Offset(25.0 + xOffset, 150.0),
new Offset(45.0 + xOffset, 145.0),
], time);
} else if (step > stepOffset + 2) {
return true;
}
path.addRect(new Rect.fromCircle(center: offsetPoint, radius: 2.0));
return false;
}

bool oChar(double time, [double xOffset = 0.0, int stepOffset = 0]) {
if (step == stepOffset) {
path.moveTo(25.0 + xOffset, 150.0);
offsetPoint = getQuadraticBezier([
new Offset(25.0 + xOffset, 150.0),
new Offset(-5.0 + xOffset, 175.0),
new Offset(-5.0 + xOffset, 200.0),
new Offset(25.0 + xOffset, 235.0),
new Offset(65.0 + xOffset, 175.0),
new Offset(65.0 + xOffset, 150.0),
new Offset(25.0 + xOffset, 150.0),
], time);
} else if (step > stepOffset) {
return true;
}
path.addRect(new Rect.fromCircle(center: offsetPoint, radius: 2.0));
return false;
}

bool fChar(double time, [double xOffset = 0.0, int stepOffset = 0]) {
if (step == stepOffset) {
path.moveTo(40.0 + xOffset, 100.0);
offsetPoint = getQuadraticBezier([
new Offset(40.0 + xOffset, 100.0),
new Offset(-15.0 + xOffset, 100.0),
new Offset(50.0 + xOffset, 200.0),
new Offset(0.0 + xOffset, 200.0),
], time);
} else if (step == stepOffset + 1) {
path.moveTo(0.0 + xOffset, 140.0);
offsetPoint = getQuadraticBezier([
new Offset(0.0 + xOffset, 140.0),
new Offset(30.0 + xOffset, 125.0),
], time);
} else if (step > stepOffset + 1) {
return true;
}
path.addRect(new Rect.fromCircle(center: offsetPoint, radius: 2.0));
return false;
}

}
15 changes: 4 additions & 11 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ packages:
name: barback
url: "https://pub.dartlang.org"
source: hosted
version: "0.15.2+14"
version: "0.15.2+15"
boolean_selector:
dependency: transitive
description:
Expand Down Expand Up @@ -84,7 +84,7 @@ packages:
name: cupertino_icons
url: "https://pub.dartlang.org"
source: hosted
version: "0.1.1"
version: "0.1.2"
flutter:
dependency: "direct main"
description: flutter
Expand Down Expand Up @@ -193,13 +193,6 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "0.9.6"
mockito:
dependency: transitive
description:
name: mockito
url: "https://pub.dartlang.org"
source: hosted
version: "2.2.3"
multi_server_socket:
dependency: transitive
description:
Expand Down Expand Up @@ -351,7 +344,7 @@ packages:
name: test
url: "https://pub.dartlang.org"
source: hosted
version: "0.12.32+1"
version: "0.12.32+2"
typed_data:
dependency: transitive
description:
Expand Down Expand Up @@ -395,4 +388,4 @@ packages:
source: hosted
version: "2.1.13"
sdks:
dart: ">=2.0.0-dev.23.0 <=2.0.0-edge.0d5cf900b021bf5c9fa593ffa12b15bcd1cc5fe0"
dart: ">=2.0.0-dev.28.0 <=2.0.0-edge.0d5cf900b021bf5c9fa593ffa12b15bcd1cc5fe0"

0 comments on commit 9fe7159

Please sign in to comment.