Skip to content

Instantly share code, notes, and snippets.

@nhancv
Last active April 22, 2018 11:14
Show Gist options
  • Select an option

  • Save nhancv/a4de7b8bc176c6fad091d33545d7f0ae to your computer and use it in GitHub Desktop.

Select an option

Save nhancv/a4de7b8bc176c6fad091d33545d7f0ae to your computer and use it in GitHub Desktop.
Bezier function
Offset getQuadraticBezier(List<Offset> offsetList, double t,
{Canvas canvas, Paint paint}) {
return getQuadraticBezier2(
offsetList, t, 0, offsetList.length - 1, canvas, paint);
}
Offset getQuadraticBezier2(List<Offset> offsetList, double t, int i, int j,
Canvas canvas, Paint paint) {
if (i == j) return offsetList[i];
Offset b0 = getQuadraticBezier2(offsetList, t, i, j - 1, canvas, paint);
Offset b1 = getQuadraticBezier2(offsetList, t, i + 1, j, canvas, paint);
Offset res =
new Offset((1 - t) * b0.dx + t * b1.dx, (1 - t) * b0.dy + t * b1.dy);
if (canvas != null && paint != null) {
canvas.drawLine(b1, b0, paint);
canvas.drawCircle(res, 2.0, paint);
}
return res;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment