home *** CD-ROM | disk | FTP | other *** search
/ Black Box 4 / BlackBox.cdr / progbas / baswiz13.arj / DEMO.BAS < prev    next >
BASIC Source File  |  1990-05-26  |  7KB  |  172 lines

  1. '   +----------------------------------------------------------------------+
  2. '   |                                                                      |
  3. '   |           BASWIZ  Copyright (c) 1990  Thomas G. Hanlin III           |
  4. '   |                                                                      |
  5. '   |                       The BASIC Wizard's Library                     |
  6. '   |                                                                      |
  7. '   +----------------------------------------------------------------------+
  8.  
  9. DECLARE FUNCTION Center$ (St$)
  10.    REM $INCLUDE: 'BASWIZ.BI'
  11.    DEFINT A-Z
  12.    Rows = 25: Columns = 80                         ' define display size
  13.    WInit Rows, Columns, ErrCode                    ' initialize VWS
  14.    IF ErrCode THEN                                 ' stop if we couldn't...
  15.       PRINT "Sorry, insufficient memory to run Demo."
  16.       END
  17.    END IF
  18.    FInit 15, ErrCode                               ' initialize file handler
  19.    FOpen "DEMO.DAT", "RT", 256, TextFile, ErrCode  ' open file for Read, Text
  20.    IF ErrCode THEN
  21.       PRINT "Unable to access DEMO.DAT file."
  22.       FDone
  23.       END
  24.    END IF
  25.  
  26.    Handle0 = 0                                     ' use background handle
  27.    St$ = "Demonstration of The BASIC Wizard's Library"
  28.    WWriteLn Handle0, Center$(St$)
  29.    WWriteLn Handle0, ""
  30.    St$ = "Copyright (c) 1990  Thomas G. Hanlin III"
  31.    WWriteLn Handle0, Center$(St$)
  32.    WWriteLn Handle0, ""
  33.    WWriteLn Handle0, ""
  34.    DO UNTIL FEOF(TextFile)                         ' read text from file and
  35.       WWriteLn Handle0, FReadLn$(TextFile)         ' ...print it to the
  36.    LOOP                                            ' ...virtual screen
  37.    FDone                                           ' terminate file handler
  38.    WLocate Handle0, 25, 1
  39.    St$ = "Press the space bar for a virtual window demonstration."
  40.    WWrite Handle0, Center$(St$)
  41.    WUpdate                                         ' update the display
  42.    DO
  43.    LOOP UNTIL INKEY$ = " "
  44.  
  45.    ' ------------ This sets up the second demo screen --------------
  46.  
  47.    WOpen Rows, Columns, 7, 5, 22, 45, Handle1, ErrCode
  48.    IF ErrCode THEN
  49.       PRINT "I'm sorry, there's not enough memory available!"
  50.       WDone
  51.       END
  52.    END IF
  53.    WCopy Handle0, Handle1                          ' copy text to new window
  54.    WColor Handle0, 0, 2                            ' recolor background
  55.    WClear Handle0                                  ' clear it
  56.    WLocate Handle0, 1, 1                           ' home the cursor
  57.    WWriteLn Handle0, " This is Window #0, the background screen"
  58.    WColor Handle0, 15, 2
  59.    WLocate Handle0, 14, 48
  60.    WWriteLn Handle0, "This is a slow-motion demo!"
  61.    WColor Handle0, 0, 2
  62.    WLocate Handle0, 25, 1
  63.    WWrite Handle0, Center$("Press the <ESC> key to exit")
  64.    WFrame Handle1, 2, 14, 3                        ' set frame (double lines)
  65.    WTitle Handle1, " Window #1 ", 5, 3             ' set title
  66.    WExplode Handle1                                ' "explode" it on
  67.  
  68.    Rows2 = 10: Columns2 = 40
  69.    Row2 = 9: Col2 = 35
  70.    WOpen Rows2, Columns2, Row2, Col2, 17, 70, Handle2, ErrCode
  71.    IF ErrCode THEN
  72.       PRINT "I'm sorry, there's not enough memory available!"
  73.       WDone
  74.       END
  75.    END IF
  76.    WFrame Handle2, 1, 4, 1                         ' set frame (single lines)
  77.    WTitle Handle2, " Window #2 ", 14, 1            ' set title
  78.    WColor Handle2, 7, 1                            ' set colors
  79.    WClear Handle2                                  ' clear to new colors
  80.    WWriteLn Handle2, "Adding virtual windows to"
  81.    WWriteLn Handle2, "your programs uses only about"
  82.    WWriteLn Handle2, "5K RAM, plus extra memory for"
  83.    WWriteLn Handle2, "each window (around 4K for a"
  84.    WWriteLn Handle2, "full 25x80 virtual screen,"
  85.    WWriteLn Handle2, "which is larger than you'll"
  86.    WWriteLn Handle2, "need for most windows)."
  87.    WWriteLn Handle2, ""
  88.    WWriteLn Handle2, ""
  89.    WWrite Handle2, "                  Look Ma, No Hands!"
  90.    WExplode Handle2                                ' "explode" it on
  91.  
  92.    St$ = "Just a little BASIC Wizardry..."         ' a tiny one-line window!
  93.    Rows = 1: Columns = LEN(St$) + 1
  94.    WOpen Rows, Columns, 3, 38, 3, 37 + LEN(St$), Handle3, ErrCode
  95.    IF ErrCode THEN
  96.       PRINT "I'm sorry, there's not enough memory available!"
  97.       WDone
  98.       END
  99.    END IF
  100.    WColor Handle3, 15, 4                           ' set color
  101.    WWrite Handle3, St$                             ' no <CR><LF> or it scrolls
  102.  
  103.    WUpdate                                         ' pop on the micro window
  104.  
  105.    ' ------------- The second screen is on- let's animate it! ------------
  106.  
  107.    Counter1H = 0                     ' for Window #1
  108.    Direction1H = 1
  109.    Counter1V = 0
  110.    Direction1V = 0
  111.    Counter2A = 0                     ' for Window #2
  112.    Counter2B = 0
  113.    Direction2 = 1
  114.    DO
  115.       ' The following four statements do the actual work.  The rest is just --
  116.       ' to calculate the information for the next step in the animation. -----
  117.       WView Handle1, 1 + Counter1V, 1 + Counter1H                ' set viewport
  118.       WPlace Handle2, Row2 - Counter2B, Col2 + Counter2B         ' screen pos'n
  119.       WSize Handle2, Rows2 - Counter2B, Columns2 - Counter2B * 2 ' window size
  120.       WUpdate                                                    ' display it
  121.       Counter2A = Counter2A + 1
  122.       IF (Counter2A AND 1) = 0 THEN
  123.          Counter2A = 0
  124.          Counter2B = Counter2B + Direction2
  125.          IF Counter2B < 1 OR Counter2B > 5 THEN
  126.             Direction2 = -Direction2
  127.          END IF
  128.       END IF
  129.       Counter1H = Counter1H + Direction1H
  130.       Counter1V = Counter1V + Direction1V
  131.       IF Counter1H < 0 THEN
  132.          Counter1H = 0
  133.          Direction1H = 0
  134.          Direction1V = -1
  135.       ELSEIF Counter1H > 39 THEN
  136.          Counter1H = 39
  137.          Direction1H = 0
  138.          Direction1V = 1
  139.       ELSEIF Counter1V < 0 THEN
  140.          Counter1V = 0
  141.          Direction1V = 0
  142.          Direction1H = 1
  143.       ELSEIF Counter1V > 9 THEN
  144.          Counter1V = 9
  145.          Direction1V = 0
  146.          Direction1H = -1
  147.       END IF
  148.       t! = TIMER                     ' these delay a while so we have long
  149.       WHILE t! = TIMER: WEND         ' enough to see what's going on
  150.       t! = TIMER
  151.       WHILE t! = TIMER: WEND
  152.    LOOP UNTIL INKEY$ = CHR$(27)      ' continue until <ESC> is pressed
  153.  
  154.    ' -------------- All done, time to terminate and exit -----------------
  155.  
  156.    WCollapse Handle3                 ' collapse windows in mixed order
  157.    WCollapse Handle1
  158.    WCollapse Handle2
  159.    WDone                             ' terminate VWS
  160.    junk& = SETMEM(999999)            ' give QB its memory back
  161.    END
  162.  
  163. FUNCTION Center$ (St$)        ' ------ used for centering lines on the screen
  164.    WGetVSize 0, Rows, Columns                ' get size of display
  165.    IF LEN(St$) > Columns THEN
  166.       Center$ = LEFT$(St$, Columns)          ' truncate if string is too long
  167.    ELSE
  168.       Center$ = SPACE$((Columns - LEN(St$) + 1) \ 2) + St$  ' center it
  169.    END IF
  170. END FUNCTION
  171.  
  172.