
(Sometimes the image generation takes a little while. So have a little patience.)
Code: Select all
EnableExplicit
Enumeration
#Window
#lblPrompt
#lblWait
#txtPrompt
#cmdExecutePrompt
#ImageGadget
EndEnumeration
Procedure InProgress(Flag)
DisableGadget(#txtPrompt, Flag)
DisableGadget(#cmdExecutePrompt, Flag)
HideGadget(#ImageGadget, Flag)
HideGadget(#lblWait, Bool(Flag=#False))
EndProcedure
Procedure cmdExecutePromptEvent()
If GetGadgetText(#txtPrompt) = "" : ProcedureReturn : EndIf
InProgress(#True)
LoadImage(0, "https://image.pollinations.ai/prompt/" + URLEncoder(GetGadgetText(#txtPrompt))) ; + "&seed=" + ElapsedMilliseconds()
EndProcedure
Procedure Loaded(Type, Filename$, ObjectId)
SetGadgetState(#ImageGadget, ImageID(ObjectId))
InProgress(#False)
EndProcedure
Procedure LoadingError(Type, Filename$, ObjectId)
Debug Filename$ + ": loading error"
DisableGadget(#cmdExecutePrompt, #False)
InProgress(#False)
EndProcedure
OpenWindow(#Window, #PB_Ignore, #PB_Ignore, 532, 444, "pollinations.ai Image generator", #PB_Window_ScreenCentered)
TextGadget(#lblPrompt, 10, 10, 50, 30, "Prompt:", #PB_Text_VerticalCenter)
StringGadget(#txtPrompt, 60, 10, 400, 30, "PureBasic Programmer")
ButtonGadget(#cmdExecutePrompt, 470, 10, 55, 30, "Execute")
TextGadget(#lblWait, 0, 0, WindowWidth(#Window), WindowHeight(#Window), "Please wait...", #PB_Text_VerticalCenter | #PB_Text_Center)
ImageGadget(#ImageGadget, 10, 50, 512, 384, 0)
InProgress(#False)
BindGadgetEvent(#cmdExecutePrompt, @cmdExecutePromptEvent())
BindEvent(#PB_Event_Loading, @Loaded())
BindEvent(#PB_Event_LoadingError, @LoadingError())
