Rounded Rectangles?

If you have questions about any aspect of QBasic programming, or would like to help fellow programmers solve their problems, check out this board!

Moderators: Pete, Mods

Post Reply
Rocket Boy
Coder
Posts: 19
Joined: Thu Sep 08, 2005 3:14 am

Rounded Rectangles?

Post by Rocket Boy »

Does anyone know how to do this in Qbasic? I've seen it before. It's probably something ridiculously easy... If you don't know, I mean the rectangles with rounded edges, like the buttons in MacOS and stuff like that.
User avatar
Zamaster
Veteran
Posts: 174
Joined: Wed Jun 15, 2005 1:51 pm

Post by Zamaster »

Well, your gonna need on LINE command and one CIRCLE command. Start off by drawing your box of lines except cut them off by whatever the radius of your rounded circle edges will be. Next, draw the circle at the "would be" intersection point of all the lines(top left, top right, ect...) except only draw sections corresponding with the angles so
top left = 90 to 180
top right = 180 to 270
bottom right = 270 to 0
bottom left = 0 to 90

Im sorry, this is really confusing but I dont feel like actually doing any work :? . Ill hope somebody else gives you some code.
C:\DOS
C:\DOS\RUN
RUN\DOS\RUN
User avatar
Kyle
Veteran
Posts: 107
Joined: Thu Apr 14, 2005 2:41 pm

Post by Kyle »

Code: Select all

declare sub rbox(x1,y1,x2,y2,c,r)
const pi=3.1415926

screen 12

rbox 50,50,150,150,6,17

sub rbox(x1,y1,x2,y2,c,r)
     
line (x1,y1+r)-(x1,y2-r),c
line (x1+r,y1)-(x2-r,y1),c
line (x2,y1+r)-(x2,y2-r),c
line (x2-r,y2)-(x1+r,y2),c
circle (x1+r,y1+r),r,c,pi*0.5,pi
circle (x2-r,y1+r),r,c,0,pi*0.5
circle (x1+r,y2-r),r,c,pi,pi*1.5
circle (x2-r,y2-r),r,c,pi*1.5
     
end sub
Enjoy
Rocket Boy
Coder
Posts: 19
Joined: Thu Sep 08, 2005 3:14 am

Post by Rocket Boy »

That's a pretty useful sub... but what would you do if you wanted to be able to fill it with color?
Nodtveidt
Veteran
Posts: 826
Joined: Sun Jul 25, 2004 4:24 am
Location: Quebradillas, PR
Contact:

Post by Nodtveidt »

Do a floodfill I guess...
User avatar
Kyle
Veteran
Posts: 107
Joined: Thu Apr 14, 2005 2:41 pm

Post by Kyle »

Yeah, just a simple paint will do.
User avatar
{Nathan}
Veteran
Posts: 1169
Joined: Thu Aug 19, 2004 6:08 pm
Location: The wetlands of central Ohio, USA
Contact:

Post by {Nathan} »

Kylemc wrote:Yeah, just a simple paint will do.
it seems like some commands (like PAINT, the other use for SCREEN, and and FILE (it is for QB45, just found that out)) are just to underused...
Image
User avatar
Kyle
Veteran
Posts: 107
Joined: Thu Apr 14, 2005 2:41 pm

Post by Kyle »

You forgot GOTO :D
Post Reply