0

I try to draw a comet, by drawLine() with alpha Gradient, but the lines won't connect perfectly like in this image:

http://s14.postimg.org/y5w6pgl6p/Screenshot_2013_07_09_16_14_21.png

the path could be like S shape or C or (keep moving)

using this code :

paint.setStrokeJoin(Paint.Join.BEVEL);
paint.setStrokeWidth(20);
paint.setShader(new LinearGradient(100,200,150,200, 0x00ffff00,0x44ffff00, Shader.TileMode.CLAMP));
canvas.drawLine(100, 200, 150, 200, paint);
paint.setShader(new LinearGradient(150,200,200,220, 0x44ffff00,0x88ffff00, Shader.TileMode.CLAMP));
canvas.drawLine(150, 200, 200, 220, paint);
paint.setShader(new LinearGradient(200, 220, 230, 230, 0x88ffff00, 0xccffff00, Shader.TileMode.CLAMP));
canvas.drawLine(200, 220, 230, 260, paint);
paint.setShader(new LinearGradient(230, 230, 230, 280, 0xccffff00, 0xffffff00, Shader.TileMode.CLAMP));
canvas.drawLine(230,260,230,310,paint);

setStrokeJoin() didn't help for drawLine/s

I converted the Lines into a Path, but the Gradient didn't curve with the whole path

I also draw shapes instead of Lines, to fill the empty space between them, but it took a lot time and CPU to draw on an animated lines.

Any other ideas ?

1 Answer 1

1
Path path = new Path();
path.moveTo(100, 200);
path.lineTo(150, 200);
path.lineTo(200, 220);
path.lineTo(230, 260);
path.lineTo(230,310);
Paint paint = new Paint();
paint.setShader(new LinearGradient(100,200,230,310, 0x00ffff00,0x44ffff00, TileMode.CLAMP));
paint.setStyle(Style.STROKE);
paint.setStrokeWidth(50);
canvas.drawPath(path, paint);

Hope it helps!

1
  • Your app might use hardware acceleration internally. Then a Path will only work as long as the dimension (size) of the canvas is less than the maximum OpenGL texture size. Better performance is achieved with DrawLines (multiple) and if even works if the path is larger or outside the bounds. But it does not support line joins.
    – Matthias
    May 14, 2014 at 10:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.