-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
32 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
```` |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.