A gift of flowers

Share your advanced PureBasic knowledge/code with the community.
AZJIO
Addict
Addict
Posts: 2141
Joined: Sun May 14, 2017 1:48 am

A gift of flowers

Post by AZJIO »

A gift of flowers
Download: yandex
Discussion

Code: Select all

EnableExplicit

UsePNGImageDecoder()

Define hGUI, w, h, Counter, id_img, i

;- DataSection
DataSection
	p1:
	IncludeBinary "images\1.png"
	p2:
	IncludeBinary "images\2.png"
	p3:
	IncludeBinary "images\3.png"
	p4:
	IncludeBinary "images\4.png"
	p5:
	IncludeBinary "images\5.png"
	p6:
	IncludeBinary "images\6.png"
	p7:
	IncludeBinary "images\7.png"
	p8:
	IncludeBinary "images\8.png"
	p9:
	IncludeBinary "images\9.png"
	p10:
	IncludeBinary "images\10.png"
	p11:
	IncludeBinary "images\11.png"
	p12:
	IncludeBinary "images\12.png"
	p13:
	IncludeBinary "images\13.png"
	p14:
	IncludeBinary "images\14.png"
	p15:
	IncludeBinary "images\15.png"
	p16:
	IncludeBinary "images\16.png"
	p17:
	IncludeBinary "images\17.png"
	p18:
	IncludeBinary "images\18.png"
	p19:
	IncludeBinary "images\19.png"
	p20:
	IncludeBinary "images\20.png"
	p21:
	IncludeBinary "images\21.png"
	p22:
	IncludeBinary "images\22.png"
	p23:
	IncludeBinary "images\23.png"
	p24:
	IncludeBinary "images\24.png"
	p25:
	IncludeBinary "images\25.png"
	p26:
	IncludeBinary "images\26.png"
	p27:
	IncludeBinary "images\27.png"
	p28:
	IncludeBinary "images\28.png"
	p29:
	IncludeBinary "images\29.png"
	p30:
	IncludeBinary "images\30.png"
	p31:
	IncludeBinary "images\31.png"
	p32:
	IncludeBinary "images\32.png"
	p33:
	IncludeBinary "images\33.png"
	p34:
	IncludeBinary "images\34.png"
	p35:
	IncludeBinary "images\35.png"
	p36:
	IncludeBinary "images\36.png"
	p37:
	IncludeBinary "images\37.png"
	p38:
	IncludeBinary "images\38.png"
	p39:
	IncludeBinary "images\39.png"
	p40:
	IncludeBinary "images\40.png"
	p41:
	IncludeBinary "images\41.png"
EndDataSection



CatchImage(1, ?p1)
CatchImage(2, ?p2)
CatchImage(3, ?p3)
CatchImage(4, ?p4)
CatchImage(5, ?p5)
CatchImage(6, ?p6)
CatchImage(7, ?p7)
CatchImage(8, ?p8)
CatchImage(9, ?p9)
CatchImage(10, ?p10)
CatchImage(11, ?p11)
CatchImage(12, ?p12)
CatchImage(13, ?p13)
CatchImage(14, ?p14)
CatchImage(15, ?p15)
CatchImage(16, ?p16)
CatchImage(17, ?p17)
CatchImage(18, ?p18)
CatchImage(19, ?p19)
CatchImage(20, ?p20)
CatchImage(21, ?p21)
CatchImage(22, ?p22)
CatchImage(23, ?p23)
CatchImage(24, ?p24)
CatchImage(25, ?p25)
CatchImage(26, ?p26)
CatchImage(27, ?p27)
CatchImage(28, ?p28)
CatchImage(29, ?p29)
CatchImage(30, ?p30)
CatchImage(31, ?p31)
CatchImage(32, ?p32)
CatchImage(33, ?p33)
CatchImage(34, ?p34)
CatchImage(35, ?p35)
CatchImage(36, ?p36)
CatchImage(37, ?p37)
CatchImage(38, ?p38)
CatchImage(39, ?p39)
CatchImage(40, ?p40)
CatchImage(41, ?p41)

Declare AddLayeredWindow(x, y, Image)

ExamineDesktops()
w = DesktopWidth(0)
h = DesktopHeight(0)

hGUI = OpenWindow(0, 0, 0, 10, 10, "", #PB_Window_Invisible) ; Невидимое окно для таймера.
AddWindowTimer(0, 0, 100)

Repeat
	Select WaitWindowEvent()
		Case #PB_Event_Timer
			If EventTimer() = 0
				Counter + 1
				If Counter <= 150 ; Число картинок
					id_img = Random(41, 1)
					AddLayeredWindow(Random(w - ImageWidth(id_img), 0), Random(h - ImageHeight(id_img), 0), id_img)
				Else
					RemoveWindowTimer(0, 0)
				EndIf
			EndIf
		Case #PB_Event_LeftClick, #PB_Event_RightClick
			Break
		Case #PB_Event_CloseWindow
			Break
	EndSelect
ForEver

End


Procedure AddLayeredWindow(x, y, Image)
	Protected WinNum, hGUI, hDC, pt2.Point, sz.Point, bf.BlendFunction
	Static ID = 0
	ID + 1
	WinNum = OpenWindow(ID, x, y, ImageWidth(Image), ImageHeight(Image), "", #PB_Window_Invisible | #PB_Window_BorderLess)

	hGUI = WindowID(ID)

	SetWindowLongPtr_(hGUI, #GWL_EXSTYLE,
	                  GetWindowLongPtr_(hGUI, #GWL_EXSTYLE) | #WS_EX_LAYERED | #WS_EX_TOOLWINDOW)
	StickyWindow(ID, #True)
	sz\x = ImageWidth(Image)
	sz\y = ImageHeight(Image)
	bf\BlendOp = #AC_SRC_OVER
	bf\BlendFlags = 0
	bf\SourceConstantAlpha = 255 ; общая прозрачность окна
	bf\AlphaFormat = #AC_SRC_ALPHA ; используем альфа-канал
	hDC = StartDrawing(ImageOutput(Image))
	UpdateLayeredWindow_(hGUI, 0, 0, @sz, hDC, @pt2, 0, @bf, #ULW_ALPHA)
	StopDrawing()

	HideWindow(ID, #False)
	ProcedureReturn ID
EndProcedure
miso
Enthusiast
Enthusiast
Posts: 410
Joined: Sat Oct 21, 2023 4:06 pm
Location: Hungary

Re: A gift of flowers

Post by miso »

It's kind ;)
Quin
Addict
Addict
Posts: 1124
Joined: Thu Mar 31, 2022 7:03 pm
Location: Colorado, United States
Contact:

Re: A gift of flowers

Post by Quin »

Very nice!
But...why not use a macro to define/catch all your images, rather than having to type all that 41 times? :twisted:
AZJIO
Addict
Addict
Posts: 2141
Joined: Sun May 14, 2017 1:48 am

Re: A gift of flowers

Post by AZJIO »

Quin wrote: Fri May 02, 2025 10:48 am rather than having to type all that 41 times?
A video that shows that I did not enter it 41 times.
User avatar
minimy
Enthusiast
Enthusiast
Posts: 552
Joined: Mon Jul 08, 2013 8:43 pm
Location: off world

Re: A gift of flowers

Post by minimy »

Fantastic, thanks for share!!
If translation=Error: reply="Sorry, Im Spanish": Endif
jack
Addict
Addict
Posts: 1358
Joined: Fri Apr 25, 2003 11:10 pm

Re: A gift of flowers

Post by jack »

@AZJIO
Quin is blind, don't think that a video would help
Quin
Addict
Addict
Posts: 1124
Joined: Thu Mar 31, 2022 7:03 pm
Location: Colorado, United States
Contact:

Re: A gift of flowers

Post by Quin »

jack wrote: Sun May 04, 2025 2:02 am @AZJIO
Quin is blind, don't think that a video would help
A video not in my native language iether :D
I just chose to believe that AZJIO is okay with torturing himself :mrgreen:
AZJIO
Addict
Addict
Posts: 2141
Joined: Sun May 14, 2017 1:48 am

Re: A gift of flowers

Post by AZJIO »

jack wrote: Sun May 04, 2025 2:02 am @AZJIO
Quin is blind, don't think that a video would help
1. I think there are people nearby who can tell @Quin what's going on on the screen.
2. In fact, it's not just @Quin who thinks this way. If you open the discussion link on another forum, you will see the same question. So I killed two birds with one stone (saying/metaphor/proverb/idiom).
User avatar
Jacobus
Enthusiast
Enthusiast
Posts: 139
Joined: Wed Nov 16, 2005 7:51 pm
Location: France
Contact:

Re: A gift of flowers

Post by Jacobus »

Hi AZJIO
This is a very nice gift. A nice touch, a little sweetness in this brutal world.
PureBasicien tu es, PureBasicien tu resteras.
Quin
Addict
Addict
Posts: 1124
Joined: Thu Mar 31, 2022 7:03 pm
Location: Colorado, United States
Contact:

Re: A gift of flowers

Post by Quin »

AZJIO wrote: Sun May 04, 2025 5:42 am 1. I think there are people nearby who can tell @Quin what's going on on the screen.
I don't have a screen attached to my PC and my family and me don't get along, sohardly.
Please don't assume disabled people always have helpers and assistants around them. We very often don't and just have to fend for ourselves the best way we know how. It's exhausting.
AZJIO
Addict
Addict
Posts: 2141
Joined: Sun May 14, 2017 1:48 am

Re: A gift of flowers

Post by AZJIO »

Added the Esc key to exit
Added: clicking past a flower is also a way out (loss of focus)
DataSection is in a separate file, and CatchImage runs in a loop. Thank RASHAD, and before him Demivec.
Compressed images (newJS) (by the PNGGauntlet program).
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5494
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

Re: A gift of flowers

Post by Kwai chang caine »

Really nice 8)
All that's missing is the smell and it will be perfect :mrgreen:
Thanks for this kind sharing
ImageThe happiness is a road...
Not a destination
Post Reply