Apply Setgadgettext()
Apply Setgadgettext()
How do you actually apply a Setgadgettext(xx,"xxxx") command?
I am using one in a program, the Stringgadget is in a window, and it is followed by a large loop. I expected that it would update the String gadget immediately upon the command, but it does it half way through the large loop.
How can I ensure that the String gadget text is updated at the time I want it?
I am using one in a program, the Stringgadget is in a window, and it is followed by a large loop. I expected that it would update the String gadget immediately upon the command, but it does it half way through the large loop.
How can I ensure that the String gadget text is updated at the time I want it?
Re: Apply Setgadgettext()
Here is an example that highlights the problem:
Code: Select all
OpenWindow(0,50,50,1000,900,"Window")
CreateImage(0,800,900)
ImageGadget(0, 0, 0, 800, 900, ImageID(0))
StartDrawing(ImageOutput(0))
Box(0,0,800,900,#Black)
StopDrawing()
ButtonGadget(2,800+30,600,100,50,"Go",#PB_Text_Center)
StringGadget(3,800+30,830,80,25,"IDLE",#PB_Text_Center)
Repeat
Event = WaitWindowEvent()
Select event
Case #PB_Event_Gadget
EventGadget = EventGadget()
Select EventGadget
Case 2
SetGadgetText(3,"BUSY")
For t=1 To 255
StartDrawing(ImageOutput(0))
For y=1 To 899
For x= 1 To 799
Plot(x,y,t)
Next
Next
StopDrawing()
SetGadgetState(0,ImageID(0))
Next
EndSelect
EndSelect
Until Event = #PB_Event_CloseWindow
End [code]Re: Apply Setgadgettext()
The update of the window controls seems to be done in the next (invisible) part of the message loop. Putting long-running computations in this loop is unlikely to be appropriate.
Re: Apply Setgadgettext()
I would suggest a thread to do the computation seperately so that the window is able to process events.
Re: Apply Setgadgettext()
Loops like this are best done in a thread, so your app's main loop can still run and process events / update gadgets.
But in your example above, you have two ways of updating the StringGadget() immediately, without using a thread. See both options below, and either one goes after you set the StringGadget text and before the For/Next loop starts.
Cross-platform:
Windows only:
And here's a threaded version (using "Step 2" to save time for this demo):
But in your example above, you have two ways of updating the StringGadget() immediately, without using a thread. See both options below, and either one goes after you set the StringGadget text and before the For/Next loop starts.
Cross-platform:
Code: Select all
While WindowEvent() : WendCode: Select all
UpdateWindow_(GadgetID(3))Code: Select all
OpenWindow(0,50,50,1000,900,"Window")
CreateImage(0,800,900)
ImageGadget(0, 0, 0, 800, 900, ImageID(0))
StartDrawing(ImageOutput(0))
Box(0,0,800,900,#Black)
StopDrawing()
ButtonGadget(2,800+30,600,100,50,"Go",#PB_Text_Center)
StringGadget(3,800+30,830,80,25,"IDLE",#PB_Text_Center)
Procedure DrawStuff(null)
For t=1 To 255
StartDrawing(ImageOutput(0))
For y=1 To 899 Step 2
For x= 1 To 799 Step 2
Plot(x,y,t)
Next
Next
StopDrawing()
Next
SetGadgetState(0,ImageID(0))
SetGadgetText(3,"IDLE")
EndProcedure
Repeat
Event = WaitWindowEvent()
Select event
Case #PB_Event_Gadget
EventGadget = EventGadget()
Select EventGadget
Case 2
SetGadgetText(3,"BUSY")
CreateThread(@DrawStuff(),0)
EndSelect
EndSelect
Until Event = #PB_Event_CloseWindow
Re: Apply Setgadgettext()
Thanks for that. That works great.BarryG wrote: Thu Dec 29, 2022 1:09 am Loops like this are best done in a thread, so your app's main loop can still run and process events / update gadgets.
But in your example above, you have two ways of updating the StringGadget() immediately, without using a thread. See both options below, and either one goes after you set the StringGadget text and before the For/Next loop starts.
Cross-platform:
Windows only:Code: Select all
While WindowEvent() : Wend
And here's a threaded version (using "Step 2" to save time for this demo):Code: Select all
UpdateWindow_(GadgetID(3))
I tried to add my drawing loop as a thread in my full program, and it has problems with all the arrays and variables. Do they have to be set in a particular way for a Thread? I have not used them before.
Re: Apply Setgadgettext()
You have to enable "Thread safety" in the Compiler Options for your source. Also, any variables from outside the threaded procedure need to be declared before the procedure as Global type, or declared before the procedure but then accessed inside the procedure with the Shared keyword. See the manual for both of these.
Re: Apply Setgadgettext()
You can use Windows Timer as well to check periodically the status
But THREAD is much better as suggested by Mijikai
But THREAD is much better as suggested by Mijikai
Code: Select all
Procedure draw(par)
Repeat
StartDrawing(ImageOutput(0))
For y=1 To 899
For x= 1 To 799
Plot(x,y,t)
Next
Next
StopDrawing()
SetGadgetState(0,ImageID(0))
t + 1
Until t = 255
SetGadgetText(3,"IDLE")
EndProcedure
OpenWindow(0,50,50,1000,900,"Window")
CreateImage(0,800,900)
ImageGadget(0, 0, 0, 800, 900, ImageID(0))
StartDrawing(ImageOutput(0))
Box(0,0,800,900,#Black)
StopDrawing()
ButtonGadget(2,800+30,600,100,50,"Go",#PB_Text_Center)
StringGadget(3,800+30,830,80,25,"IDLE",#PB_Text_Center)
Repeat
Event = WaitWindowEvent()
Select event
Case #PB_Event_Gadget
Select EventGadget()
Case 2
SetGadgetText(3,"BUSY")
If IsThread(thread) = 0
thread = CreateThread(@draw(),30)
EndIf
EndSelect
EndSelect
Until Event = #PB_Event_CloseWindow
End
Egypt my love
Re: Apply Setgadgettext()
Thanks, I have various 2-dimensional arrays, they seem to give problems when I attempted to use a Thread, memory exceptions or something with memory.RASHAD wrote: Thu Dec 29, 2022 1:56 am You can use Windows Timer as well to check periodically the status
But THREAD is much better as suggested by Mijikai
How would windows timer be used, and would it also allow slidergadgets to be changed while the program is busy looping through an image?
Re: Apply Setgadgettext()
Your workable example doesn't show your problem ,sorry
Maybe you need to use Thread Mutex
Using Windows Timer :
Maybe you need to use Thread Mutex
Using Windows Timer :
Code: Select all
OpenWindow(0,50,50,1000,900,"Window")
CreateImage(0,800,900)
ImageGadget(0, 0, 0, 800, 900, ImageID(0))
StartDrawing(ImageOutput(0))
Box(0,0,800,900,#Black)
StopDrawing()
ButtonGadget(2,800+30,600,100,50,"Go",#PB_Text_Center)
StringGadget(3,800+30,830,80,25,"IDLE",#PB_Text_Center)
AddWindowTimer(0,125,100)
Repeat
Event = WaitWindowEvent()
Select event
Case #PB_Event_Timer
If drawflag = 1
For t=1 To 255
StartDrawing(ImageOutput(0))
For y=1 To 899
For x= 1 To 799
Plot(x,y,t)
Next
Next
StopDrawing()
SetGadgetState(0,ImageID(0))
Next
drawflag = 0
SetGadgetText(3,"IDLE")
EndIf
Case #PB_Event_Gadget
Select EventGadget()
Case 2
SetGadgetText(3,"BUSY")
drawflag = 1
EndSelect
EndSelect
Until Event = #PB_Event_CloseWindow
End
Egypt my love
Re: Apply Setgadgettext()
Thanks, yeah, it still locks everything else up. I guess I will have to use Threaded.RASHAD wrote: Thu Dec 29, 2022 1:32 pm Your workable example doesn't show your problem ,sorry
Maybe you need to use Thread Mutex
Using Windows Timer :
The program I wanted to use threaded is in a recent post, Seasonal Snowflakes in the coding questions page.
Re: Apply Setgadgettext()
I have been trying to get this program to run threaded, so the sliders do not become inactive, without success, there are various problems mentioned, at the minute, it is saying that the index array is out of bounds, an array that is defined earlier.
The problems arise when the "Keep On" button is used.
Could someone point me in the right direction of getting it to run threaded?
The problems arise when the "Keep On" button is used.
Could someone point me in the right direction of getting it to run threaded?
Code: Select all
EnableExplicit
#width = 1000 ; Set Viewing Width
#height = 1000 ; Set Viewing Height
#width1 = 5000 ; Set Final Image Width - This can be greater than Viewing Width
#height1 = 5000 ; Set Final Image Height - This can be greater than Viewing Width
#max=100000000
Dim unreceptivetemp.d(#width1/6,#height1/5) ; Setup arrays for the hex 'points'
Dim receptive.d(#width1/6,#height1/5)
Dim unreceptive.d(#width1/6,#height1/5)
Dim receptivetemp.d(#width1/6,#height1/5)
Global colcho=1
Global r.i,ti.d
ti=0
Global r=0
Dim ared.i(360)
Dim agreen.i(360)
Dim ablue.i(360)
DataSection ; Setup Colour Arrays
Red:
Data.i 23,21,20,19,18,17,15,14,13,12,11,11,10,9,8,7,6,6,5,4,4,3,3,2,2,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,2,2,3,3,4,4,5,6,6,7,8,9,10,11,11,12,13,14,15,17,18,19,20,21,23,24,25,27,28,29,31,32,34,35,37,38,40,42,43,45,47,49,50,52,54,56,58,59,61,63,65,67,69,71,73,75,77,79,81,83,85,88,90,92,94,96,98,100,103,105,107,109,111,114,116,118,120,123,125,127,129,131,134,136,138,140,143,145,147,149,151,154,156,158,160,162,164,166,169,171,173,175,177,179,181,183,185,187,189,191,193,195,196,198,200,202,204,205,207,209,211,212,214,216,217,219,220,222,223,225,226,227,229,230,231,233,234,235,236,237,239,240,241,242,243,243,244,245,246,247,248,248,249,250,250,251,251,252,252,253,253,253,254,254,254,254,254,254,254,255,254,254,254,254,254,254,254,253,253,253,252,252,251,251,250,250,249,248,248,247,246,245,244,243,243,242,241,240,239,237,236,235,234,233,231,230,229,227,226,225,223,222,220,219,217,216,214,212,211,209,207,205,204,202,200,198,196,195,193,191,189,187,185,183,181,179,177,175,173,171,169,166,164,162,160,158,156,154,151,149,147,145,143,140,138,136,134,131,129,127,125,123,120,118,116,114,111,109,107,105,103,100,98,96,94,92,90,88,85,83,81,79,77,75,73,71,69,67,65,63,61,59,58,56,54,52,50,49,47,45,43,42,40,38,37,35,34,32,31,29,28,27,25,24
Green:
Data.i 108,106,104,102,101,99,97,96,94,92,90,89,87,85,83,82,80,78,77,75,73,72,70,68,67,65,63,62,60,59,57,55,54,52,51,49,48,46,45,43,42,41,39,38,36,35,34,32,31,30,29,27,26,25,24,23,22,21,20,19,17,17,16,15,14,13,12,11,10,10,9,8,7,7,6,6,5,4,4,3,3,2,2,2,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,2,2,2,3,3,4,4,5,6,6,7,7,8,9,10,10,11,12,13,14,15,16,17,17,19,20,21,22,23,24,25,26,27,29,30,31,32,34,35,36,38,39,41,42,43,45,46,48,49,51,52,54,55,57,59,60,62,63,65,67,68,70,72,73,75,77,78,80,82,83,85,87,89,90,92,94,96,97,99,101,102,104,106,108,109,111,113,115,116,118,120,121,123,125,126,128,130,131,133,135,136,138,139,141,143,144,146,147,149,150,152,153,155,156,157,159,160,162,163,164,166,167,168,169,171,172,173,174,175,176,177,178,179,181,181,182,183,184,185,186,187,188,188,189,190,191,191,192,192,193,194,194,195,195,196,196,196,197,197,197,198,198,198,198,198,198,198,198,199,198,198,198,198,198,198,198,198,197,197,197,196,196,196,195,195,194,194,193,192,192,191,191,190,189,188,188,187,186,185,184,183,182,181,181,179,178,177,176,175,174,173,172,171,169,168,167,166,164,163,162,160,159,157,156,155,153,152,150,149,147,146,144,143,141,139,138,136,135,133,131,130,128,126,125,123,121,120,118,116,115,113,111,109
Blue:
Data.i 124,126,128,131,133,135,137,139,141,143,146,148,150,152,154,156,158,160,162,165,167,169,171,173,175,177,179,181,182,184,186,188,190,192,194,195,197,199,201,202,204,206,207,209,210,212,214,215,217,218,219,221,222,223,225,226,227,228,230,231,232,233,234,235,236,237,238,239,239,240,241,242,242,243,244,244,245,245,246,246,247,247,247,248,248,248,248,248,248,248,249,248,248,248,248,248,248,248,247,247,247,246,246,245,245,244,244,243,242,242,241,240,239,239,238,237,236,235,234,233,232,231,230,228,227,226,225,223,222,221,219,218,217,215,214,212,210,209,207,206,204,202,201,199,197,195,194,192,190,188,186,184,182,181,179,177,175,173,171,169,167,165,162,160,158,156,154,152,150,148,146,143,141,139,137,135,133,131,128,126,124,122,120,117,115,113,111,109,107,105,102,100,98,96,94,92,90,88,86,83,81,79,77,75,73,71,69,67,66,64,62,60,58,56,54,53,51,49,47,46,44,42,41,39,38,36,34,33,31,30,29,27,26,25,23,22,21,20,18,17,16,15,14,13,12,11,10,9,9,8,7,6,6,5,4,4,3,3,2,2,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,2,2,3,3,4,4,5,6,6,7,8,9,9,10,11,12,13,14,15,16,17,18,20,21,22,23,25,26,27,29,30,31,33,34,36,38,39,41,42,44,46,47,49,51,53,54,56,58,60,62,64,66,67,69,71,73,75,77,79,81,83,86,88,90,92,94,96,98,100,102,105,107,109,111,113,115,117,120,122
EndDataSection
Restore Red
For r=1 To 360
Read.i ared(r)
Next
Restore Green
For r=1 To 360
Read.i agreen(r)
Next
Restore Blue
For r=1 To 360
Read.i ablue(r)
Next
#ImgGadget = 0
DataSection ; Setup hexagonal shape to be drawn at each 'pixel' - *This may not be necessary at all, at higher resolutions a square shape on hex grid may be fine, not sure.
Numbers:
Data.i 2,4,6,6,6,4,2
EndDataSection
; set various variables, some may not be necessary at this stage
Global.d g,z
Global.f d
Global.d t,const,background,tbcnst,backgroundold,tbbckr
Global.i j,count,loops,total,numbers,b,save,wi,he,action,re,gr,bl,col,tot
Global.i x,y,h,v,set,y1,x1,a,lineup,x1s,y1s,total,keepon
keepon=0
save=0
total=0
a=4
x=#width1/2:y=#height1/2
Enumeration ; More keys than I actually use, but sure, why not.
#Menu_Escape
#Menu_Space
#Menu_W
#Menu_C
#Menu_E
#Menu_P
#Menu_O
#Menu_A
#Menu_Z
#Menu_X
#Menu_V
#Menu_B
#Menu_N
EndEnumeration
count=1
wi=#width1/2
he=#height1/2
action=0
tot=0
background=0.4 ;set background value - all cells will be set to this initially and boundary cells set to this each iteration
For y1=1 To #height1/5
For x1=1 To #width1/6 ;set background values initial state in this loop
y=y1*5+a
z=3*Mod(y,2)
x=x1*6+4+z
lineup=Bool(z=0)
unreceptivetemp(x1-lineup,y1)=background
count=count+1
Next
Next
receptive(#width1/6/2+1,#height1/5/2)=1 ;set initial central seed
const=0.007
Procedure SDRAW(image.i)
Shared ared(),ablue(),agreen(),receptive(),receptivetemp(),unreceptive(),unreceptivetemp() ;set shared arrays
count=0
;set constant value added ot receptive cells each iteration
;Debug col
StartDrawing(ImageOutput(image))
DrawingMode(#PB_2DDrawing_Default)
;SDRAW(image)
re=aRed(Int(ti)) ;set colours
gr=aGreen(Int(ti))
bl=aBlue(Int(ti))
col=RGB(re,gr,bl)
ti=ti+0.8 ; ti sets the speed of change of colour - Higher = faster, it's a double so decimal numbers are okay.
If ti>360
ti=0
EndIf
Repeat
For y1=2 To #height1/5-2
For x1=2 To #width1/6-2
y=y1*5+a ;make hex grid from square grid
z=3*Mod(y,2)
x=x1*6+4+z
lineup=Bool(z=0)
If x1<=4 Or x1>=#width1/6-4 Or y1<=4 Or y1>=#height1/5-4 ; set boundary cells to background value - Not sure about this, but it seems to work until the Snowflake almost touches the walls
unreceptivetemp(x1,y1)=background
unreceptivetemp(x1-lineup,y1)=background
unreceptivetemp(x1-lineup-1,y1)=background
unreceptivetemp(x1-lineup+1,y1)=background
unreceptivetemp(x1,y1-1)=background
unreceptivetemp(x1,y1+1)=background
unreceptivetemp(x1-1,y1-1)=background
unreceptivetemp(x1-1,y1+1)=background
EndIf
;now carryout Iterations - Stage 1
If receptive(x1-lineup,y1)>=1 Or receptive(x1-1-lineup,y1)>=1 Or receptive(x1,y1-1)>=1 Or receptive(x1-1,y1-1)>=1 Or receptive(x1-1,y1+1)>=1 Or receptive(x1+1-lineup,y1)>=1 Or receptive(x1,y1+1)>=1
unreceptivetemp(x1-lineup,y1)=0
receptivetemp(x1-lineup,y1)=receptive(x1-lineup,y1)+const
Else
receptivetemp(x1-lineup,y1)=0
EndIf
Next
Next
For y1=2 To #height1/5-2
For x1=2 To #width1/6-2
y=y1*5+a ;make hex grid from square grid again for stage 2 and plotting
z=3*Mod(y,2)
x=x1*6+4+z
lineup=Bool(z=0)
;Iterations - Stage 2
unreceptive(x1-lineup,y1)=(1/2)*unreceptivetemp(x1-lineup,y1)+(unreceptivetemp(x1-1-lineup,y1)+unreceptivetemp(x1-1,y1-1)+unreceptivetemp(x1-1,y1+1)+unreceptivetemp(x1,y1-1)+unreceptivetemp(x1+1-lineup,y1)+unreceptivetemp(x1,y1+1))/12
receptive(x1-lineup,y1)=unreceptive(x1-lineup,y1)+receptivetemp(x1-lineup,y1)
If receptive(x1-lineup,y1)>=1
If Point(x,y)=0
Restore numbers
For h=1 To 7
Read numbers
For v=1 To numbers
Plot (x+v-numbers/2,y+h-7/2,col)
Next
Next
; Restore numbers
EndIf
EndIf
Next
Next
CopyArray(unreceptive(),unreceptivetemp())
action=action+1
Until action=10 ; Run it 10 times to save lag due to image generation
action=0
StopDrawing()
tot=tot+1
EndProcedure
Define.i Event, EventGadget, copy, quit, main, image, imagesc ; Setup up windows and images
main = OpenWindow(#PB_Any, 50, 0, #width-23+300, #height, "Drawing",#PB_Window_MinimizeGadget)
image = CreateImage(#PB_Any, #width1,#height1)
ImageGadget(#ImgGadget, 0, 0, #width1, #height1, ImageID(image))
CreateStatusBar(0, WindowID(main))
imagesc = CreateImage(#PB_Any, #width-StatusBarHeight(0),#height-StatusBarHeight(0))
ImageGadget(#ImgGadget, 0, 0, #width-StatusBarHeight(0), #height-StatusBarHeight(0), ImageID(imagesc))
TrackBarGadget(10,#width+30,200,200,30,0,9999)
SetGadgetState(10,Background*9999)
tbbckr=GetGadgetState(10)/9999
TrackBarGadget(12,#width+30,400,200,30,0,9999)
SetGadgetState(12,const*9999)
tbcnst=GetGadgetState(12)/9999
;StringGadget(20,#width+30,280,200,25,StrD(tbbckr))
ButtonGadget(25,#width+30,600,100,50,"Go",#PB_Text_Center)
ButtonGadget(26,#width+30,660,100,50,"Keep On",#PB_Text_Center)
ButtonGadget(27,#width+30,720,100,50,"Stop",#PB_Text_Center)
StringGadget(21,#width+30,230,200,25,StrD(tbbckr))
StringGadget(22,#width+30,430,200,25,StrD(tbcnst))
TextGadget(24,#width+30,930,200,25,"IDLE",#PB_Text_Center)
TextGadget(11,#width+30,170,200,20,"Background: "+StrD(tbbckr),#PB_Text_Center)
TextGadget(13,#width+30,370,200,20,"Const: "+StrD(tbcnst),#PB_Text_Center)
AddKeyboardShortcut(main, #PB_Shortcut_Escape, #Menu_Escape) ; more than I need but I leave them
AddKeyboardShortcut(main, #PB_Shortcut_Space, #Menu_Space)
AddKeyboardShortcut(main, #PB_Shortcut_W, #Menu_W)
AddKeyboardShortcut(main, #PB_Shortcut_C, #Menu_C)
AddKeyboardShortcut(main, #PB_Shortcut_E, #Menu_E)
AddKeyboardShortcut(main, #PB_Shortcut_P, #Menu_P)
AddKeyboardShortcut(main, #PB_Shortcut_O, #Menu_O)
AddKeyboardShortcut(main, #PB_Shortcut_A, #Menu_A)
AddKeyboardShortcut(main, #PB_Shortcut_Z, #Menu_Z)
AddKeyboardShortcut(main, #PB_Shortcut_X, #Menu_X)
AddKeyboardShortcut(main, #PB_Shortcut_V, #Menu_V)
AddKeyboardShortcut(main, #PB_Shortcut_B, #Menu_B)
AddKeyboardShortcut(main, #PB_Shortcut_N, #Menu_N)
UseJPEGImageEncoder()
AddWindowTimer(main, 1, 100)
;CreateStatusBar(0, WindowID(main))
AddStatusBarField(130) ; too many here, but I use them elsewhere
AddStatusBarField(130)
AddStatusBarField(130)
AddStatusBarField(130)
AddStatusBarField(130)
AddStatusBarField(130)
AddStatusBarField(130)
Repeat ; Start main loop
Event = WaitWindowEvent()
Select Event
Case #PB_Event_Timer
Select EventTimer()
Case 1
SetGadgetText(24,"BUSY")
If keepon=1
;StartDrawing(ImageOutput(image))
; DrawingMode(#PB_2DDrawing_Default)
;SDRAW(image)
CreateThread(@SDRAW(),image)
; StopDrawing()
CopyImage(image, copy)
ResizeImage(copy, #width-StatusBarHeight(0), #height-StatusBarHeight(0))
If StartDrawing(ImageOutput(imagesc))
DrawImage(ImageID(copy), 0, 0)
StopDrawing()
StatusBarText(0, 0, "Bckgnd= "+StrD(background), #PB_StatusBar_Center)
StatusBarText(0, 1, "tot= "+Str(tot), #PB_StatusBar_Center)
StatusBarText(0, 2, "count= "+Str(count), #PB_StatusBar_Center)
StatusBarText(0, 3, "total= "+Str(total), #PB_StatusBar_Center)
StatusBarText(0, 4, "ti= "+Str(ti), #PB_StatusBar_Center)
StatusBarText(0, 5, "const="+StrD(const), #PB_StatusBar_Center)
;StatusBarText(0, 6, Str(count), #PB_StatusBar_Center)
;tick=tick+1
SetGadgetState(#ImgGadget, ImageID(imagesc))
; Delay(2000)
EndIf
total=total+1
If Mod(total,40)=0
SaveImage(image,"Randraw - "+FormatDate("%yyyy%mm%dd_%hh%ii%ss", Date())+Str(Random(9999,1))+".jpg", #PB_ImagePlugin_JPEG,99)
StatusBarText(0, 0, "Saved Image " + Str(save), #PB_StatusBar_Right)
EndIf
EndIf
SetGadgetText(24,"IDLE")
EndSelect
Case #PB_Event_Menu
Select EventMenu()
Case #Menu_C
For y1=2 To #height1/5-2
For x1=2 To #width1/6-2
y=y1*5+a ;make hex grid from square grid
z=3*Mod(y,2)
x=x1*6+4+z
lineup=Bool(z=0)
If unreceptivetemp(x1-lineup,y1)=background ; set boundary cells to background value - Not sure about this, but it seems to work until the Snowflake almost touches the walls
background=0.9
unreceptivetemp(x1-lineup,y1)=background
EndIf
Next
Next
Case #menu_Z
For y1=2 To #height1/5-2
For x1=2 To #width1/6-2
y=y1*5+a ;make hex grid from square grid
z=3*Mod(y,2)
x=x1*6+4+z
lineup=Bool(z=0)
If unreceptivetemp(x1-lineup,y1)=background ; set boundary cells to background value - Not sure about this, but it seems to work until the Snowflake almost touches the walls
background=0.1
unreceptivetemp(x1-lineup,y1)=background
EndIf
Next
Next
Case #Menu_X
For y1=2 To #height1/5-2
For x1=2 To #width1/6-2
y=y1*5+a ;make hex grid from square grid
z=3*Mod(y,2)
x=x1*6+4+z
lineup=Bool(z=0)
If unreceptivetemp(x1-lineup,y1)=background ; set boundary cells to background value - Not sure about this, but it seems to work until the Snowflake almost touches the walls
background=0.4
unreceptivetemp(x1-lineup,y1)=background
EndIf
Next
Next
Case #Menu_V
const=0.1
Case #Menu_B
const=0.01
Case #Menu_N
const=0.001
Case #Menu_O
; c=0
;blackon=600000
Case #Menu_P
; h=100000
Case #Menu_Escape
quit = #True
Case #Menu_Space
Delay(800)
Case #Menu_W
SaveImage(image,"Randraw - "+FormatDate("%yyyy%mm%dd_%hh%ii%ss", Date())+Str(Random(9999,1))+".jpg", #PB_ImagePlugin_JPEG,99)
StatusBarText(0, 0, "Saved Image " + Str(save), #PB_StatusBar_Right)
save=save+1
EndSelect
Case #PB_Event_Gadget
EventGadget = EventGadget()
Select EventGadget
Case 10
tbbckr=GetGadgetState(10)/9999
SetGadgetState(10,tbbckr*9999)
SetGadgetText(21,StrD(tbbckr))
SetGadgetText(11,"Background: "+StrD(tbbckr))
backgroundold=background
background=tbbckr
For y1=2 To #height1/5-2
For x1=2 To #width1/6-2
y=y1*5+a ;make hex grid from square grid
z=3*Mod(y,2)
lineup=Bool(z=0)
If unreceptivetemp(x1-lineup,y1)<1 ; change background values
unreceptivetemp(x1-lineup,y1)=background
EndIf
Next
Next
Case 12
tbcnst=GetGadgetState(12)/9999
SetGadgetText(22,StrD(tbcnst))
SetGadgetText(13,"Const: "+StrD(tbcnst))
const=tbcnst
Case 21
tbbckr=ValD(GetGadgetText(21))
SetGadgetState(10,tbbckr*9999)
SetGadgetText(11,"Background: "+StrD(tbbckr))
backgroundold=background
background=tbbckr
For y1=2 To #height1/5-2
For x1=2 To #width1/6-2
y=y1*5+a ;make hex grid from square grid
z=3*Mod(y,2)
lineup=Bool(z=0)
If unreceptivetemp(x1-lineup,y1)<1 ; change background values
unreceptivetemp(x1-lineup,y1)=background
EndIf
Next
Next
Case 22
tbcnst=ValD(GetGadgetText(22))
SetGadgetState(12,tbcnst*9999)
SetGadgetText(13,"Const: "+StrD(tbcnst))
Case 25
SetGadgetText(24,"BUSY")
;SetGadgetState(#ImgGadget, ImageID(imagesc))
StartDrawing(ImageOutput(image))
DrawingMode(#PB_2DDrawing_Default)
; SDRAW(image)
CreateThread(@SDRAW(),image)
StopDrawing()
CopyImage(image, copy)
ResizeImage(copy, #width-StatusBarHeight(0), #height-StatusBarHeight(0))
If StartDrawing(ImageOutput(imagesc))
DrawImage(ImageID(copy), 0, 0)
StopDrawing()
StatusBarText(0, 0, "Bckgnd= "+StrD(background), #PB_StatusBar_Center)
StatusBarText(0, 1, "tot= "+Str(tot), #PB_StatusBar_Center)
StatusBarText(0, 2, "count= "+Str(count), #PB_StatusBar_Center)
StatusBarText(0, 3, "total= "+Str(total), #PB_StatusBar_Center)
StatusBarText(0, 4, "ti= "+Str(ti), #PB_StatusBar_Center)
StatusBarText(0, 5, "const="+StrD(const), #PB_StatusBar_Center)
;StatusBarText(0, 6, Str(count), #PB_StatusBar_Center)
;tick=tick+1
SetGadgetState(#ImgGadget, ImageID(imagesc))
; Delay(2000)
EndIf
total=total+1
If Mod(total,40)=0
SaveImage(image,"Randraw - "+FormatDate("%yyyy%mm%dd_%hh%ii%ss", Date())+Str(Random(9999,1))+".jpg", #PB_ImagePlugin_JPEG,99)
StatusBarText(0, 0, "Saved Image " + Str(save), #PB_StatusBar_Right)
EndIf
SetGadgetText(24,"IDLE")
Case 26
keepon=1
Case 27
keepon=0
EndSelect
Case #PB_Event_CloseWindow
Quit=#True
EndSelect
Until quitRe: Apply Setgadgettext()
Hi matalog
Sorry I can't go with your code
But if you are a Windows user the next snippet will give you a method to run many activities at the same time
Try it and good luck
Sorry I can't go with your code
But if you are a Windows user the next snippet will give you a method to run many activities at the same time
Try it and good luck
Code: Select all
Global TEvent
Procedure draw()
For t = 1 To 255
StartDrawing(ImageOutput(0))
For y=1 To 899
For x= 1 To 799
Plot(x,y,t)
Next
Next
StopDrawing()
SetGadgetState(0,ImageID(0))
Next
SetGadgetText(3,"IDLE")
timeKillEvent_(TEvent)
EndProcedure
OpenWindow(0,50,50,1000,900,"Window")
CreateImage(0,800,900)
ImageGadget(0, 0, 0, 800, 900, ImageID(0))
StartDrawing(ImageOutput(0))
Box(0,0,800,900,#Black)
StopDrawing()
ButtonGadget(2,800+30,600,100,50,"Go",#PB_Text_Center)
StringGadget(3,800+30,830,80,25,"IDLE",#PB_Text_Center)
cycle = 10
Repeat
Event = WaitWindowEvent()
Select event
Case #PB_Event_Gadget
Select EventGadget()
Case 2
SetGadgetText(3,"BUSY")
TEvent = timeSetEvent_(cycle,0,@draw(),0,#TIME_PERIODIC)
EndSelect
EndSelect
Until Event = #PB_Event_CloseWindow
End
Egypt my love


