GLBasic forum

Codesnippets => 2D-snippets => Topic started by: Kitty Hello on 2008-May-06

Title: Rounded Rects
Post by: Kitty Hello 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