### Author Topic: Rounded Rects  (Read 4327 times)

#### Kitty Hello

• code monkey
• Prof. Inline
• Posts: 10651
• here on my island the sea says 'hello'
##### Rounded Rects
« on: 2008-May-06 »
Code: GLBasic [Select]

FOR i=0 TO 100
RoundRect(RND(500),RND(400),40+RND(200),40+RND(200),24,RGB(RND(255),255,RND(255)))
NEXT
USEASBMP

WHILE TRUE

MOUSESTATE mx, my, b1, b2
RoundRectBorder(mx,my, 250,150, 16, 8, RGB(0x80, 0x80, 0xff), RGB(0xff,0xff,0xff), 16)
RoundRectBorder(mx,my, 250, 40, 16, 8, RGB(0x80, 0xff, 0x80), RGB(0xff,0xff,0xff), 0)
PRINT "OBJECTIVE:", mx+12, my+12
PRINT "Draw round rectangles", mx+12, my+60
SHOWSCREEN
WEND

ALPHAMODE -.5
ENDIF
ALPHAMODE 0
RoundRect(x,y,w,h,r,col_border)
RoundRect(x+border,y+border, w-2*border, h-2*border, r-border, col)
ENDFUNCTION

FUNCTION RoundRect: x,y,w,h,r,col
// polyvector way of doing it:
STARTPOLY -1
RRCircle(x+r,  y+r,    90,180, r,col)
RRCircle(x+r,  y+h-r, 180,270, r,col)
RRCircle(x+w-r,y+h-r, 270,360, r,col)
RRCircle(x+w-r,y+r,   360,450, r,col)

ENDPOLY
ENDFUNCTION

FUNCTION RRCircle: x,y,phi1, phi2, r, col
LOCAL p
FOR p=phi1 TO phi2+0.00001 STEP (phi2-phi1)/16
POLYVECTOR x+COS(p)*r, y-SIN(p)*r, 0,0,col
NEXT
ENDFUNCTION

« Last Edit: 2008-May-06 by Gernot Frisch »

#### AndyH

• Dr. Type
• Posts: 383
##### Re: Rounded Rects
« Reply #1 on: 2008-May-06 »
Very nice!

#### mentalthink

• Prof. Inline
• Posts: 3328
• Integrated Brain
##### Re: Rounded Rects
« Reply #2 on: 2013-Oct-21 »
Very Usefull for buttons, I never see this post... (some ordner in the forum I think it's needed some list or something)