|
Post by xcoder on Nov 7, 2020 5:06:44 GMT -5
I need 8 indicators randomly flashing to indicate binary numbers in a GUI. Would like for the indictors to randomly flash for 10 seconds when I select a button. I'm trying to liven up a program to give the impression of activity in progress.
|
|
|
Post by Carl Gundel on Nov 7, 2020 10:22:19 GMT -5
I need 8 indicators randomly flashing to indicate binary numbers in a GUI. Would like for the indictors to randomly flash for 10 seconds when I select a button. I'm trying to liven up a program to give the impression of activity in progress. Here is one. You need to provide your own bitmaps, one for on, and one for off. The code expects them to be 32 pixels wide. loadbmp "on", "lighton.bmp" loadbmp "off", "lightoff.bmp" open "binary flasher for 10 seconds" for graphics as #flasher #flasher "down" timer 200, [flash] start = time$("ms") timeLimitMS = 10 * 1000 'in milliseconds" wait
[flash] for x = 0 to 7 light$ = "on" if rnd(1) < 0.5 then light$ = "off" #flasher "drawbmp "; light$; " "; x * 32; " 0" next x if time$("ms") - start < timeLimitMS then #flasher "discard" else timer 0 #flasher "home" #flasher "|Done!" #flasher "flush" end if wait
|
|
|
Post by Carl Gundel on Nov 7, 2020 10:29:17 GMT -5
And here is a version that doesn't need bitmaps.
open "binary flasher for 10 seconds" for graphics as #flasher #flasher "down" timer 200, [flash] start = time$("ms") timeLimitMS = 10 * 1000 'in milliseconds" wait
[flash] for x = 0 to 7 light$ = "red" if rnd(1) < 0.5 then light$ = "darkred" #flasher "backcolor "; light$ #flasher "place "; x * 32 + 16; " 16" #flasher "circlefilled 12" next x if time$("ms") - start < timeLimitMS then #flasher "discard" else timer 0 #flasher "home; color white" #flasher "|Done!" #flasher "flush" end if wait
|
|
|
Post by tenochtitlanuk on Nov 7, 2020 10:29:49 GMT -5
..or try this, which just sets the LEDs as a graphic point..
WindowWidth =400 WindowHeight =300 nomainwin graphicbox #w.g1, 100 ,100, 204, 30 button #w.b1, "killTime", killTime, LR, 50, 30 open "Demo. of binary random count" for window as #w #w "trapclose quit" #w.g1 "down ; fill darkblue ; size 18" wait
sub killTime h$ start =time$( "seconds") do x =25 *int( 8 *rnd( 1)) if rnd( 1) <0.5 then #w.g1 "color 255 90 90" else #w.g1 "color darkblue" #w.g1 "set "; x +12; " 15 " now =time$( "seconds") scan loop until ( now -start) >=10 end sub
sub quit h$ close #w end end sub
|
|
|
Post by Carl Gundel on Nov 7, 2020 10:39:16 GMT -5
Here's a version that doesn't use a timer, if that's your thing.
open "binary flasher for 10 seconds" for graphics as #flasher #flasher "down" start = time$("ms") timeLimitMS = 10 * 1000 'in milliseconds"
while time$("ms") - start < timeLimitMS if time$("ms") - animateMS > 200 then animateMS = time$("ms") for x = 0 to 7 light$ = "red" if rnd(1) < 0.5 then light$ = "darkred" #flasher "backcolor "; light$ #flasher "place "; x * 32 + 16; " 16" #flasher "circlefilled 12" next x #flasher "discard" end if wend #flasher "home; color white" #flasher "|Done!" #flasher "flush" wait
|
|
|
Post by tenochtitlanuk on Nov 7, 2020 10:47:39 GMT -5
The ability to whip up things like this in minutes is why we love LB! Code for a related 'busy lights' demo has been on my site at www.diga.me.uk/password.html for years. Some of us remember fondly the WHOPR computer!
|
|
|
Post by Carl Gundel on Nov 7, 2020 11:15:21 GMT -5
The ability to whip up things like this in minutes is why we love LB! Code for a related 'busy lights' demo has been on my site at www.diga.me.uk/password.html for years. Some of us remember fondly the WHOPR computer! Joshua
|
|