uses gdip

Screen 640,490,1
SetCaption "Constrain Demo"
sys font= LoadFont ("arial",24)
SetSmoothMode 4

Function Constrain(single xb,mi,ma) as single
iF xb > mi and xb < ma then
   Return xb
Else iF xb < mi then
   Return mi
Else iF xb < ma then
   Return ma
End iF   
End Function

single x, y=200, a

While Key(27)=0
ClsColor 10,255,255,255
Text font,200,0,"Constrain Demo",ARGB 255,255,0,0
y=200+100*sin(rad(x))
FillOval x,y,30,30, ARGB 75,255,0,0
y=200+100*cos(rad(x))
FillOval x,y,30,30, ARGB 75,0,255,0
a = Constrain(x,0,sWidth)
iF Constrain(x,0,sWidth) > 0 
   x = x +1
Else
   x=0 
End iF  
Flip
Wend
Ends