Alpha Blend 32 bit Images w PB

Share your advanced PureBasic knowledge/code with the community.
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4622
Joined: Sun Apr 12, 2009 6:27 am

Alpha Blend 32 bit Images w PB

Post 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
Last edited by RASHAD on Tue Oct 12, 2021 11:06 am, edited 2 times in total.
Egypt my love
User avatar
STARGÅTE
Addict
Addict
Posts: 2063
Joined: Thu Jan 10, 2008 1:30 pm
Location: Germany, Glienicke
Contact:

Re: Alpha Blend 32 bit Images w PB

Post 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)
PB 6.01 ― Win 10, 21H2 ― Ryzen 9 3900X, 32 GB ― NVIDIA GeForce RTX 3080 ― Vivaldi 6.0 ― www.unionbytes.de
Lizard - Script language for symbolic calculations and moreTypeface - Sprite-based font include/module
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4622
Joined: Sun Apr 12, 2009 6:27 am

Re: Alpha Blend 32 bit Images w PB

Post by RASHAD »

My bad
I always think that Point() is equal to GetPixel_() which return RGB() not RGBA()
Egypt my love
Seymour Clufley
Addict
Addict
Posts: 1233
Joined: Wed Feb 28, 2007 9:13 am
Location: London

Re: Alpha Blend 32 bit Images w PB

Post by Seymour Clufley »

So is those code worth looking at or not?
JACK WEBB: "Coding in C is like sculpting a statue using only sandpaper. You can do it, but the result wouldn't be any better. So why bother? Just use the right tools and get the job done."
Post Reply