Development goes on. ⚡️👟QB64 v2.0.2 released! 🤩🤩🤩🤩Get it now!
0 Members and 1 Guest are viewing this topic.
Another idea from Shiffman, Circle Packing.Basic random fill:Code: QB64: [Select]_TITLE "Circle Packing 1 fill" 'B+ started 2019-04-07 just basic random fill spaceCONST xmax = 800CONST ymax = 600SCREEN _NEWIMAGE(xmax, ymax, 32)_SCREENMOVE _MIDDLE TYPE CircleType x AS SINGLE y AS SINGLE r AS SINGLE c AS _UNSIGNED LONG growing AS INTEGEREND TYPEREDIM SHARED circles(1 TO 1) AS CircleTypeDIM SHARED flagDone AS INTEGER WHILE _KEYDOWN(27) = 0 AND flagDone = 0 CLS newCircle 1 drawCircles _DISPLAY _LIMIT 60WENDPRINT "done" SUB drawCircles FOR i = 1 TO UBOUND(circles) IF circles(i).growing THEN 'check new r testr = circles(i).r + 2 IF circles(i).x - testr < 0 OR circles(i).x + testr > xmax OR circles(i).y - testr < 0 OR circles(i).y + testr > ymax THEN circles(i).growing = 0 ELSE 'check if run into another circle FOR j = 1 TO UBOUND(circles) IF j <> i THEN IF SQR((circles(j).x - circles(i).x) ^ 2 + (circles(j).y - circles(i).y) ^ 2) <= testr + circles(j).r THEN circles(i).growing = 0: circles(j).growing = 0 EXIT FOR END IF END IF NEXT END IF END IF IF circles(i).growing THEN circles(i).r = testr fcirc circles(i).x, circles(i).y, circles(i).r, circles(i).c NEXT PRINT UBOUND(circles)END SUB SUB newCircle (n) FOR i = 1 TO n attempts = 0 retry: testX = RND * xmax: testY = RND * ymax OK = -1 FOR j = 1 TO UBOUND(circles) IF SQR((testX - circles(j).x) ^ 2 + (testY - circles(j).y) ^ 2) < circles(j).r + 2 THEN OK = 0: EXIT FOR NEXT IF OK THEN new = UBOUND(circles) + 1 REDIM _PRESERVE circles(1 TO new) AS CircleType circles(new).x = testX circles(new).y = testY circles(new).r = 1 circles(new).growing = -1 circles(new).c = _RGB32(RND * 155 + 100, RND * 155 + 100, RND * 155 + 100) ELSE attempts = attempts + 1 IF attempts > 3000 THEN flagDone = -1: EXIT SUB GOTO retry END IF NEXTEND SUB 'from Steve Gold standardSUB fcirc (CX AS INTEGER, CY AS INTEGER, R AS INTEGER, C AS _UNSIGNED LONG) DIM Radius AS INTEGER, RadiusError AS INTEGER DIM X AS INTEGER, Y AS INTEGER Radius = ABS(R) RadiusError = -Radius X = Radius Y = 0 IF Radius = 0 THEN PSET (CX, CY), C: EXIT SUB ' Draw the middle span here so we don't draw it twice in the main loop, ' which would be a problem with blending turned on. LINE (CX - X, CY)-(CX + X, CY), C, BF WHILE X > Y RadiusError = RadiusError + Y * 2 + 1 IF RadiusError >= 0 THEN IF X <> Y + 1 THEN LINE (CX - Y, CY - X)-(CX + Y, CY - X), C, BF LINE (CX - Y, CY + X)-(CX + Y, CY + X), C, BF END IF X = X - 1 RadiusError = RadiusError - X * 2 END IF Y = Y + 1 LINE (CX - X, CY - Y)-(CX + X, CY - Y), C, BF LINE (CX - X, CY + Y)-(CX + X, CY + Y), C, BF WENDEND SUB It's more fun with images: