how to generate a bezier curve code example
Example 1: what is the use of cubic bezier in html
In CSS, the cubic-bezier curve is used to control how the animation
will play throughout. The shape of the curve represents the animation play.
The curve lies on a 1 by 1 co-ordinate system.The X-axis implies the
duration(time) of the animation. The Y-axis implies the change in the
animation. The curve mainly has four points of which two points are specific.
The two points are the origin O(0,0) and the other is (1,1).
The other two points are defined by us (x1,y1) and (x2,y2).
The code goes like this--
animation-timing-function: cubic-bezier(x1,y1,x2,y2);
The co-ordinate system--
(Y-AXIS)
[CHANGE IN ANIMATION] /|\
|
| . (1,1)
|
|
|
|
|
| (X-AXIS)
/____________________________._________________________________\
\ o(0,0) | /
| [DURATION IN ANIMATION]
|
|
|
|
|
|
|
\|/
Example 2: How to draw Bezier Curve in Android
public class DrawView extends View {
Paint paint;
Path path;
public DrawView(Context context) {
super(context);
init();
}
public DrawView(Context context, AttributeSet attrs) {
super(context, attrs);
init();
}
public DrawView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
init();
}
private void init(){
paint = new Paint();
paint.setStyle(Paint.Style.STROKE);
}
@Override
protected void onDraw(Canvas canvas) {
// TODO Auto-generated method stub
super.onDraw(canvas);
path = new Path();
paint.setColor(Color.RED);
paint.setStrokeWidth(3);
path.moveTo(34, 259);
path.cubicTo(68, 151, 286, 350, 336, 252);
canvas.drawPath(path, paint);
}