Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
_CLEARCOLOR evety color EXCEPT ...?
#5
Hi
Quote:This would need to be fast, like for animation.
can you be more specific with an example?
Maybe the path is NOT _clearcolor

in the meanwhile I had 2 study with _Clearcolor and _SetAlpha

I took the third example from the wiki and going on I develop this first snippet...
BUT I brought with me a conceptual error that is in that example....
as result of running the code we must get that the foreground parts of the image copied over the screen always overwrite the background image of the screen, while increasing the alpha channel from 0 to 255, we must see the presence of the background of the image copied over the screen covering the background image of the screen. This doesn't happen because in the code it has been used _Setalpha  without a specific color OR range of colors so all the colors of the image copied over the screen (including its background color that before by _Clearcolor made transparent) change their degree of transparency. So all the image changes from transparent to opaque with no blending between image of the screen and the background of image pasted over it.
I must say that wiki says clearly that _Setalpha changes the alpha channel of all the colors of the image, also those that have been treated with _clearcolor before .

here the code
Code: (Select All)

Dim Shared As Long mainScreen, Image1, NewImage1, a
mainScreen = _NewImage(1200, 800, 32) ' Main Screen (viewable)
Screen mainScreen
_Title "Clearcolor study 1"
_ScreenMove 1, 1
Image1 = _NewImage(1200, 800, 32)

init


a = 0
d = 5
Do
    _Limit 10 'regulate speed of fades

    _PutImage , Image1
    a = a + d
    If a >= 255 Or a <= 0 Then d = -d: a = a + d: Sleep 2 'reverse fade
    _SetAlpha a, , NewImage1 'sets alpha level of all colors to fade image page in/out
    _PutImage (0, 342), NewImage1
    Locate 1, 1: Print "Alpha: "; a: Locate 1, 12: Print " Press a key to pause, r to restart, a to change alpha step, spacebar to quit    "
    _Display
    Kp$ = InKey$
    Select Case Kp$
        Case " ":
            System
        Case "r", "R":
            init
            a = 0
        Case "a", "A":
            Select Case d
                Case 1
                    d = 5
                Case 5
                    d = 10
                Case 10
                    d = 15
                Case 15
                    d = 1
            End Select
        Case Else
            If Kp$ <> "" Then Sleep
    End Select
Loop
End

Sub init
    If Image1& < -1 Then 'check loaded image handle value before using!
        _Dest Image1&
        Cls , _RGB32(Rnd * 255, Rnd * 255, Rnd * 255)
        For I = 1 To 10
            x = Rnd * 800
            y = Rnd * 400
            k = _RGB32(Rnd * 255, Rnd * 255, Rnd * 255)
            Circle (x, y), Rnd * 100, k
            Paint Step(0, 0), _RGB32(Rnd * 255, Rnd * 255, Rnd * 255), k
        Next I
        _Source Image1
        clr~& = Point(0, 0) 'get background color from image source
        _ClearColor clr~&, Image1 'clear background color of image
        NewImage1 = _NewImage(_Width(Image1), _Height(Image1), 32) 'new image page
        _PutImage , Image1, NewImage1 'put image without background color on new page
        _FreeImage Image1 'free loaded image from memory
    End If
    _Dest mainScreen:
    Cls , _RGB32(0, 0, 0, 255) 'the background of mainscreen is opaque black
    For I = 1 To 10
        Line (Rnd * 1200, Rnd * 800)-(Rnd * 1200, Rnd * 800), _RGB32(Rnd * 255, Rnd * 255, Rnd * 255), BF
    Next I
    Image1 = _CopyImage(mainScreen)

End Sub
it remains a good example of how to exclude a color of an image to avoid to be copied to another one.

So going on in the wiki I found the right information in page _SetAlpha and I keep informations from the example about the specific :
how to give the range of colors to treat with _setalpha without affecting all the colors of the image

here the code in which finally the background of the image copied on the screen goes ranging from transparent to opaque
Code: (Select All)

Dim Shared As Long mainScreen, Image1, NewImage1, a, topcolor
mainScreen = _NewImage(1200, 800, 32) ' Main Screen (viewable)
Screen mainScreen
_Title "Clearcolor study 2"
_ScreenMove 1, 1
Image1 = _NewImage(1200, 800, 32)

init


a = 0
d = 5
Do
    _Limit 10 'regulate speed of fades

    _PutImage , Image1
    a = a + d
    If a >= 255 Or a <= 0 Then d = -d: a = a + d: Sleep 2 'reverse fade
    _SetAlpha a, 0 To topcolor, NewImage1 'sets alpha level of all colors to fade image page in/out
    _PutImage (0, 342), NewImage1
    Locate 1, 1: Print "Alpha: "; a: Locate 1, 12: Print " Press a key to pause, r to restart, a to change alpha step, spacebar to quit    "
    _Display
    Kp$ = InKey$
    Select Case Kp$
        Case " ":
            System
        Case "r", "R":
            init
            a = 0
        Case "a", "A":
            Select Case d
                Case 1
                    d = 5
                Case 5
                    d = 10
                Case 10
                    d = 15
                Case 15
                    d = 1
            End Select
        Case Else
            If Kp$ <> "" Then Sleep
    End Select
Loop
End

Sub init
    If Image1 < -1 Then 'check loaded image handle value before using!
        _Dest Image1
        Cls , _RGB32(Rnd * 255, Rnd * 255, Rnd * 255)
        For I = 1 To 10
            x = Rnd * 800
            y = Rnd * 400
            k = _RGB32(Rnd * 255, Rnd * 255, Rnd * 255)
            Circle (x, y), Rnd * 100, k
            Paint Step(0, 0), _RGB32(Rnd * 255, Rnd * 255, Rnd * 255), k
        Next I
        _Source Image1
        clr~& = Point(0, 0) 'get background color from image source
        _ClearColor clr~&, Image1 'clear background color of image
        topcolor = clr~& - _RGBA(1, 1, 1, 0)
        NewImage1 = _NewImage(_Width(Image1), _Height(Image1), 32) 'new image page
        _PutImage , Image1, NewImage1 'put image without background color on new page
        _FreeImage Image1 'free loaded image from memory
    End If
    _Dest mainScreen:
    Cls , _RGB32(0, 0, 0, 255) 'the background of mainscreen is opaque black
    For I = 1 To 10
        Line (Rnd * 1200, Rnd * 800)-(Rnd * 1200, Rnd * 800), _RGB32(Rnd * 255, Rnd * 255, Rnd * 255), BF
    Next I
    Image1 = _CopyImage(mainScreen)

End Sub

I have found no day for _Clearcolor and _Setalpha keywords also if it seems a recurrent issue dealing with them

making mask or use _clearcolor
setting _cleacolor
printing to image handle
[/url][url=https://qb64phoenix.com/forum/showthread.php?tid=3606&highlight=_clearcolor]setalpha and clearcolor

I think that it is useful to have more example about how to specify the range of colors to treat with _Setalpha.
the range from Color1& TO Color2& must be continue? 
(i.e. from _RGB32(255,0,0) TO _RGB32(0,255,0) means that all colors with values between full Red and full Green are treated by _Setalpha?)
for different colors must I  use an array with handles of colors and apply _setalpha on each one at a time? (i.e. simulating the action of Palette Using and _SetPalette of legacy graphic screens?)
in the example taken from the wiki why topcolor = _RGBA(0,0,0,0)- _RGBA(1,1,1,0) and not only _RGBA(1,1,1,0) that is the next one after black transparent? 
Is it possible to claim a day for _Clearcolor and _Setalpha in the keyword of day?
a good day like this _Putimage day
Reply


Messages In This Thread
_CLEARCOLOR evety color EXCEPT ...? - by madscijr - 04-27-2025, 03:21 PM
RE: _CLEARCOLOR evety color EXCEPT ...? - by Petr - 04-27-2025, 08:35 PM
RE: _CLEARCOLOR evety color EXCEPT ...? - by TempodiBasic - 04-27-2025, 10:51 PM



Users browsing this thread: 1 Guest(s)