09-25-2024, 12:26 PM
Has anyone made a routine to copy a paste a non-rectangular area of the screen? Or does QB64PE have a built-in way? I'm working on a new drawing program and trying to add a feature where you can draw an enclosed area with the mouse, copy it, and paste it. Making a circle area routine was easy, but having some difficulty with the any shape one. I'm doing a polygon approach for the any shaped one, capture all the pixels inside the drawn polygon. Wondered if someone here has already made such a routine that is working.
Here's the circle copy/paste that is working ok.
- Dav
Here's the circle copy/paste that is working ok.
- Dav
Code: (Select All)
Screen _NewImage(1000, 700, 32)
For t = 1 To 7000
Color _RGB(Rnd * 255, Rnd * 255, Rnd * 255)
Print _Trim$(Str$(Int(Rnd * 10)));
Next
Circle (100, 100), 51, _RGB(255, 255, 255)
x& = GetCircle&(100, 100, 50)
Locate 2, 24:: Color _RGB(255, 255, 255)
Print " Copied this area of the screen "
_Delay 2
Cls
Do
PutCircle Rnd * _Width, Rnd * _Height, x&, Rnd * 255
_Limit 30
Loop Until InKey$ <> ""
Function GetCircle& (cx, cy, radius)
If circleimg& <> 0 Then _FreeImage circleimg&
circleimg& = _NewImage(radius * 2, radius * 2) '
_Dest circleimg&
For x = 0 To radius * 2
For y = 0 To radius * 2
If Sqr((x - radius) ^ 2 + (y - radius) ^ 2) <= radius Then
clr& = Point(cx - radius + x, cy - radius + y)
PSet (x, y), clr&
End If
Next
Next
GetCircle& = _CopyImage(circleimg&)
_FreeImage circleimg&
_Dest 0
End Function
Sub PutCircle (cx, cy, img&, alpha)
If img& = 0 Then Exit Sub
radius = _Width(img&) / 2
_Source img&
_Dest 0
For x = 0 To radius * 2
For y = 0 To radius * 2
If Sqr((x - radius) ^ 2 + (y - radius) ^ 2) <= radius Then
clr~& = Point(x, y)
r = _Red32(clr~&)
g = _Green32(clr~&)
b = _Blue32(clr~&)
PSet (cx + x, cy + y), _RGBA(r, g, b, alpha)
End If
Next
Next
_Source 0
End Sub