You may adjust to your needs - still some problem with small rects, and no optimized code (too much variables) , but works:
Strict
Graphics 640,480,0
SeedRnd MilliSecs()
Local x = 100
Local y = 100
Local w = 200
Local h = 100
'SetLineWidth 3
While Not KeyDown(KEY_ESCAPE)
x = Rand(0,640)
y = Rand(0,480)
w = Rand(0,640)
h = Rand(0,480)
SetColor Rand(255),Rand(255),Rand(255)
roundrect(x,y,w,h)
FlushMem
Flip
Wend
'================================================
Function RoundRect(x,y,w,h)
'================================================
Local DR = 4
Local R#
If h < w Then
r = Floor(h/dr)
Else
r = Floor(w/dr)
EndIf
Local x1 = x + r
Local y1 = y
Local x2 = x + w - r
Local y2 = y
Local x3 = x + w - 1
Local y3 = y + r
Local x4 = x + w - 1
Local y4 = y + h - r
Local x5 = x2
Local y5 = y + h - 1
Local x6 = x1
Local y6 = y5
Local x7 = x
Local y7 = y4
Local x8 = x
Local y8 = y3
Local xc1 = x1
Local yc1 = y8
Local xc2 = x2
Local yc2 = y3
Local xc3 = x2
Local yc3 = y4
Local xc4 = x1
Local yc4 = y4
'draw lines
'SetColor 0,0,255
DrawLine x1,y1,x2,y2,True
DrawLine x3,y3,x4,y4,True
DrawLine x5,y5,x6,y6,True
DrawLine x7,y7,x8,y8,True
'SetColor 255,255,255
'draw arcs
arc(xc1,yc1,r,180,270)
arc(xc2,yc2,r,270,360)
arc(xc3,yc3,r,0,90)
arc(xc4,yc4,r,90,180)
End Function
'================================================
Function arc(a,b,r,sd,ed)
'================================================
'Plot a,b
If sd < 0 Then
sd = 360 + sd
EndIf
If ed < 0 Then
ed = 360 + ed
EndIf
Local angle,x,y
For angle = sd To ed
x = a + R*Cos(angle)
y = b + R*Sin(angle)
Plot x,y
Next
End Function
Sergio.
|