Page 1 of 1

Alpha Blend 32 bit Images w PB

Posted: Tue Oct 12, 2021 2:50 am
by RASHAD
Hi

Code: Select all

CreateImage(0,600,600,32)
StartDrawing(ImageOutput(0))
For i = 0 To 100
  DrawingMode(#PB_2DDrawing_AllChannels )
  alpha = Random(255,0)
  Circle(Random(600,10),Random(600,10),Random(50,10),RGBA(255,0,0,alpha))
Next
StopDrawing()

CreateImage(1,600,600,32)
StartDrawing(ImageOutput(1))
For i = 0 To 100
  DrawingMode(#PB_2DDrawing_AllChannels )
  alpha = Random(255,0)
  Circle(Random(600,10),Random(600,10),Random(50,10),RGBA(0,255,0,alpha))
Next
StopDrawing()

CreateImage(2,600,600,32)
StartDrawing(ImageOutput(2))
For i = 0 To 100
  DrawingMode(#PB_2DDrawing_AllChannels )
  alpha = Random(255,0)
  Circle(Random(600,10),Random(600,10),Random(50,10),RGBA(0,0,255,alpha))
Next
StopDrawing()

OpenWindow(0, 0, 0, 600, 600, "2D Drawing Test",#PB_Window_SystemMenu|#PB_Window_ScreenCentered)
If CreateImage(100, 1200, 1200 ,32)
  If StartDrawing(ImageOutput(100))
    DrawingMode(#PB_2DDrawing_AllChannels )
    DrawImage(ImageID(0),0,0,600,600)
    DrawImage(ImageID(1),600,0,600,600)
    For x = 0 To 599
      For y = 0 To 599
        c1 = Point(x,y)
        c2 = Point(x+600,y)
        color = AlphaBlend(c1,c2)
        Plot(x,y+600,color)            
      Next
    Next
    GrabDrawingImage(3,0,600,600,600)
    StopDrawing()
  EndIf
EndIf
If CreateImage(100, 1200, 1200 ,32)
  If StartDrawing(ImageOutput(100))
    DrawingMode(#PB_2DDrawing_AllChannels )
    DrawImage(ImageID(3),0,0,600,600)
    DrawImage(ImageID(2),600,0,600,600)
    For x = 0 To 599
      For y = 0 To 599
        c1 = Point(x,y)
        c2 = Point(x+600,y)
        color = AlphaBlend(c1,c2)
        Plot(x,y+600,color)               
      Next
    Next
    GrabDrawingImage(4,0,600,600,600)
    StopDrawing()
  EndIf
EndIf

ImageGadget(0, 0, 0, 600,600, ImageID(4))

Repeat
  Event = WaitWindowEvent() 
Until Event = #PB_Event_CloseWindow
End

Edit : Fixed

Re: Alpha Blend 32 bit Images w PB

Posted: Tue Oct 12, 2021 7:48 am
by STARGĂ…TE
I see messy distributes circles.
What is the purpose of this code?

Especially, why you calculate c11 and c22? They are the same as c1 and c2, respectively.

Code: Select all

c1 = $12345678
c11 = Alpha(c1) << 24 + Blue(c1) << 16 + Green(c1) << 8 + Red(c1)
Debug Hex(c1)
Debug Hex(c11)

Re: Alpha Blend 32 bit Images w PB

Posted: Tue Oct 12, 2021 10:37 am
by RASHAD
My bad
I always think that Point() is equal to GetPixel_() which return RGB() not RGBA()

Re: Alpha Blend 32 bit Images w PB

Posted: Tue Oct 12, 2021 10:39 am
by Seymour Clufley
So is those code worth looking at or not?