samedi 1 novembre 2014

Custom curved lines in Android


Vote count:

0




I am working on a game where I have some bezier curves. At the moment, everything is fine and it's working as it should, although I do some complicated operation on this curves. To draw the curves I use a canvas and paths, like this:



private void refresh() {
mPath = new Path();
mPath.moveTo(start_x, start_y);
mPath.cubicTo(anchor1_x, anchor1_y, anchor2_x, anchor2_y, end_x, end_y);
}
public void draw(Canvas canvas, Paint paint) {
Path newPath = new Path(mPath);
Matrix mMatrix = new Matrix();
mMatrix.setTranslate(-mCamera.x1, -.mCamera.y1);
mMatrix.postScale(mCamera.getWidthRatio(), mCamera.getHeightRatio());
newPath.transform(mMatrix);
canvas.drawPath(newPath, paint);
}


The paint parameter is ussually the following one:



curvesPaint = new Paint();
curvesPaint.setColor(0xFFFFFFFF);
curvesPaint.setAntiAlias(true);
curvesPaint.setStrokeCap(Paint.Cap.ROUND);
curvesPaint.setStrokeJoin(Paint.Join.ROUND);
curvesPaint.setStyle(Paint.Style.STROKE);
curvesPaint.setStrokeWidth(canvas.getHeight() / 100f);
if (shadow)
curvesPaint.setShadowLayer(canvas.getHeight() / 50f, 0, 0, 0xAAFFFFFF);
else
curvesPaint.setShadowLayer(0, 0, 0, 0xAAFFFFFF);


My question is: how can I make the curves more beautiful? At the moment, they're only white (or white with a white shadow). I want to be able to draw them with a nice gradient or model on them and I have no idea how to do that. I was thinking about the setShader function of the Paint class but I don't know if I can use it for my purpose or how to use it. Other solutions, like drawing multiple paths one above the other, is clearly impractical due to low fps.



asked 4 mins ago







Custom curved lines in Android

Aucun commentaire:

Enregistrer un commentaire