Rounded rectangles

Post Reply
User avatar
Dutchman
Posts: 925
Joined: Mon May 06, 2013 9:21 am
My devices: iMac, iPad Air, iPhone
Location: Netherlands
Flag: Netherlands

Rounded rectangles

Post by Dutchman » Fri Jan 10, 2014 8:01 pm

The following program contains functions to draw rounded rectangles, with or without borders.

Code: Select all

'Rounded filled rectangle with border
' by Dutchman, january 2014
sw=SCREEN_WIDTH() ! sh=SCREEN_HEIGHT()
GRAPHICS
x=sw/3 ! y=sh/3
width=sw/3 ! height=sh/3
Radius=20 ! border=sw/100
CALL RoundedPanel(x,y,width,height,radius,border,1,1,0,0,0,1)
END
'
' ===== Functions =====
DEF RoundedPanel(x,y,width,height,radius,border,Rb,Gb,Bb,Rf,Gf,Bf)
' draw filledrectangle with coloured border
' Rb,Gb,Bb is the bordercolor, Rf,Gf,Bf is the fill color
FILL COLOR Rb,Gb,Bb
RoundedRect(x,y,width,height,radius)
FILL COLOR Rf,Gf,Bf
RoundedRect(x+border,y+border,width-2*border,height-2*border,radius-border)
END DEF
'
DEF RoundedRect(x,y,xsize,ysize,radius)
' draw rectangle with rounded corners
' color should be set in advance with 'FILL COLOR r,g,b'
xmax=x+xsize ! ymax=y+ysize ! r2=2*radius
FILL CIRCLE x,y TO x+r2,y+r2
FILL CIRCLE xmax,y TO xmax-r2,y+r2
FILL CIRCLE xmax,ymax TO xmax-r2,ymax-r2
FILL CIRCLE x,ymax TO x+r2,ymax-r2
FILL RECT x,y+radius TO xmax,ymax-radius
FILL RECT x+radius,y TO xmax-radius,ymax
END DEF
We consider it a refreshing mental exercise to figure out ways to circumvent foolishness (Quote from Richard)

User avatar
Mr. Kibernetik
Site Admin
Posts: 4607
Joined: Mon Nov 19, 2012 10:16 pm
My devices: iPad, iPhone, MacBook
Location: Russia
Flag: Russia

Re: Rounded rectangles

Post by Mr. Kibernetik » Fri Jan 10, 2014 8:35 pm

Very nice!

Post Reply