Re: Rounded rectangles
Posted: Thu Apr 21, 2011 5:13 am
I still have no clue ways going on. Does anyone else?
The Place to Start for Operating System Developers
https://f.osdev.org/
Code: Select all
//void drawRoundedRectangle(int x0, int y0, int x1, int y1, int radius)
f = 1 - radius;
ddF_x = 1;
ddF_y = -2 * radius;
xx = 0;
yy = radius;
draw_point(x0, y0 + radius); //bottom dot
draw_point(x0, y0 - radius); //top dot
draw_point(x0 + radius, y0); //right dot
draw_point(x0 - radius, y0); //left dot
while(xx < yy)
{
// ddF_x == 2 * x + 1;
// ddF_y == -2 * y;
// f == x*x + y*y - radius*radius + 2*x - y + 1;
if(f >= 0)
{
yy-=1;
ddF_y += 2;
f += ddF_y;
}
xx+=1;
ddF_x += 2;
f += ddF_x;
draw_point(x1 + xx - radius, y1 + yy - radius); //Bottom Right Corner
draw_point(x1 + yy - radius, y1 + xx - radius); //^^^
draw_point(x0 - xx + radius, y1 + yy - radius); //Bottom Left Corner
draw_point(x0 - yy + radius, y1 + xx - radius); //^^^
draw_point(x1 + xx - radius, y0 - yy + radius); //Top Right Corner
draw_point(x1 + yy - radius, y0 - xx + radius); //^^^
draw_point(x0 - xx + radius, y0 - yy + radius); //Top Left Corner
draw_point(x0 - yy + radius, y0 - xx + radius); //^^^
}
draw_line(x0+radius,y0,x1-radius,y0); //top side
draw_line(x0+radius,y1,x1-radius,y1); //botom side
draw_line(x0,y0+radius,x0,y1-radius); //left side
draw_line(x1,y0+radius,x1,y1-radius); //right side