L
L
Lordao2019-08-01 20:40:02
Android
Lordao, 2019-08-01 20:40:02

How to fill with color the area between lines in android?

There is code that creates two curved lines that extend from the left to the top. How can you fill with the right color the area that has formed between them, taking into account the fact that the lines can move?
5d4323ce2e569709740839.png

public class DrawView extends View {

Paint paint;
Path path1 = new Path();
Path path2 = new 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) {
    super.onDraw(canvas);
    path1.reset();
    path2.reset();

    paint.setColor(Color.RED);
    paint.setStrokeWidth(3);

    path1.moveTo(0, 750);
    path2.moveTo(0, 900);

    path1.cubicTo(185, 250, 599, 177, 585, 0);
    path2.cubicTo(350, 250, 750, 177, 900, 0);

    canvas.drawPath(path1, paint);
    canvas.drawPath(path2, paint);

 }
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmtm, 2019-08-02
@Dmtm

search for two points horizontally, paint with horizontal lines
to speed up - own implementation of a cubic spline, point caching

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question