Skip to content

Commit

Permalink
Update README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
xujiaao committed Mar 26, 2019
1 parent 3eb248d commit 0ed86d9
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1 +1,33 @@
# BezierSpline

[Smooth Bézier Spline Through Prescribed Points](https://www.particleincell.com/2012/bezier-splines/) for Android Platform.

Helps to simulate curves such as `Sine Curve`, `Wave` etc...

![Wave](docs/wave.gif)


## Usage

Copy [BezierSpline.java](bezier-spline/src/main/java/com/xujiaao/android/bezier/spline/BezierSpline.java) to your project.

````java
private final Path mPath = new Path();
private final Paint mPaint = new Paint();
private final BezierSpline mBezierSpline = new BezierSpline(20);
...

@Override
protected void onDraw(Canvas canvas) {
final float width = getWidth();
final float density = getResources().getDisplayMetrics().density;
for (int knot = 0, knots = mBezierSpline.knots(); knot < knots; knot++) {
final float x = knot * (width / (knots - 1F));
final float y = (float) (Math.toDegrees(Math.sin(Math.toRadians(x / density))) * density);
mBezierSpline.set(knot, x, y);
}

mBezierSpline.applyToPath(mPath);
canvas.drawPath(mPath, mPaint);
}
````
Binary file added docs/wave.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 0ed86d9

Please sign in to comment.