02-06-2025, 09:08 PM
And just for fun, here's the same as the above, except instead of squares, you can use images!
Code: (Select All)
_Title "Fractal Pictures in QB64PE"
Screen _NewImage(640, 480, 32)
Dim Shared image As Long
image = _LoadImage(_OpenFileDialog$("Select an image file."), 32)
If image >= -1 Then System 'you chose a bad file. We're terminating!
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
_PutImage (x, y)-(x + size, y + size), image
' 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