Advertisement
LBASIC

TSMYST.BAS

Jun 5th, 2023
572
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
QBasic 5.13 KB | Source Code | 0 0
  1. 'From: Trevor Sinclair           Conference: Quik_Bas (3)
  2. 'Date: 09-02-96 15:26            Subject: Mystify                    
  3. 'Hey people, here's my mystify code I though some of you could maybe use.
  4. 'Type a number on the commandline as a paramater to Mystify.exe and that
  5. 'will be the number of lines.  You can form a nice web by doing mystify 200.
  6. ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
  7. ' MYSTIFY.BAS    - by Trevor Sinclair for the public domain.
  8. ' :::::::::::
  9. ' :::::::::::    - This is my QBasic version of Mystify, like the one
  10. ' :::::::::::      that comes with Windows.  If you change the screen
  11. ' :::::::::::      mode, be sure to change the maxx, maxy variables.
  12. ' :::::::::::    - This is anybody's source code now, so use it in your
  13. ' :::::::::::      programs and don't worry about giving me credit.
  14. '
  15. '                - You may wish to add a delay.  On my 386 this was a bit
  16. '                  too fast.
  17.  
  18. '          ******* Thanks to Kurt Kuzba for the Delay sub *******
  19.  
  20. DECLARE SUB delay (hold!)
  21.  
  22. DEFINT A-Z                ' all untypes variables are int
  23.  
  24. OPTION BASE 1             ' Arrays start at 1
  25. RANDOMIZE TIMER           ' randomize randomizer
  26.  
  27. SCREEN 9
  28.  
  29. TYPE dotType
  30.   x AS INTEGER
  31.   y AS INTEGER
  32. END TYPE
  33.  
  34. numlines = VAL(COMMAND$)
  35. IF numlines < 2 THEN numlines = 5
  36.  
  37. DIM Points(numlines, 4) AS dotType   ' the main array
  38. DIM Incs(4) AS dotType        ' holds the dots' increments
  39. head = 1
  40. tail = 2
  41.  
  42. col = RND * 14 + 1            ' pick a color
  43. colCounter = 0                ' counts up to certain amount then
  44.                               '  changes color
  45.  
  46. maxx = 640                    ' change these to the maximum coordinates
  47. maxy = 350                    ' for your screen mode
  48.  
  49. FOR i = 1 TO 4                ' generate initial increments
  50.   DO
  51.     xinc = RND * 10 - 5
  52.     yinc = RND * 10 - 5
  53.   LOOP UNTIL xinc <> 0 AND yinc <> 0
  54.   Incs(i).x = xinc
  55.   Incs(i).y = yinc
  56. NEXT i
  57.  
  58. FOR i = 1 TO 4                ' starting spots for each point in the thingy
  59.   Points(head, i).x = RND * maxx
  60.   Points(head, i).y = RND * maxy
  61. NEXT i
  62.  
  63. DO                                        ' main loop
  64.  
  65.   colCounter = colCounter + 1             ' increment colCounter
  66.   IF (colCounter > 50) THEN              ' change current color when
  67.     col = RND * 14 + 1                    '  colCounter reaches 200
  68.     colCounter = 0
  69.   END IF
  70.  
  71.   FOR i = 1 TO 3
  72.     x1 = Points(tail, i).x: x2 = Points(tail, i + 1).x     ' erase most last
  73.     y1 = Points(tail, i).y: y2 = Points(tail, i + 1).y     '  thingy drawn
  74.     LINE (x1, y1)-(x2, y2), 0
  75.   NEXT i
  76.   x1 = Points(tail, 4).x: x2 = Points(tail, 1).x
  77.   y1 = Points(tail, 4).y: y2 = Points(tail, 1).y
  78.   LINE (x1, y1)-(x2, y2), 0
  79.  
  80.   oldHead = head                     ' change the pointers to the tail
  81.   head = tail                        '  and head elements.  This simulates
  82.   tail = tail + 1                    '  a stack.
  83.   IF tail > numlines THEN tail = 1          ' make sure stack doesn't overflow
  84.  
  85.   FOR i = 1 TO 4                     ' make new shape
  86.     Points(head, i).x = Points(oldHead, i).x + Incs(i).x
  87.     Points(head, i).y = Points(oldHead, i).y + Incs(i).y
  88.   NEXT i
  89.  
  90.   FOR i = 1 TO 4                     ' check that the thingy isn't off the
  91.     temp = RND * 10 + 1              '  screen, invert increments if it is.
  92.     IF (Points(head, i).x > maxx - 12) THEN Incs(i).x = -temp
  93.     IF (Points(head, i).x < 12) THEN Incs(i).x = temp
  94.     IF (Points(head, i).y > maxy - 12) THEN Incs(i).y = -temp
  95.     IF (Points(head, i).y < 12) THEN Incs(i).y = temp
  96.   NEXT i
  97.  
  98.   FOR i = 1 TO 3                      ' now draw the current thingy
  99.     x1 = Points(head, i).x: x2 = Points(head, i + 1).x
  100.     y1 = Points(head, i).y: y2 = Points(head, i + 1).y
  101.     LINE (x1, y1)-(x2, y2), col
  102.   NEXT i
  103.   x1 = Points(head, 4).x: x2 = Points(head, 1).x
  104.   y1 = Points(head, 4).y: y2 = Points(head, 1).y
  105.   LINE (x1, y1)-(x2, y2), col
  106.    
  107.   delay .01                           ' delay program operation.
  108.                                       '  Thank you Kurt Kuzba for this SUB
  109.                                       '  I was wondering how one did that..
  110. LOOP WHILE INKEY$ = ""   ' stop when keyboard has been pressed
  111.  
  112. SCREEN 0                 ' return to text screen mode
  113.  
  114. ' Okay basically what this does is hold the data for all the 4 corners of
  115. ' the quadrilateral, and saves the data for the last five dots.  By simulating
  116. ' a stack, with wrap-around pointers to the head and tail, it uses the same
  117. ' five elements over and over again.  That is the best I can explain it.
  118. '
  119. ' Made by Trevor Sinclair, September 1st, 1996.
  120. '* Origin: <FIDONET> Late Nite DIVERSIONS * Sarnia Ontario
  121. '* 519-332-0241 * (1:246/104)
  122.  
  123. SUB delay (hold!)   ' Thanks to Kurt Kuzba for this function
  124. ' pause program in .05 second intervals.
  125.  
  126. DEF SEG = 0
  127. IF hold! < (3600 / 65536) THEN hold! = (3600 / 65536)
  128. WHILE hold! > 14.0625
  129.    hold% = PEEK(&H46C)
  130.    WHILE PEEK(&H46C) = hold%: WEND
  131.    WHILE PEEK(&H46C) <> hold%: WEND
  132.    hold! = hold! - 14.0625
  133. WEND
  134. hold% = hold! * 18.20444444#
  135. hold% = (PEEK(&H46C) + hold%) AND 255
  136.    WHILE PEEK(&H46C) <> hold%: WEND
  137.  
  138. END SUB
  139.  
  140.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement