BBS: Inland Empire Archive Date: 09-10-92 (11:40) Number: 242 From: RICK PEDLEY Refer#: NONE To: BRIAN CUNNINGHAM Recvd: NO Subj: Animation Timing Conf: (2) Quik_Bas
On 09-08-92 Matt Hart wrote to Brian Cunningham...
BC> BC> using a ON TIMER stament to interrupt a DO..LOOP after two
BC> BC> the way - is there any way to get an accurate fraction of a
BC> second pause
BC> The ON TIMER event only checks after every statement
BC> executes, and bloats your code pretty badly. Look into
BC> adding a timer look at the points you need it, perhaps
BC> drawing your stuff, setting a variable to the next TIMER
BC> setting it needs to look at:
BC>
BC> DrawRoutine:
BC> drawstuff
BC> NextEvent# = TIMER+.05# ' 5 100's of a second
BC> RETURN
BC>
BC> DO
BC> drawstuff
BC> DO UNTIL TIMER>NextEvent#
BC> keycheck$=inkey$
BC> if len(keycheck$) then gosub dokeystuff
BC> LOOP
BC> LOOP
Here's something else that might work. The WAIT &H3DA, 8 statement
waits for a vertical blank to occur before continuing program
execution, and these occur 60 times per second. So to put a 1/15th
of a second pause between frames in an animation sequence, you
could do this (soodoughcode):
Move something
FOR x = 1 TO 4
WAIT &H3DA, 8
NEXT x
Move it again
An added advantage besides the constant VBL rate on different computers
(because it's tied to the video firmware and not the CPU), is that
waiting for a vertical blank to occur before drawing will eliminate
most or all of the flicker you would normally see (i.e. objects only
partly drawn before it's time to put the next one on the screen). Try
this program with and without the WAIT I've REM'd out 5 lines from the
bottom:
'ROTBOX by R. Pedley, 92-03-16
'Rotates a small square on screen using two video pages to reduce flicker.
DEFINT A-Z
CONST AspectCorrection! = .73 'Pixels are taller than they are wide --
' adjust for various graphics modes.
' This ratio is about right for my monitor.
HalfDiagonal = 75 'Determines size of square.
CenterX = 320: CenterY = 175 ' - on a 0-639 x 0-349 screen.
ULX = CenterX - HalfDiagonal: IF ULX < 0 THEN ULX = 0 'Keeps coords of
ULY = CenterY - HalfDiagonal: IF ULY < 0 THEN ULY = 0 ' box to fill and
LRX = CenterX + HalfDiagonal: IF ULX > 639 THEN ULX = 639' clear old image.
LRY = CenterY + HalfDiagonal: IF ULY > 349 THEN ULY = 349
DIM Sine!(0 TO 359), Cosine!(0 TO 359) 'Pre-calc all sine
FOR Angle = 0 TO 359 ' & cosine values.
Radian! = Angle * .01745 '(rads per degree)
Sine!(Angle) = SIN(Radian!) * HalfDiagonal * AspectCorrection!
Cosine!(Angle) = COS(Radian!) * HalfDiagonal
NEXT Angle
SCREEN 9, 0 'EGA: 640 x 350 x 16 colors.
COLOR 1, 1 'Blue on blue.
CLS
ActivePage = 1 'Page on which drawing takes place.
VisiblePage = 0 'Page you're looking at.
SCREEN , , ActivePage, VisiblePage 'draw first box on page you can't see.
DO
FOR Angle = 0 TO 89
LINE (ULX, ULY)-(LRX, LRY), 1, BF 'Clear just the box area,
' much faster than CLS.
y1 = CenterY + Sine!(Angle)
x1 = CenterX + Cosine!(Angle)
y2 = CenterY + Sine!(Angle + 90)
x2 = CenterX + Cosine!(Angle + 90)
y3 = CenterY + Sine!(Angle + 180)
x3 = CenterX + Cosine!(Angle + 180)
y4 = CenterY + Sine!(Angle + 270)
x4 = CenterX + Cosine!(Angle + 270)
LINE (x1, y1)-(x2, y2), 15
LINE (x2, y2)-(x3, y3), 15
LINE (x3, y3)-(x4, y4), 15
LINE (x4, y4)-(x1, y1), 15
PAINT (CenterX, CenterY), 15
CIRCLE (CenterX, CenterY), 5, 0, , , AspectCorrection!
PAINT (CenterX, CenterY), 0, 0
ActivePage = ActivePage - 1 - 2 * (ActivePage = 0) '0 <--> 1
VisiblePage = VisiblePage - 1 - 2 * (ActivePage = 0) '1 <--> 0
'WAIT &H3DA, 8 '<<<<---- Run, then remove the REM and run again.
SCREEN , , ActivePage, VisiblePage 'switch active/visible page.
IF LEN(INKEY$) THEN EXIT DO
NEXT Angle
LOOP
... OFFLINE 1.40 * Stalker: One who hunts vegetables.
--- Maximus 2.01wb
* Origin: The BULLpen BBS * Intel 14.4EX (613)549-5168 (1:249/140)

Books at Amazon:
Back to BASIC: The History, Corruption, and Future of the Language
Hackers: Heroes of the Computer Revolution (including Tiny BASIC)
Go to: The Story of the Math Majors, Bridge Players, Engineers, Chess Wizards, Scientists and Iconoclasts who were the Hero Programmers of the Software Revolution
The Advent of the Algorithm: The Idea that Rules the World
Moths in the Machine: The Power and Perils of Programming
Mastering Visual Basic .NET