Author Topic: Meander testing grounds  (Read 5943 times)

0 Members and 1 Guest are viewing this topic.

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Meander testing grounds
« Reply #15 on: September 17, 2020, 02:37:30 pm »
I have created a monster....

Seriously though, Thanks for the help. gets me a lot closer to the look and feel I wanted.


OK, I think we are ready for some lightning (do you hear evil laughter?)

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: Meander testing grounds
« Reply #16 on: September 17, 2020, 06:32:03 pm »
This reminds me of the path and lighting generator which I was working on with my little rogue-clone, before life interrupted the start of a nice project.  You guys might want to take a look in it sometime.

https://www.qb64.org/forum/index.php?action=dlattach;topic=1696.0;attach=3795
« Last Edit: September 17, 2020, 06:34:44 pm by SMcNeill »
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Meander testing grounds
« Reply #17 on: September 17, 2020, 07:15:59 pm »
Hi Steve,

Yes, I remember that project start (don't remember the name) but arrowing around opened up tunnels and rooms. Your link is only downloading a screen shot.

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: Meander testing grounds
« Reply #18 on: September 17, 2020, 08:35:16 pm »
Hi Steve,

Yes, I remember that project start (don't remember the name) but arrowing around opened up tunnels and rooms. Your link is only downloading a screen shot.

Sorry.  Copied the wrong link apparently.  Try this one: https://www.qb64.org/forum/index.php?topic=1696.msg109537#msg109537

CreateMap is the sub which draws our rooms and then meanders our paths for us.  My concept is really simple: Start at point A, and move towards point B, with a chance for the random variance which generates the “meandering”.


For example, say B is 10 steps due East from A...

Start at A:
East
East
North (random change)
North (again, the random change kicked in)
East
East
South (automatic course correction as we move towards B)
West (random kicked in again.)

And so on...

As long as your random variance is less than the chance for direct approach, you’ll eventually reach the goal.
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline _vince

  • Seasoned Forum Regular
  • Posts: 422
    • View Profile
Re: Meander testing grounds
« Reply #19 on: September 17, 2020, 09:26:49 pm »
Fascinating! Nice work solving the 1105 rooms problem

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Meander testing grounds
« Reply #20 on: September 18, 2020, 11:05:32 pm »
And here comes the lightning!

Watch out!

Code: QB64: [Select]
  1. _TITLE "Adding some lightning" ' b+ 2020-09-17   so much better in living color!!
  2. ' ah much better response on on escape or Q to quit! too.
  3.  
  4. SCREEN _NEWIMAGE(1024, 620, 32)
  5. _DELAY .25
  6. '_FULLSCREEN
  7. CONST flashy = &HFFFFFF88
  8. TYPE box
  9.     x AS SINGLE
  10.     y AS SINGLE
  11.     w AS SINGLE
  12.     h AS SINGLE
  13.     K AS _UNSIGNED LONG
  14.  
  15. TYPE move
  16.     x AS SINGLE
  17.     y AS SINGLE
  18.     'd AS INTEGER
  19.  
  20. DIM SHARED beeLineK AS _UNSIGNED LONG, gSize AS INTEGER
  21.  
  22.  
  23. DIM backColor AS _UNSIGNED LONG, hc AS INTEGER
  24.     'whole new set
  25.     REDIM VS(_WIDTH, _HEIGHT)
  26.     gSize = units(INT(40 * RND) + 11, 5)
  27.     nBoxes = INT(SQR(_WIDTH * _HEIGHT) / gSize * RND) + 1
  28.     IF nBoxes < 15 THEN nBoxes = 15
  29.     IF nBoxes > 100 THEN nBoxes = 100
  30.     COLOR &HFFFFFFFF, &HFF000000
  31.     PRINT gSize, nBoxes
  32.     '_DISPLAY
  33.     REDIM b(1 TO nBoxes) AS box 'new box set
  34.     FOR i = 1 TO nBoxes
  35.         tryAgain:
  36.         b(i).x = units(RND * (_WIDTH - 2 * (gSize + 1)) + gSize + 1, gSize) 'get x, y off the edges of screen!
  37.         b(i).y = units(RND * (_HEIGHT - 2 * (gSize + 1)) + gSize + 1, gSize)
  38.         IF i > 1 THEN
  39.             OK = -1
  40.             FOR j = 1 TO i - 1
  41.                 IF _HYPOT(b(j).x - b(i).x, b(j).y - b(i).y) < 3 * gSize THEN OK = 0: EXIT FOR
  42.             NEXT
  43.             IF OK = 0 THEN GOTO tryAgain
  44.         END IF
  45.         b(i).w = gSize + RND * gSize * .5
  46.         b(i).h = gSize + RND * gSize * .5
  47.         b(i).K = _RGB32(RND * 85 + 170, RND * 85 + 170, RND * 85 + 170)
  48.     NEXT
  49.     backColor = _RGB32(RND * 65, RND * 65, RND * 65)
  50.     hc = maxC(backColor)
  51.     IF hc = 1 THEN beeLineK = _RGB32(0, RND * 85 + 85, RND * 85 + 85)
  52.     IF hc = 2 THEN beeLineK = _RGB32(RND * 85 + 85, 0, RND * 85 + 85)
  53.     IF hc = 3 THEN beeLineK = _RGB32(RND * 85 + 85, RND * 85 + 85, 0)
  54.     COLOR , backColor
  55.     CLS
  56.     drawGrid gSize, gSize, _WIDTH - 1, _HEIGHT - 1, gSize, &HFF404040
  57.     'SLEEP
  58.     FOR i = 2 TO nBoxes '                                  draw the meanderings
  59.         meander2 b(i - 1).x, b(i - 1).y, b(i).x, b(i).y
  60.         LINE (b(i).x - b(i).w * .5, b(i).y - b(i).h * .5)-STEP(b(i).w, b(i).h), b(i).K, BF 'draw the boxes
  61.         LINE (b(i - 1).x - b(i - 1).w * .5, b(i - 1).y - b(i - 1).h * .5)-STEP(b(i - 1).w, b(i - 1).h), b(i - 1).K, BF 'draw the boxes
  62.     NEXT
  63.     FOR i = 1 TO nBoxes
  64.         LINE (b(i).x - b(i).w * .5, b(i).y - b(i).h * .5)-STEP(b(i).w, b(i).h), b(i).K, BF 'draw the boxes
  65.     NEXT
  66.  
  67.     '  and now for some lightning!!!
  68.     grd& = _NEWIMAGE(_WIDTH, _HEIGHT, 32)
  69.     _PUTIMAGE , 0, grd&
  70.     DIM i AS LONG
  71.     i = 0
  72.     REDIM flash AS box, moves(0) AS move, mItem AS move
  73.     r = INT(RND * nBoxes) + 1 'pick a place to strike, light it up
  74.     moves(i).x = b(r).x: moves(i).y = b(r).y: flash.w = b(r).w: flash.h = b(r).h: flash.K = flashy
  75.     LINE (moves(i).x - .5 * flash.w, moves(i).y - .5 * flash.h)-STEP(flash.w, flash.h), flashy - RND * 150, BF
  76.     GOSUB checkoutThePlace
  77.     oldUB = 0
  78.     circuit:
  79.     ub = UBOUND(moves)
  80.     IF ub > oldUB THEN
  81.         _PUTIMAGE , grd&, 0
  82.         FOR i = oldUB TO ub
  83.             fcirc moves(i).x, moves(i).y, .33 * gSize, flashy - RND * 150
  84.             GOSUB checkoutThePlace
  85.         NEXT
  86.         oldUB = ub
  87.         _DISPLAY
  88.         _LIMIT 10
  89.         GOTO circuit
  90.     END IF
  91.     _PUTIMAGE , grd&, 0
  92.     BEEP
  93.     _FREEIMAGE grd&
  94.     SLEEP
  95.  
  96.  
  97. checkoutThePlace:
  98. IF moves(i).x + .5 * gSize >= 0 AND moves(i).x + .5 * gSize < _WIDTH THEN
  99.     IF VS(moves(i).x + .5 * gSize, moves(i).y) = 1 THEN
  100.         mItem.x = moves(i).x + gSize: mItem.y = moves(i).y
  101.         sAppend moves(), mItem
  102.         VS(moves(i).x + .5 * gSize, moves(i).y) = 0
  103.     END IF
  104. IF moves(i).y + .5 * gSize >= 0 AND moves(i).y + .5 * gSize < _HEIGHT THEN
  105.     IF VS(moves(i).x, moves(i).y + .5 * gSize) = 1 THEN
  106.         mItem.x = moves(i).x: mItem.y = moves(i).y + gSize
  107.         sAppend moves(), mItem
  108.         VS(moves(i).x, moves(i).y + .5 * gSize) = 0
  109.     END IF
  110. IF moves(i).x - .5 * gSize >= 0 AND moves(i).x - .5 * gSize < _WIDTH THEN
  111.     IF VS(moves(i).x - .5 * gSize, moves(i).y) = 1 THEN
  112.         mItem.x = moves(i).x - gSize: mItem.y = moves(i).y
  113.         sAppend moves(), mItem
  114.         VS(moves(i).x - .5 * gSize, moves(i).y) = 0
  115.     END IF
  116. IF moves(i).y - .5 * gSize >= 0 AND moves(i).y - .5 * gSize < _HEIGHT THEN
  117.     IF VS(moves(i).x, moves(i).y - .5 * gSize) = 1 THEN
  118.         mItem.x = moves(i).x: mItem.y = moves(i).y - gSize
  119.         sAppend moves(), mItem
  120.         VS(moves(i).x, moves(i).y - .5 * gSize) = 0
  121.     END IF
  122.  
  123. SUB meander2 (x1, y1, x2, y2) ' snap to grid!   gSize is shared
  124.     startx = x1: starty = y1: endx = x2: endy = y2
  125.     x = startx: y = starty
  126.     GOSUB dist
  127.     IF dist > 100 THEN
  128.         time = INT(RND * 8 + 4) ' total amount allowed to move  The More the time the more the meander!!!!
  129.     ELSE
  130.         time = 3
  131.     END IF
  132.     startTime = time '       > 20 is too much!!
  133.     IF RND < .5 THEN lastmoveX = 0 ELSE lastmoveX = -1
  134.     lastx = startx: lasty = starty
  135.     DO
  136.         GOSUB dist
  137.         IF RND < .5 THEN d = -1 ELSE d = 1
  138.         IF lastmoveX = 0 THEN
  139.             lastx = x
  140.             IF time <= 2 THEN
  141.                 x = endx
  142.             ELSE
  143.                 dx = units(d * (.4 * distx * RND + gSize), gSize)
  144.                 IF dx = 0 THEN dx = gSize
  145.                 IF x + dx > 0 AND x + dx < _WIDTH THEN
  146.                     x = x + dx
  147.                 ELSE
  148.                     x = x + -dx
  149.                 END IF
  150.             END IF
  151.             'LINE (lastx, y)-(x, y)
  152.             beeline lastx, y, x, y
  153.             lastmoveX = -1
  154.         ELSE
  155.             lasty = y
  156.             IF time <= 2 THEN
  157.                 y = endy
  158.             ELSE
  159.                 dy = units(d * (.3 * disty * RND + gSize), gSize)
  160.                 IF dy = 0 THEN dy = gSize
  161.                 IF y + dy > 0 AND y + dy < _HEIGHT THEN
  162.                     y = y + dy
  163.                 ELSE
  164.                     y = y + -dy
  165.                 END IF
  166.             END IF
  167.             'LINE (x, lasty)-(x, y)
  168.             beeline x, lasty, x, y
  169.             lastmoveX = 0
  170.         END IF
  171.         time = time - 1
  172.         '_LIMIT 10
  173.     LOOP UNTIL time <= 0
  174.     EXIT SUB
  175.     dist:
  176.     distx = endx - x: disty = endy - y
  177.     RETURN
  178.  
  179. SUB fcirc (CX AS INTEGER, CY AS INTEGER, R AS INTEGER, C AS _UNSIGNED LONG)
  180.     DIM Radius AS INTEGER, RadiusError AS INTEGER
  181.     DIM X AS INTEGER, Y AS INTEGER
  182.     Radius = ABS(R): RadiusError = -Radius: X = Radius: Y = 0
  183.     IF Radius = 0 THEN PSET (CX, CY), C: EXIT SUB
  184.     LINE (CX - X, CY)-(CX + X, CY), C, BF
  185.     WHILE X > Y
  186.         RadiusError = RadiusError + Y * 2 + 1
  187.         IF RadiusError >= 0 THEN
  188.             IF X <> Y + 1 THEN
  189.                 LINE (CX - Y, CY - X)-(CX + Y, CY - X), C, BF
  190.                 LINE (CX - Y, CY + X)-(CX + Y, CY + X), C, BF
  191.             END IF
  192.             X = X - 1
  193.             RadiusError = RadiusError - X * 2
  194.         END IF
  195.         Y = Y + 1
  196.         LINE (CX - X, CY - Y)-(CX + X, CY - Y), C, BF
  197.         LINE (CX - X, CY + Y)-(CX + X, CY + Y), C, BF
  198.     WEND
  199.  
  200. SUB beeline (x1, y1, x2, y2)
  201.     IF x1 = x2 THEN
  202.         IF y1 <= y2 THEN FOR y = y1 TO y2: fcirc x1, y, 2, beeLineK: VS(INT(x1), INT(y)) = 1: NEXT
  203.         IF y1 > y2 THEN FOR y = y1 TO y2 STEP -1: fcirc x1, y, 2, beeLineK: VS(INT(x1), INT(y)) = 1: NEXT
  204.     ELSE
  205.         IF x1 <= x2 THEN FOR x = x1 TO x2: fcirc x, y1, 2, beeLineK: VS(INT(x), INT(y1)) = 1: NEXT
  206.         IF x1 > x2 THEN FOR x = x1 TO x2 STEP -1: fcirc x, y1, 2, beeLineK: VS(INT(x), INT(y1)) = 1: NEXT
  207.     END IF
  208.  
  209.     IF _RED32(K) >= _GREEN32(K) AND _RED32(K) >= _BLUE32(K) THEN maxC = 1: EXIT FUNCTION
  210.     IF _GREEN32(K) >= _BLUE(K) THEN maxC = 2 ELSE maxC = 3
  211.  
  212. ' this sub needs FUNCTION units (x, unit)
  213. SUB drawGrid (x1, y1, x2, y2, gsize, gridClr AS _UNSIGNED LONG) ' grid of square gsize X gsize
  214.     ' fit a grid between x1, x2 and  y1, y2
  215.     ' x1, y1 top right corner and x2, y2 expected bottom right corner of boundary line
  216.  
  217.     DIM x AS INTEGER, y AS INTEGER, gx1 AS INTEGER, gy1 AS INTEGER, gx2 AS INTEGER, gy2 AS INTEGER
  218.     gx1 = units(x1, gsize): gy1 = units(y1, gsize) 'convert to grid coordinates
  219.     gx2 = units(x2, gsize): gy2 = units(y2, gsize)
  220.     IF gx1 < x1 THEN gx1 = gx1 + gsize 'stay inside boundarys passed to sub
  221.     IF gy1 < y1 THEN gy1 = gy1 + gsize
  222.     IF gx1 >= gx2 OR gy1 >= gy2 THEN EXIT SUB 'that's not even a single square!
  223.     FOR x = gx1 TO gx2 STEP gsize: LINE (x, gy1)-(x, gy2), gridClr: NEXT
  224.     FOR y = gy1 TO gy2 STEP gsize: LINE (gx1, y)-(gx2, y), gridClr: NEXT
  225.  
  226. FUNCTION units (x, unit)
  227.     units = INT(x / unit) * unit
  228.  
  229. SUB sAppend (arr() AS move, addItem AS move)
  230.     REDIM _PRESERVE arr(LBOUND(arr) TO UBOUND(arr) + 1) AS move
  231.     arr(UBOUND(arr)) = addItem
  232.  
  233.  
  234.  

EDIT: Oh ha! the lightning had some bugs. ;-))  fixed
« Last Edit: September 19, 2020, 12:05:19 am by bplus »

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Meander testing grounds
« Reply #21 on: September 19, 2020, 12:45:16 am »
Burn out the lights too: 
Code: QB64: [Select]
  1. _TITLE "Adding some lightning" ' b+ 2020-09-17   so much better in living color!!
  2. ' ah much better response on on escape or Q to quit! too.
  3.  
  4. SCREEN _NEWIMAGE(1024, 620, 32)
  5. _DELAY .25
  6. '_FULLSCREEN
  7. CONST flashy = &HFFFFFF00
  8. TYPE box
  9.     x AS SINGLE
  10.     y AS SINGLE
  11.     w AS SINGLE
  12.     h AS SINGLE
  13.     K AS _UNSIGNED LONG
  14.     hit AS INTEGER
  15.  
  16. TYPE move
  17.     x AS SINGLE
  18.     y AS SINGLE
  19.     'd AS INTEGER
  20.  
  21. DIM SHARED beeLineK AS _UNSIGNED LONG, gSize AS INTEGER
  22.  
  23.  
  24. DIM backColor AS _UNSIGNED LONG, hc AS INTEGER
  25.     'whole new set
  26.     REDIM VS(_WIDTH, _HEIGHT)
  27.     gSize = units(INT(20 * RND) + 6, 5)
  28.     nBoxes = INT(SQR(_WIDTH * _HEIGHT) / gSize * RND) + 1
  29.     IF nBoxes < 40 THEN nBoxes = 40
  30.     IF nBoxes > 100 THEN nBoxes = 100
  31.     COLOR &HFFFFFFFF, &HFF000000
  32.     PRINT gSize, nBoxes
  33.     '_DISPLAY
  34.     REDIM b(1 TO nBoxes) AS box 'new box set
  35.     FOR i = 1 TO nBoxes
  36.         tryAgain:
  37.         b(i).x = units(RND * (_WIDTH - 2 * (gSize + 1)) + gSize + 1, gSize) 'get x, y off the edges of screen!
  38.         b(i).y = units(RND * (_HEIGHT - 2 * (gSize + 1)) + gSize + 1, gSize)
  39.         IF i > 1 THEN
  40.             OK = -1
  41.             FOR j = 1 TO i - 1
  42.                 IF _HYPOT(b(j).x - b(i).x, b(j).y - b(i).y) < 3 * gSize THEN OK = 0: EXIT FOR
  43.             NEXT
  44.             IF OK = 0 THEN GOTO tryAgain
  45.         END IF
  46.         b(i).w = gSize + RND * gSize * .5
  47.         b(i).h = gSize + RND * gSize * .5
  48.         b(i).K = _RGB32(RND * 85 + 170, RND * 85 + 170, RND * 85 + 170)
  49.     NEXT
  50.     backColor = _RGB32(RND * 65, RND * 65, RND * 65)
  51.     hc = maxC(backColor)
  52.     IF hc = 1 THEN beeLineK = _RGB32(0, RND * 85 + 85, RND * 85 + 85)
  53.     IF hc = 2 THEN beeLineK = _RGB32(RND * 85 + 85, 0, RND * 85 + 85)
  54.     IF hc = 3 THEN beeLineK = _RGB32(RND * 85 + 85, RND * 85 + 85, 0)
  55.     COLOR , backColor
  56.     CLS
  57.     drawGrid gSize, gSize, _WIDTH - 1, _HEIGHT - 1, gSize, &HFF404040
  58.     'SLEEP
  59.     FOR i = 2 TO nBoxes '                                  draw the meanderings
  60.         meander2 b(i - 1).x, b(i - 1).y, b(i).x, b(i).y
  61.         LINE (b(i).x - b(i).w * .5, b(i).y - b(i).h * .5)-STEP(b(i).w, b(i).h), b(i).K, BF 'draw the boxes
  62.         LINE (b(i - 1).x - b(i - 1).w * .5, b(i - 1).y - b(i - 1).h * .5)-STEP(b(i - 1).w, b(i - 1).h), b(i - 1).K, BF 'draw the boxes
  63.     NEXT
  64.     FOR i = 1 TO nBoxes
  65.         LINE (b(i).x - b(i).w * .5, b(i).y - b(i).h * .5)-STEP(b(i).w, b(i).h), b(i).K, BF 'draw the boxes
  66.     NEXT
  67.  
  68.     '  and now for some lightning!!!
  69.     grd& = _NEWIMAGE(_WIDTH, _HEIGHT, 32)
  70.     _PUTIMAGE , 0, grd&
  71.     DIM i AS LONG
  72.     i = 0
  73.     REDIM flash AS box, moves(0) AS move, mItem AS move
  74.     r = INT(RND * nBoxes) + 1 'pick a place to strike, light it up
  75.     moves(i).x = b(r).x: moves(i).y = b(r).y: flash.w = b(r).w: flash.h = b(r).h: flash.K = flashy
  76.     LINE (moves(i).x - .5 * flash.w, moves(i).y - .5 * flash.h)-STEP(flash.w, flash.h), flashy, BF
  77.     GOSUB checkoutThePlace
  78.     oldUB = 0
  79.     circuit:
  80.     ub = UBOUND(moves)
  81.     IF ub > oldUB THEN
  82.         _PUTIMAGE , grd&, 0
  83.         FOR i = 1 TO nBoxes
  84.             IF b(i).hit THEN LINE (b(i).x - b(i).w * .5, b(i).y - b(i).h * .5)-STEP(b(i).w, b(i).h), &HFF551100, BF
  85.         NEXT
  86.         FOR i = oldUB TO ub
  87.             fcirc moves(i).x, moves(i).y, .33 * gSize, flashy - RND * 150
  88.             FOR j = 1 TO nBoxes
  89.                 IF moves(i).x = b(j).x AND moves(i).y = b(j).y THEN b(j).hit = 1
  90.             NEXT
  91.             GOSUB checkoutThePlace
  92.         NEXT
  93.         oldUB = ub
  94.         _DISPLAY
  95.         _LIMIT 10
  96.         GOTO circuit
  97.     END IF
  98.     _PUTIMAGE , grd&, 0
  99.     FOR i = 1 TO nBoxes
  100.         IF b(i).hit THEN LINE (b(i).x - b(i).w * .5, b(i).y - b(i).h * .5)-STEP(b(i).w, b(i).h), &HFF551100, BF
  101.     NEXT
  102.     BEEP
  103.     _FREEIMAGE grd&
  104.     SLEEP
  105.  
  106.  
  107. checkoutThePlace:
  108. IF moves(i).x + .5 * gSize >= 0 AND moves(i).x + .5 * gSize < _WIDTH THEN
  109.     IF VS(moves(i).x + .5 * gSize, moves(i).y) = 1 THEN
  110.         mItem.x = moves(i).x + gSize: mItem.y = moves(i).y
  111.         sAppend moves(), mItem
  112.         VS(moves(i).x + .5 * gSize, moves(i).y) = 0
  113.     END IF
  114. IF moves(i).y + .5 * gSize >= 0 AND moves(i).y + .5 * gSize < _HEIGHT THEN
  115.     IF VS(moves(i).x, moves(i).y + .5 * gSize) = 1 THEN
  116.         mItem.x = moves(i).x: mItem.y = moves(i).y + gSize
  117.         sAppend moves(), mItem
  118.         VS(moves(i).x, moves(i).y + .5 * gSize) = 0
  119.     END IF
  120. IF moves(i).x - .5 * gSize >= 0 AND moves(i).x - .5 * gSize < _WIDTH THEN
  121.     IF VS(moves(i).x - .5 * gSize, moves(i).y) = 1 THEN
  122.         mItem.x = moves(i).x - gSize: mItem.y = moves(i).y
  123.         sAppend moves(), mItem
  124.         VS(moves(i).x - .5 * gSize, moves(i).y) = 0
  125.     END IF
  126. IF moves(i).y - .5 * gSize >= 0 AND moves(i).y - .5 * gSize < _HEIGHT THEN
  127.     IF VS(moves(i).x, moves(i).y - .5 * gSize) = 1 THEN
  128.         mItem.x = moves(i).x: mItem.y = moves(i).y - gSize
  129.         sAppend moves(), mItem
  130.         VS(moves(i).x, moves(i).y - .5 * gSize) = 0
  131.     END IF
  132.  
  133. SUB meander2 (x1, y1, x2, y2) ' snap to grid!   gSize is shared
  134.     startx = x1: starty = y1: endx = x2: endy = y2
  135.     x = startx: y = starty
  136.     GOSUB dist
  137.     IF dist > 100 THEN
  138.         time = INT(RND * 8 + 4) ' total amount allowed to move  The More the time the more the meander!!!!
  139.     ELSE
  140.         time = 3
  141.     END IF
  142.     startTime = time '       > 20 is too much!!
  143.     IF RND < .5 THEN lastmoveX = 0 ELSE lastmoveX = -1
  144.     lastx = startx: lasty = starty
  145.     DO
  146.         GOSUB dist
  147.         IF RND < .5 THEN d = -1 ELSE d = 1
  148.         IF lastmoveX = 0 THEN
  149.             lastx = x
  150.             IF time <= 2 THEN
  151.                 x = endx
  152.             ELSE
  153.                 dx = units(d * (.4 * distx * RND + gSize), gSize)
  154.                 IF dx = 0 THEN dx = gSize
  155.                 IF x + dx > 0 AND x + dx < _WIDTH THEN
  156.                     x = x + dx
  157.                 ELSE
  158.                     x = x + -dx
  159.                 END IF
  160.             END IF
  161.             'LINE (lastx, y)-(x, y)
  162.             beeline lastx, y, x, y
  163.             lastmoveX = -1
  164.         ELSE
  165.             lasty = y
  166.             IF time <= 2 THEN
  167.                 y = endy
  168.             ELSE
  169.                 dy = units(d * (.3 * disty * RND + gSize), gSize)
  170.                 IF dy = 0 THEN dy = gSize
  171.                 IF y + dy > 0 AND y + dy < _HEIGHT THEN
  172.                     y = y + dy
  173.                 ELSE
  174.                     y = y + -dy
  175.                 END IF
  176.             END IF
  177.             'LINE (x, lasty)-(x, y)
  178.             beeline x, lasty, x, y
  179.             lastmoveX = 0
  180.         END IF
  181.         time = time - 1
  182.         '_LIMIT 10
  183.     LOOP UNTIL time <= 0
  184.     EXIT SUB
  185.     dist:
  186.     distx = endx - x: disty = endy - y
  187.     RETURN
  188.  
  189. SUB fcirc (CX AS INTEGER, CY AS INTEGER, R AS INTEGER, C AS _UNSIGNED LONG)
  190.     DIM Radius AS INTEGER, RadiusError AS INTEGER
  191.     DIM X AS INTEGER, Y AS INTEGER
  192.     Radius = ABS(R): RadiusError = -Radius: X = Radius: Y = 0
  193.     IF Radius = 0 THEN PSET (CX, CY), C: EXIT SUB
  194.     LINE (CX - X, CY)-(CX + X, CY), C, BF
  195.     WHILE X > Y
  196.         RadiusError = RadiusError + Y * 2 + 1
  197.         IF RadiusError >= 0 THEN
  198.             IF X <> Y + 1 THEN
  199.                 LINE (CX - Y, CY - X)-(CX + Y, CY - X), C, BF
  200.                 LINE (CX - Y, CY + X)-(CX + Y, CY + X), C, BF
  201.             END IF
  202.             X = X - 1
  203.             RadiusError = RadiusError - X * 2
  204.         END IF
  205.         Y = Y + 1
  206.         LINE (CX - X, CY - Y)-(CX + X, CY - Y), C, BF
  207.         LINE (CX - X, CY + Y)-(CX + X, CY + Y), C, BF
  208.     WEND
  209.  
  210. SUB beeline (x1, y1, x2, y2)
  211.     IF x1 = x2 THEN
  212.         IF y1 <= y2 THEN FOR y = y1 TO y2: fcirc x1, y, 1, beeLineK: VS(INT(x1), INT(y)) = 1: NEXT
  213.         IF y1 > y2 THEN FOR y = y1 TO y2 STEP -1: fcirc x1, y, 1, beeLineK: VS(INT(x1), INT(y)) = 1: NEXT
  214.     ELSE
  215.         IF x1 <= x2 THEN FOR x = x1 TO x2: fcirc x, y1, 1, beeLineK: VS(INT(x), INT(y1)) = 1: NEXT
  216.         IF x1 > x2 THEN FOR x = x1 TO x2 STEP -1: fcirc x, y1, 1, beeLineK: VS(INT(x), INT(y1)) = 1: NEXT
  217.     END IF
  218.  
  219.     IF _RED32(K) >= _GREEN32(K) AND _RED32(K) >= _BLUE32(K) THEN maxC = 1: EXIT FUNCTION
  220.     IF _GREEN32(K) >= _BLUE(K) THEN maxC = 2 ELSE maxC = 3
  221.  
  222. ' this sub needs FUNCTION units (x, unit)
  223. SUB drawGrid (x1, y1, x2, y2, gsize, gridClr AS _UNSIGNED LONG) ' grid of square gsize X gsize
  224.     ' fit a grid between x1, x2 and  y1, y2
  225.     ' x1, y1 top right corner and x2, y2 expected bottom right corner of boundary line
  226.  
  227.     DIM x AS INTEGER, y AS INTEGER, gx1 AS INTEGER, gy1 AS INTEGER, gx2 AS INTEGER, gy2 AS INTEGER
  228.     gx1 = units(x1, gsize): gy1 = units(y1, gsize) 'convert to grid coordinates
  229.     gx2 = units(x2, gsize): gy2 = units(y2, gsize)
  230.     IF gx1 < x1 THEN gx1 = gx1 + gsize 'stay inside boundarys passed to sub
  231.     IF gy1 < y1 THEN gy1 = gy1 + gsize
  232.     IF gx1 >= gx2 OR gy1 >= gy2 THEN EXIT SUB 'that's not even a single square!
  233.     FOR x = gx1 TO gx2 STEP gsize: LINE (x, gy1)-(x, gy2), gridClr: NEXT
  234.     FOR y = gy1 TO gy2 STEP gsize: LINE (gx1, y)-(gx2, y), gridClr: NEXT
  235.  
  236. FUNCTION units (x, unit)
  237.     units = INT(x / unit) * unit
  238.  
  239. SUB sAppend (arr() AS move, addItem AS move)
  240.     REDIM _PRESERVE arr(LBOUND(arr) TO UBOUND(arr) + 1) AS move
  241.     arr(UBOUND(arr)) = addItem
  242.  
  243.  

BTW the beep is to remind you to hit the spacebar.
« Last Edit: September 19, 2020, 12:46:57 am by bplus »