سؤال

There is almost a duplicate for what I'm asking: almost duplicate

But I want to make the rounded corners at the top.

I tried to modify the code looking at the documentation but I'm pretty new to this drawing in Java and I didn't get it to work. :/

So my question is, how would I modify this:

moveTo(0,0);
lineTo(0, radius);
curveTo(0, 0, radius, radius, 0, radius);
lineTo(width, height - radius);
curveTo(width, height, width, height, width - radius, height);
lineTo(0, height);
closePath();

to make the rounded corners be the top corners.

I really appreciate all answers that can help me with this.

Thanks

هل كانت مفيدة؟

المحلول

The key is you want to visualize how the code is drawing the object. The original code starts at the top left corner and draws in a clockwise direction.

First, you need to move your start point, this will be much easier if you start on a corner, not a rounded edge.

Next, you need to modify your draws so that your rounding the edges in the right place.

moveTo(0, height);
lineTo(0, radius);
curveTo(0, 0, 0, 0, radius, 0);
lineTo(width - radius, 0);
curveTo(width, 0, width, 0, width, radius);
lineTo(width, height);
closePath();

So, what I've done here is:

  1. Start in the bottom left corner
  2. Move vertically to the start of the curve located in the top left corner
  3. Draw the curve in the top left corner
  4. Move horizontally to the start of the curve located in the top right corner
  5. Draw the curve in the top right corner
  6. Move vertically to the bottom right corner
  7. Close the shape (move horizontally to the bottom left corner)
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top