02-06-2025, 09:01 PM
Code: (Select All)
_Title "Fractal Squares in QB64PE"
Screen _NewImage(640, 480, 32)
Dim Shared maxDepth
For maxDepth = 0 To 8
Cls , &HFF000000&&
drawSquare 220, 140, 200, 0 'center the initial square
_Display
_Delay 2
Next
System
Sub drawSquare (x, y, size, depth)
If depth > maxDepth Then Exit Sub
' Draw the current square
Line (x, y)-(x + size, y + size), , B
' Calculate new size and new depth
newSize = size / 2
newDepth = depth + 1
' Recursively draw smaller squares in each corner
drawSquare x - newSize / 2, y - newSize / 2, newSize, newDepth
drawSquare x + size - newSize / 2, y - newSize / 2, newSize, newDepth
drawSquare x - newSize / 2, y + size - newSize / 2, newSize, newDepth
drawSquare x + size - newSize / 2, y + size - newSize / 2, newSize, newDepth
End Sub