Just a lil contest for fun to see who can align random sized boxes the fastest.
Rules:
1. Align boxes next to one another without overlaping on screen.
2. Waste minimum screen space.
Heres my super fast boxAlign Entry:
Rules:
1. Align boxes next to one another without overlaping on screen.
2. Waste minimum screen space.
Heres my super fast boxAlign Entry:
Type box Field id,x,y,w,h End Type Function boxAlign() ;Purpose: align boxes ;Parameters: None ;return: None For box.box = Each box Repeat ;reset overlap counter and test against all boxes, except self boxesoverlap=0 For box2.box = Each box If box<>box2 boxesoverlap=boxesoverlap+RectsOverlap(box\x,box\y,box\w,box\h,box2\x,box2\y,box2\w,box2\h) End If Next ;if box overlaps any of the others, move it and check again If boxesoverlap box\x=box\x+1 If box\x>(GraphicsWidth()-box\w) box\y=box\y+1 box\x=0 EndIf EndIf Until Not boxesoverlap Next End Function .MAIN Graphics 800,600,16,2 SetBuffer(BackBuffer()) ;make some random sized boxes For loop = 1 To 48 box.box = New box box\id=loop box\w=Rnd(112)+12 box\h=Rnd(112)+12 Next starttime=MilliSecs() boxAlign() stoptime=MilliSecs()-starttime ;display the boxes Color 63,127,255 For boxd.box = Each box Text boxd\x,boxd\y,boxd\id Rect boxd\x,boxd\y,boxd\w,boxd\h,0 Next Flip() Color 255,255,255 Print stoptime WaitKey()