April 25, 2024, 01:11:03 PM

News:

Own IWBasic 2.x ? -----> Get your free upgrade to 3.x now.........


An interesting Wait.

Started by GWS, April 17, 2012, 12:28:43 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

GWS

Hi,

Here's an interesting little program from years ago ..  ::)

I've no idea who penned it, but it uses the WAIT instruction in ways I've not seen before.

Here it is, modified slightly by me to improve flicker and timings ..


' small intro (Author unknown)
DEF win:WINDOW
DEF x,y,w,h:INT
DEF rr,gg,bb:INT
DEF run,lx:int
'---------------------------------------------------------
WINDOW win,-300,0,300,255,@nocaption|@border,0,"Intro",<class>
SETWINDOWCOLOR win,rgb(231,231,231)
Intro()
Pause()

CLOSEWINDOW win
END
'--------------------------
SUB <class>
SELECT @CLASS
CASE @IDCLOSEWINDOW
run=0
CASE @IDCREATE
ENDSELECT
RETURN

SUB Intro
gg=0
bb=0
x=0:w=300:h=5
y=255
For n=0 TO 255 step 1
y=y-1
gg=y:bb=y
Loop()
RECT win, x,n,w,h, RGB(0,gg,bb),RGB(0,gg,bb)
Next n

CENTERWINDOW win

'------------------------------------
SETFONT win, "Tahoma", 7, 700
DRAWMODE win, @TRANSPARENT
Move win,10,25
FRONTPEN win, RGB(180,80,80)
Print win,"LOADING..."
LINE win,x,36,w,36,rgb(0,gg-140,bb-140)
LINE win,x,24,w,24,rgb(140,gg,bb)
'------------------------------------
RECT win, x+6,150,w-20,h+3, RGB(0,gg,bb)
'--------------------------------------
FRONTPEN win, RGB(180,gg,bb)
FOR lx = 8 TO 283
LINE win,lx,152,lx,156,rgb(180,gg,bb)
For px = 1 to 50
Wait px
Signs()
Next px
NEXT lx
RETURN
'-----------------------------------
SUB Loop
For y2 = 25 to 35 step 1
LINE win,x,y2,w,y2,rgb(20,gg-40,bb)
NEXT y2
Return
'----------------------------------
SUB Pause
' about 5 sec
For pa = 0 to 5000
LINE win,x,256,w,256,rgb(20,gg-40,bb)
wait pa
Next pa
'run=0
Return
'-----------------------------
SUB Signs
SETFONT win, "Tahoma", 12, 700
If lx=8:move win,50,100:print win,"I":Endif
If lx=63:move win,70,100:print win,"N":Endif
If lx=118:move win,90,100:print win,"T":Endif
If lx=173:move win,110,100:print win,"R":Endif
If lx=228:move win,130,100:print win,"O":Endif
Return



best wishes, :)

Graham
Tomorrow may be too late ..

ZeroDog

" it uses the WAIT instruction in ways I've not seen before."

Probably because the way they are being used are incorrect.  If I am not mistaken, the WAIT instruction only accepts a boolean value, so once the loop passes the first interval, the parameter being passed is not actually being accepted, since its neither 0 nor 1. 


GWS

Hi ZD,

Yep, I think you're right.

If you take this bit:


FOR lx = 8 TO 283
LINE win,lx,152,lx,156,rgb(180,gg,bb)
For px = 1 to 50
Wait px
Signs()
Next px
NEXT lx


and change it to this:


FOR lx = 8 TO 283
LINE win,lx,152,lx,156,rgb(180,gg,bb)
For px = 1 to 50
Wait 1
Signs()
Next px
NEXT lx


.. you get the same timing effect.  Because it's doing a WAIT True (ie Wait 1) at each pass through the outer FOR loop.

So the use of the 'px' wasn't needed in the inner loop.  Still, it is valid, and works OK because any positive value 1 or more qualifies as 'True'.  :)

all the best, :)

Graham
Tomorrow may be too late ..

ZeroDog

In the case of "pauses", where you want your program to pause for a certain amount of time, you should be using the Sleep() API function found in the "Kernel32.dll":


DECLARE "kernel32.dll",Sleep(dwMilliseconds:INT)