below a example showing, how a once drawn image, can be used as overlay.
The base of the trick is *transparency* of the image, used as overlay.
The example also shows, how to create an *endless* image of a Brick:
- endless refers to: can be endlessly put along itself, creating a whole Wall.
TransparentOverlay.bas:
Code: Select all
' TranparentOverlay.bas -- 2017-05-14, by MrSwiss
'
' compile with: -s GUI
'
'#Include "GFX_MATH.bi" ' see: https://freebasic.net/forum/viewtopic.php?f=7&t=25635
Const As Single Pi = 4f * Atn(1f)
Const As Single d2r = Pi / 180f
#Define RAD(d) ( d * d2r )
#Define LRange(l, h) ( CLng(Rnd() * (h - l) + l) )
' above is taken out of: GFX_MATH.bi
Declare Sub BuildBrickImage(ByVal As Any Ptr, ByVal As ULong=0)
Declare Sub BuildSmileyImage(ByVal As Any Ptr, ByVal As ULong, ByVal As ULong=0, ByVal As ULong )
' ===== MAIN =====
Randomize(Timer, 3)
ScreenRes(651, 481, 32)
Dim As ULong x, y, w = 321, h = w, ctrx = 160, r = 150, clr = &hff5f5f5f
Dim As Any Ptr img = ImageCreate(50, 30, &hffbf3f00) ' orangey bg (brick color)
Dim As Any Ptr smiley = ImageCreate(w, h) ' transparent bg (default)
Dim As Boolean sf = TRUE ' smiley flag (aka, switch: TRUE = ON, FALSE = OFF)
BuildBrickImage(img, clr) ' clr = mortar color fg (line color)
BuildSmileyImage(smiley, ctrx,, r)
Do
ScreenLock ' prevent flickering
For v As UInteger = 0 To 480-30 Step 30 ' vertical stepping
For h As UInteger = 0 To 650-50 Step 50 ' horizontal stepping
Put (h, v), img, PSet ' bricks to screen (build wall)
Next 'h
Next
x = LRange(10, 320) : y = LRange(10, 150) ' randomize smiley's positioning
If sf Then Put (x, y), smiley, Trans ' smiley ON/OFF (transparent overlay)
ScreenUnLock ' prevent flickering end
Sleep 333, 1 : sf = Not sf ' give user time to see | flip the switch
Loop Until Len(InKey()) ' quit on user action, keyboard/mouse
' clean up ...
ImageDestroy(img) : img = 0 ' clear memory, re-set pointer
ImageDestroy(smiley) : smiley = 0 ' as above
' ===== END-MAIN =====
' imlement declared sub's ...
Sub BuildBrickImage(ByVal i As Any Ptr, ByVal clr As ULong=0)
' top half
Line i, ( 0, 0)-(49, 14), clr, B ' whole top half block dark grey
Line i, ( 0, 1)-(49, 1), clr ' horiz. top line (dbl. thick)
' center part
Line i, ( 0, 15)-(49, 15), clr ' horiz. center line (dbl. thick)
' bottom half
Line i, (24, 15)-(24, 29), clr ' vertical line center
Line i, (25, 15)-(25, 29), clr ' vertical line center (dbl. thick)
End Sub
Sub BuildSmileyImage(ByVal i As Any Ptr, ByVal xc As ULong, _
ByVal yc As ULong=0, ByVal rd As ULong )
If yc = 0 Then yc = xc ' default: assume a square
Circle i, (xc, yc), rd, &hffffdf00,,,, F ' smiley face yellow filled
Circle i, (xc, yc), rd, &hff000000 ' smiley face border black
Circle i, (xc-50, yc-30), rd \ 6, &hff000000 ' left eye border black
Circle i, (xc-50, yc-30), rd \ 6 - 1, &hff00ff,,,, F ' left eye fill transparent
Circle i, (xc+50, yc-30), rd \ 6, &hff000000 ' right eye border black
Circle i, (xc+50, yc-30), rd \ 6 - 1, &hff00ff,,,, F ' right eye fill transparent
Circle i, (xc, yc+25), rd \ 2, &hff000000, RAD(200), RAD(340) ' mouth lower shape
Circle i, (xc, yc-80), rd, &hff000000, RAD(242), RAD(298) ' mouth upper shape
Paint i, (xc, yc+90), &hff00ff, &hff000000 ' mouth fill transparent
End Sub
' ------ EOF -----