Author Topic: Labyrinth Tiles  (Read 9918 times)

0 Members and 1 Guest are viewing this topic.

This topic contains a post which is marked as Best Answer. Press here if you would like to see it.

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Labyrinth Tiles
« on: January 16, 2021, 10:37:37 am »
Here is something I found interesting Thursday night, Labyrinth Tiles:
Code: QB64: [Select]
  1. _TITLE "Labyrinth Tile, spacebar for random tiling escape for Tile Design" 'b+ 2021-01-15
  2.  
  3. CONST Xmax = 700, Ymax = 700
  4. SCREEN _NEWIMAGE(Xmax, Ymax, 32)
  5. _DELAY .25
  6.  
  7.  
  8. makeTileImageLeft
  9. 'TileLeft 100, 100
  10. 'TileRight 0, 100
  11.  
  12. makeTileImageUp
  13. 'TileUp 100, 0
  14. 'TileDown 100, 99
  15. 'TileDown 100, 199
  16.  
  17.     CLS
  18.     FOR y = 0 TO Ymax STEP 100
  19.         FOR x = 0 TO Xmax STEP 100
  20.             r = RND
  21.             IF r < .25 THEN
  22.                 TileLeft x, y
  23.             ELSEIF r < .5 THEN
  24.                 TileDown x, y
  25.             ELSEIF r < .75 THEN
  26.                 TileRight x, y
  27.             ELSE
  28.                 TileUp x, y
  29.             END IF
  30.         NEXT
  31.     NEXT
  32.     _DISPLAY
  33.     SLEEP
  34.  
  35. ' can we make some designs?
  36. _TITLE "Labyrinth Tile, a Tile Design, Spacebar to Click your own Design"
  37. FOR y = 0 TO 7
  38.     FOR x = 0 TO 7
  39.         IF y MOD 4 = 0 OR y MOD 4 = 2 THEN
  40.             IF x MOD 4 = 0 OR x MOD 4 = 2 THEN
  41.                 TileLeft x * 100, y * 100
  42.             ELSEIF x MOD 4 = 1 OR x MOD 4 = 3 THEN
  43.                 TileRight x * 100, y * 100
  44.             END IF
  45.         ELSEIF y MOD 4 = 1 THEN
  46.             IF x MOD 4 = 0 THEN
  47.                 TileDown x * 100, y * 100
  48.             ELSEIF x MOD 4 = 2 THEN
  49.                 TileUp x * 100, y * 100
  50.             ELSEIF x MOD 4 = 1 THEN
  51.                 TileDown x * 100, y * 100
  52.             ELSEIF x MOD 4 = 3 THEN
  53.                 TileUp x * 100, y * 100
  54.             END IF
  55.         ELSEIF y MOD 4 = 3 THEN
  56.             IF x MOD 4 = 0 THEN
  57.                 TileUp x * 100, y * 100
  58.             ELSEIF x MOD 4 = 2 THEN
  59.                 TileDown x * 100, y * 100
  60.             ELSEIF x MOD 4 = 1 THEN
  61.                 TileUp x * 100, y * 100
  62.             ELSEIF x MOD 4 = 3 THEN
  63.                 TileDown x * 100, y * 100
  64.             END IF
  65.         END IF
  66.     NEXT
  67.  
  68.  
  69. _TITLE "Labyrinth Tile, Click tile to turn it, escape to quit..."
  70. REDIM t(7, 7) AS LONG
  71. FOR y = 0 TO 7
  72.     FOR x = 0 TO 7
  73.         t(x, y) = INT(RND * 4)
  74.     NEXT
  75.     CLS
  76.     FOR y = 0 TO 7
  77.         FOR x = 0 TO 7
  78.             SELECT CASE t(x, y)
  79.                 CASE 0: TileRight x * 100, y * 100
  80.                 CASE 1: TileDown x * 100, y * 100
  81.                 CASE 2: TileLeft x * 100, y * 100
  82.                 CASE 3: TileUp x * 100, y * 100
  83.             END SELECT
  84.         NEXT
  85.     NEXT
  86.     mb = _MOUSEBUTTON(1): mx = INT(_MOUSEX / 100): my = INT(_MOUSEY / 100)
  87.     LINE (mx * 100, my * 100)-STEP(100, 100), , B
  88.     IF mb THEN
  89.         IF mx >= 0 AND mx <= 7 AND my >= 0 AND my <= 7 THEN
  90.             t(mx, my) = (t(mx, my) + 1) MOD 4
  91.             PRINT mx, my
  92.             _DELAY .25
  93.         END IF
  94.     END IF
  95.     _DISPLAY
  96.     _LIMIT 100
  97.  
  98.  
  99. SUB TileLeft (x, y)
  100.     _PUTIMAGE (x, y), TL, 0
  101. SUB TileRight (x, y)
  102.     _PUTIMAGE (x, y), TL, 0, (100, 0)-(0, 100)
  103. SUB TileUp (x, y)
  104.     _PUTIMAGE (x, y), TU, 0
  105. SUB TileDown (x, y)
  106.     _PUTIMAGE (x, y), TU, 0, (0, 100)-(100, 0)
  107.  
  108. SUB makeTileImageLeft ()
  109.     s2 = 50 * SQR(2) + .51
  110.     TL = _NEWIMAGE(100, 100, 32)
  111.     _DEST TL
  112.     FOR x = 10 TO 130 STEP 20
  113.         x1 = x + s2 * COS(_PI(3 / 4))
  114.         y1 = s2 * SIN(_PI(3 / 4))
  115.         x2 = x + s2 * COS(_PI(5 / 4))
  116.         y2 = 100 + s2 * SIN(_PI(5 / 4))
  117.         LINE (x, 0)-(x1, y1)
  118.         LINE (x, 100)-(x2, y2)
  119.     NEXT
  120.     'LINE (0, 0)-STEP(99, 99), , B
  121.     _DEST 0
  122.  
  123. SUB makeTileImageUp ()
  124.     s2 = 50 * SQR(2) + .51
  125.     TU = _NEWIMAGE(100, 100, 32)
  126.     _DEST TU
  127.     FOR y = 10 TO 130 STEP 20
  128.         x1 = s2 * COS(_PI(7 / 4))
  129.         y1 = y + s2 * SIN(_PI(7 / 4))
  130.         x2 = 100 + s2 * COS(_PI(5 / 4))
  131.         y2 = y + s2 * SIN(_PI(5 / 4))
  132.         LINE (0, y)-(x1, y1)
  133.         LINE (100, y)-(x2, y2)
  134.     NEXT
  135.     'LINE (0, 0)-STEP(99, 99), , B
  136.     _DEST 0
  137.  
  138.  
  139.  

Here is design I clicked up today:
 
Labyrinth Click a pattern.PNG


Couldn't figure out how to get rid of that one pesky pixel hole set. Maybe one last try with Rotozoom...
« Last Edit: January 16, 2021, 10:41:54 am by bplus »

Offline Pete

  • Forum Resident
  • Posts: 2361
  • Cuz I sez so, varmint!
    • View Profile
Re: Labyrinth Tiles
« Reply #1 on: January 16, 2021, 10:51:17 am »
Is it available in oak or walnut? Reminds me of Parkay floor tiles.

Pete
Want to learn how to write code on cave walls? https://www.tapatalk.com/groups/qbasic/qbasic-f1/

FellippeHeitor

  • Guest
Re: Labyrinth Tiles
« Reply #2 on: January 16, 2021, 10:52:59 am »
Neat! Kind of like:

Quote from: Commodore 64
10 PRINT CHR$(205.5+RND(1)); : GOTO 10

For the old Commodore.

 
the_ppg256_article_image.png
« Last Edit: January 16, 2021, 10:57:08 am by FellippeHeitor »

Offline Pete

  • Forum Resident
  • Posts: 2361
  • Cuz I sez so, varmint!
    • View Profile
Re: Labyrinth Tiles
« Reply #3 on: January 16, 2021, 11:11:13 am »
Is that available in 64 and 128? Oh well, lucky for me, I was an Atari guy. We just had plain old black screens. You know... like SCREEN Zero. The way God intended it.

Pete

Want to learn how to write code on cave walls? https://www.tapatalk.com/groups/qbasic/qbasic-f1/

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Labyrinth Tiles
« Reply #4 on: January 16, 2021, 11:23:57 am »
Is it available in oak or walnut? Reminds me of Parkay floor tiles.

Pete

Actually it was Old Moses Chess board that had me thinking about tiles. :)

I started thinking about mazes that might turn after a player passes so there is no going back.

Yeah @FellippeHeitor  I remember that! Alas, these tiles don't make very good mazes.

Too bad Rotozoom can not translate a straight line! it has the gaps between tiles more than filled:
Code: QB64: [Select]
  1. _TITLE "Labyrinth Tile, spacebar for random tiling escape for Tile Design" 'b+ 2021-01-15
  2.  
  3. CONST Xmax = 700, Ymax = 700
  4. SCREEN _NEWIMAGE(Xmax, Ymax, 32)
  5. _DELAY .25
  6.  
  7.  
  8. makeTileImageUp
  9.  
  10.     CLS
  11.     FOR y = 0 TO Ymax STEP 100
  12.         FOR x = 0 TO Xmax STEP 100
  13.             r = RND
  14.             IF r < .25 THEN
  15.                 TileLeft x, y
  16.             ELSEIF r < .5 THEN
  17.                 TileDown x, y
  18.             ELSEIF r < .75 THEN
  19.                 TileRight x, y
  20.             ELSE
  21.                 TileUp x, y
  22.             END IF
  23.         NEXT
  24.     NEXT
  25.     _DISPLAY
  26.     SLEEP
  27.  
  28. ' can we make some designs?
  29. _TITLE "Labyrinth Tile, a Tile Design, Spacebar to Click your own Design"
  30. FOR y = 0 TO 7
  31.     FOR x = 0 TO 7
  32.         IF y MOD 4 = 0 OR y MOD 4 = 2 THEN
  33.             IF x MOD 4 = 0 OR x MOD 4 = 2 THEN
  34.                 TileLeft x * 100, y * 100
  35.             ELSEIF x MOD 4 = 1 OR x MOD 4 = 3 THEN
  36.                 TileRight x * 100, y * 100
  37.             END IF
  38.         ELSEIF y MOD 4 = 1 THEN
  39.             IF x MOD 4 = 0 THEN
  40.                 TileDown x * 100, y * 100
  41.             ELSEIF x MOD 4 = 2 THEN
  42.                 TileUp x * 100, y * 100
  43.             ELSEIF x MOD 4 = 1 THEN
  44.                 TileDown x * 100, y * 100
  45.             ELSEIF x MOD 4 = 3 THEN
  46.                 TileUp x * 100, y * 100
  47.             END IF
  48.         ELSEIF y MOD 4 = 3 THEN
  49.             IF x MOD 4 = 0 THEN
  50.                 TileUp x * 100, y * 100
  51.             ELSEIF x MOD 4 = 2 THEN
  52.                 TileDown x * 100, y * 100
  53.             ELSEIF x MOD 4 = 1 THEN
  54.                 TileUp x * 100, y * 100
  55.             ELSEIF x MOD 4 = 3 THEN
  56.                 TileDown x * 100, y * 100
  57.             END IF
  58.         END IF
  59.     NEXT
  60.  
  61.  
  62. _TITLE "Labyrinth Tile, Click tile to turn it, escape to quit..."
  63. REDIM t(7, 7) AS LONG
  64. FOR y = 0 TO 7
  65.     FOR x = 0 TO 7
  66.         t(x, y) = INT(RND * 4)
  67.     NEXT
  68.     CLS
  69.     FOR y = 0 TO 7
  70.         FOR x = 0 TO 7
  71.             SELECT CASE t(x, y)
  72.                 CASE 0: TileRight x * 100, y * 100
  73.                 CASE 1: TileDown x * 100, y * 100
  74.                 CASE 2: TileLeft x * 100, y * 100
  75.                 CASE 3: TileUp x * 100, y * 100
  76.             END SELECT
  77.         NEXT
  78.     NEXT
  79.     mb = _MOUSEBUTTON(1): mx = INT(_MOUSEX / 100): my = INT(_MOUSEY / 100)
  80.     LINE (mx * 100, my * 100)-STEP(100, 100), , B
  81.     IF mb THEN
  82.         IF mx >= 0 AND mx <= 7 AND my >= 0 AND my <= 7 THEN
  83.             t(mx, my) = (t(mx, my) + 1) MOD 4
  84.             PRINT mx, my
  85.             _DELAY .25
  86.         END IF
  87.     END IF
  88.     _DISPLAY
  89.     _LIMIT 100
  90.  
  91.  
  92. SUB TileLeft (x, y)
  93.     RotoZoom x + 50, y + 50, TU, 1, 270
  94. SUB TileRight (x, y)
  95.     RotoZoom x + 50, y + 50, TU, 1, 90
  96. SUB TileUp (x, y)
  97.     RotoZoom x + 50, y + 50, TU, 1, 0
  98. SUB TileDown (x, y)
  99.     RotoZoom x + 50, y + 50, TU, 1, 180
  100.  
  101. SUB makeTileImageUp ()
  102.     s2 = 50 * SQR(2)
  103.     TU = _NEWIMAGE(100, 100, 32)
  104.     _DEST TU
  105.     FOR y = 10 TO 130 STEP 20
  106.         x1 = s2 * COS(_PI(7 / 4))
  107.         y1 = y + s2 * SIN(_PI(7 / 4))
  108.         x2 = 100 + s2 * COS(_PI(5 / 4))
  109.         y2 = y + s2 * SIN(_PI(5 / 4))
  110.         LINE (0, y)-(x1, y1)
  111.         LINE (99, y)-(x2, y2)
  112.     NEXT
  113.     'LINE (0, 0)-STEP(99, 99), , B
  114.     _DEST 0
  115.  
  116. SUB RotoZoom (X AS LONG, Y AS LONG, Image AS LONG, Scale AS SINGLE, degreesRotation AS SINGLE)
  117.     DIM px(3) AS SINGLE, py(3) AS SINGLE, W&, H&, sinr!, cosr!, i&, x2&, y2&
  118.     W& = _WIDTH(Image&): H& = _HEIGHT(Image&)
  119.     px(0) = -W& / 2: py(0) = -H& / 2: px(1) = -W& / 2: py(1) = H& / 2
  120.     px(2) = W& / 2: py(2) = H& / 2: px(3) = W& / 2: py(3) = -H& / 2
  121.     sinr! = SIN(-degreesRotation / 57.2957795131): cosr! = COS(-degreesRotation / 57.2957795131)
  122.     FOR i& = 0 TO 3
  123.         x2& = (px(i&) * cosr! + sinr! * py(i&)) * Scale + X: y2& = (py(i&) * cosr! - px(i&) * sinr!) * Scale + Y
  124.         px(i&) = x2&: py(i&) = y2&
  125.     NEXT
  126.     _MAPTRIANGLE (0, 0)-(0, H& - 1)-(W& - 1, H& - 1), Image& TO(px(0), py(0))-(px(1), py(1))-(px(2), py(2))
  127.     _MAPTRIANGLE (0, 0)-(W& - 1, 0)-(W& - 1, H& - 1), Image& TO(px(0), py(0))-(px(3), py(3))-(px(2), py(2))
  128.  
  129.  
« Last Edit: January 16, 2021, 11:33:29 am by bplus »

Offline Richard Frost

  • Seasoned Forum Regular
  • Posts: 316
  • Needle nardle noo. - Peter Sellers
    • View Profile
Re: Labyrinth Tiles
« Reply #5 on: January 16, 2021, 02:49:47 pm »
TILE: Totally Insane Line Excursions

Code: QB64: [Select]
  1. _TITLE "Truchet Tiling, SciAm Jul89 pg 111"
  2. DEFINT A-Z
  3. DIM a(1000)
  4. s = 18: xm = 800 / s: ym = 600 / s: z = (800 - ((xm - 2) * s)) / 2
  5. SCREEN _NEWIMAGE(800, 600, 12)
  6. FOR i = 0 TO 1 '             create tiles (just 2)
  7.     FOR j = 0 TO 1
  8.         FOR a = 0 TO 90
  9.             r! = _D2R(a + j * 180)
  10.             FOR q = -1 TO 1
  11.                 x = j * s + ((s \ 2) + q) * COS(r!)
  12.                 y = j * s + ((s \ 2) + q) * SIN(r!)
  13.                 IF i THEN y = s - y
  14.                 PSET (x, y), 1
  15.             NEXT q
  16.         NEXT a
  17.     NEXT j
  18.     GET (0, 0)-(s, s), a(i * 500)
  19.     CLS
  20.  
  21. DO: _LIMIT 2 '               display tiles
  22.     FOR i = 0 TO xm - 3
  23.         FOR j = 0 TO ym - 3
  24.             xs = i * s + z
  25.             ys = j * s + z
  26.             PUT (xs, ys), a(INT(RND * 2) * 500), PSET
  27.         NEXT j
  28.     NEXT i
  29.     LINE (z, z)-((xm - 2) * s + z, (ym - 2) * s + z), 1, B
  30.     _DISPLAY
truchet.png
* truchet.png (Filesize: 35.71 KB, Dimensions: 752x504, Views: 170)
It works better if you plug it in.

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Labyrinth Tiles
« Reply #6 on: January 16, 2021, 03:57:38 pm »
Yeah for 2 Tiler System!

Code: QB64: [Select]
  1. _TITLE "2 Tiler press any for next, esc to quit" 'b+ 2021-01-16
  2.  
  3. CONST Xmax = 700, Ymax = 700, s = 10, sd2 = 5
  4. SCREEN _NEWIMAGE(Xmax, Ymax, 32)
  5. _DELAY .25
  6.     CLS
  7.     FOR y = 0 TO Ymax STEP s
  8.         FOR x = 0 TO Xmax STEP s
  9.             IF RND < .5 THEN t1 x, y ELSE t2 x, y
  10.         NEXT
  11.     NEXT
  12.     FOR x = 1 TO 100
  13.         PAINT (RND * Xmax, RND * Ymax), _RGB32(RND * 255, RND * 255, RND * 254), &HFFFFFFFF
  14.         _LIMIT 30
  15.     NEXT
  16.     ' _DISPLAY
  17.     SLEEP
  18.  
  19. SUB t1 (x, y)
  20.     LINE (x + sd2, y)-(x, y + sd2)
  21.     LINE (x + s, y + sd2)-(x + sd2, y + s)
  22.  
  23. SUB t2 (x, y)
  24.     LINE (x + sd2, y)-(x + s, y + sd2)
  25.     LINE (x, y + sd2)-(x + sd2, y + s)
  26.  
  27.  

 
2 Tiler System.PNG

Offline Richard Frost

  • Seasoned Forum Regular
  • Posts: 316
  • Needle nardle noo. - Peter Sellers
    • View Profile
Re: Labyrinth Tiles
« Reply #7 on: January 16, 2021, 08:17:16 pm »
What a gem - endless beauty from 26 lines of code, 25 since
the _DELAY should not be required.  I likes de foist one too.
It works better if you plug it in.

Offline johannhowitzer

  • Forum Regular
  • Posts: 118
    • View Profile
Re: Labyrinth Tiles
« Reply #8 on: January 17, 2021, 07:51:33 am »
Got inspired, so I pared this down to 16 lines, 15 if you don't care about the constants and just put their values in-line.  STEP is used to turn the two SUBs into three lines of code... r is set to 1 or -1, and then that's used to flip the result of the STEPs horizontally.  Thanks bplus!  That was really fun.

Code: QB64: [Select]
  1. const w = 700, s = 5
  2. screen _newimage(w, w, 32)
  3.    cls
  4.    for y = 0 to w step s * 2
  5.       for x = 0 to w step s * 2
  6.          r = ((int(rnd * 2)) * 2) - 1
  7.          line(x + s, y)-step(s * r, s)
  8.          line(x + s, y + (s * 2))-step(-s * r, -s)
  9.       next
  10.    next
  11.    for x = 1 to 100
  12.       paint(rnd * w, rnd * w), _rgb32(rnd * 255, rnd * 255, rnd * 254), &HFFFFFFFF
  13.    next
  14.    sleep
« Last Edit: January 17, 2021, 08:16:26 am by johannhowitzer »

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Labyrinth Tiles
« Reply #9 on: January 17, 2021, 11:04:19 am »
Thanks Richard Frost, I am delighted we enjoy simple things.

Nice @johannhowitzer, 2 tile Subs down to 2 lines!

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Labyrinth Tiles
« Reply #10 on: January 17, 2021, 07:11:36 pm »
Take a walk amongst the tiles with keypad, diagonals burn bridges, up, down left right jumps corners and spacebar reverses all your neighbors! Just follow the yellow brick road!

Code: QB64: [Select]
  1. _TITLE "Walk amongst the 2 Tilers: USE KEYPAD  Diagonal keys 7,9,3,1 burns bridges, 8,6,2,4 jumps corners, spacebar reverses neighbors" 'b+ 2021-01-17
  2. CONST Xmax = 1000, Ymax = 700, S = 20, Sd2 = S \ 2, Xcells = Xmax \ S, Ycells = Ymax \ S
  3. SCREEN _NEWIMAGE(Xmax, Ymax, 32): _DELAY .25: _SCREENMOVE _MIDDLE
  4. REDIM TS(Xcells, Ycells) AS LONG
  5. FOR y = 0 TO Ycells
  6.     FOR x = 0 TO Xcells
  7.         TS(x, y) = INT(RND * 2)
  8.     NEXT
  9. bx = Xcells \ 2: by = Ycells \ 2
  10.     CLS
  11.     FOR y = 0 TO Ycells
  12.         FOR x = 0 TO Xcells
  13.             IF TS(x, y) THEN t1 x * S, y * S ELSE t2 x * S, y * S
  14.         NEXT
  15.     NEXT
  16.     drawBplusPath bx, by
  17.     numLock = _KEYDOWN(100300)
  18.     KH& = _KEYHIT
  19.  
  20.     ' go diagonally if the target block is same as current                    and burn bridges as you go!
  21.     IF KH& = 18176 OR (numLock AND (KH& = 55)) THEN 'up, left number 7
  22.         IF bx - 1 >= 0 AND by - 1 >= 0 THEN
  23.             IF TS(bx, by) = TS(bx - 1, by - 1) THEN
  24.                 TS(bx, by) = (TS(bx, by) + 1) MOD 2
  25.                 bx = bx - 1: by = by - 1
  26.             END IF
  27.         END IF
  28.     ELSEIF KH& = 18688 OR (numLock AND (KH& = 57)) THEN ' up, right   number 9
  29.         IF bx + 1 < Xcells AND by - 1 >= 0 THEN
  30.             IF TS(bx, by) = TS(bx + 1, by - 1) THEN
  31.                 TS(bx, by) = (TS(bx, by) + 1) MOD 2
  32.                 bx = bx + 1: by = by - 1
  33.             END IF
  34.         END IF
  35.     ELSEIF KH& = 20736 OR (numLock AND (KH& = 51)) THEN ' down right number 3
  36.         IF bx + 1 < Xcells AND by + 1 < Ycells THEN
  37.             IF TS(bx, by) = TS(bx + 1, by + 1) THEN
  38.                 TS(bx, by) = (TS(bx, by) + 1) MOD 2
  39.                 bx = bx + 1: by = by + 1
  40.             END IF
  41.         END IF
  42.     ELSEIF KH& = 20224 OR (numLock AND (KH& = 49)) THEN ' down left number 1
  43.         IF bx - 1 >= 0 AND by + 1 < Ycells THEN
  44.             IF TS(bx, by) = TS(bx - 1, by + 1) THEN
  45.                 TS(bx, by) = (TS(bx, by) + 1) MOD 2
  46.                 bx = bx - 1: by = by + 1
  47.             END IF
  48.         END IF
  49.  
  50.         '                          ' go up down left right for cornering
  51.     ELSEIF KH& = 18432 OR (numLock AND (KH& = 56)) THEN 'up
  52.         IF by - 1 >= 0 THEN
  53.             IF TS(bx, by) <> TS(bx, by - 1) THEN
  54.                 by = by - 1
  55.             END IF
  56.         END IF
  57.     ELSEIF KH& = 19712 OR (numLock AND (KH& = 54)) THEN 'right
  58.         IF bx + 1 < Xcells THEN
  59.             IF TS(bx, by) <> TS(bx + 1, by) THEN
  60.                 bx = bx + 1
  61.             END IF
  62.         END IF
  63.     ELSEIF KH& = 20480 OR (numLock AND (KH& = 50)) THEN 'down
  64.         IF by + 1 < Ycells THEN
  65.             IF TS(bx, by) <> TS(bx, by + 1) THEN
  66.                 by = by + 1
  67.             END IF
  68.         END IF
  69.  
  70.     ELSEIF KH& = 19200 OR (numLock AND (KH& = 52)) THEN 'left
  71.         IF bx - 1 >= 0 THEN
  72.             IF TS(bx, by) <> TS(bx - 1, by) THEN
  73.                 bx = bx - 1
  74.             END IF
  75.         END IF
  76.     ELSEIF KH& = 32 THEN 'space bar, reverse your neighbors!
  77.         FOR y = -1 TO 1
  78.             FOR x = -1 TO 1
  79.                 IF bx + x >= 0 AND bx + x < Xcells THEN
  80.                     IF by + y >= 0 AND by + y < Ycells THEN
  81.                         IF NOT (x = 0 AND y = 0) THEN
  82.                             TS(bx + x, by + y) = (TS(bx + x, by + y) + 1) MOD 2
  83.                         END IF
  84.                     END IF
  85.                 END IF
  86.             NEXT
  87.         NEXT
  88.     END IF
  89.     _DISPLAY
  90.     _LIMIT 30
  91.  
  92.  
  93. SUB t1 (x, y)
  94.     LINE (x + Sd2, y)-(x, y + Sd2), &HFF006600
  95.     LINE (x + S, y + Sd2)-(x + Sd2, y + S), &HFF006600
  96.     'LINE (x, y)-STEP(S, S), &HFFFFFFFF, B
  97.  
  98. SUB t2 (x, y)
  99.     LINE (x + Sd2, y)-(x + S, y + Sd2), &HFF006600
  100.     LINE (x, y + Sd2)-(x + Sd2, y + S), &HFF006600
  101.     'LINE (x, y)-STEP(S, S), &HFFFFFFFF, B
  102.  
  103. SUB drawBplusPath (x, y)
  104.     'CIRCLE (x * S + Sd2, y * S + Sd2), 2, &HFF006600
  105.     PAINT (x * S + Sd2, y * S + Sd2), &HFFFFFF00, &HFF006600
  106.     FOR r = 0 TO 6 STEP .25
  107.         CIRCLE (x * S + Sd2, y * S + Sd2), r, &HFF0000FF
  108.     NEXT
  109.     COLOR , &H00000000
  110.     _PRINTSTRING (x * S + Sd2 - 4, y * S + Sd2 - 7), "B"
  111.     COLOR , &HFF000000
  112.  
  113.  
  114.  

 
Walk amongst.PNG






« Last Edit: January 17, 2021, 07:22:14 pm by bplus »

Offline johannhowitzer

  • Forum Regular
  • Posts: 118
    • View Profile
Re: Labyrinth Tiles
« Reply #11 on: January 18, 2021, 03:15:05 am »
Thanks Richard Frost, I am delighted we enjoy simple things.

Nice @johannhowitzer, 2 tile Subs down to 2 lines!
mathematical.gif

Offline NOVARSEG

  • Forum Resident
  • Posts: 509
    • View Profile
Re: Labyrinth Tiles
« Reply #12 on: January 19, 2021, 11:02:43 pm »
A variation with 2 lines of code.

How it works I don't know

working on a horizontal code so objects can move around the grid with arrow keys

Code: QB64: [Select]
  1. s = 5
  2. w = 700
  3.  
  4. SCREEN _NEWIMAGE(w, w, 32)
  5.  
  6.  
  7.     CLS
  8.     IF INKEY$ = CHR$(27) THEN END
  9.     FOR y = 0 TO w STEP s * 2
  10.  
  11.         FOR x = 0 TO w STEP s * 2
  12.  
  13.             r = ((INT(RND * 2)) * 2) - 1 'returns  -1, 1
  14.  
  15.             LINE (x - s * r, y)-(x, y + s)
  16.             LINE (x + s * r, y)-(x, y - s)
  17.  
  18.         NEXT x
  19.  
  20.     NEXT y
  21.     SLEEP
  22.  
« Last Edit: January 20, 2021, 01:43:53 am by NOVARSEG »

Offline NOVARSEG

  • Forum Resident
  • Posts: 509
    • View Profile
Re: C Tiles
« Reply #13 on: January 22, 2021, 10:34:09 pm »
It is hard to explain how the code generates the labyrinth.

This code will show how the diagonal labyrinth is generated.

press space bar to see how it works.

It should be possible to generate a vertical/horizontal labyrinth in the same way. 

Code: QB64: [Select]
  1. s = 5
  2. w = 1024
  3. h = 768
  4.  
  5. SCREEN _NEWIMAGE(w, h, 32)
  6.  
  7.  
  8.     CLS
  9.     'IF INKEY$ = CHR$(27) THEN END
  10.     FOR y = 10 TO h STEP s * 2
  11.  
  12.         FOR x = 0 TO w STEP s * 2
  13.  
  14.             r = ((INT(RND * 2)) * 2) - 1 'returns  -1, 1
  15.  
  16.             LINE (x - s * r, y)-(x, y + s)
  17.             LINE (x + s * r, y)-(x, y - s)
  18.             DO
  19.                 I$ = INKEY$
  20.                 IF I$ = CHR$(27) THEN END
  21.                 IF I$ = CHR$(32) THEN EXIT DO
  22.             LOOP
  23.  
  24.         NEXT x
  25.  
  26.     NEXT y
  27.     SLEEP
  28.  
  29.  

Shows nice diagonal boxes if alternate 1, -1 are fed into the code

This gives an idea of how to generate a grid of horizontal / vertical boxes.

Code: QB64: [Select]
  1. s = 5
  2. w = 1024
  3. h = 768
  4. r = 1
  5. SCREEN _NEWIMAGE(w, h, 32)
  6.  
  7.  
  8.     CLS
  9.     'IF INKEY$ = CHR$(27) THEN END
  10.     FOR y = 10 TO h STEP s * 2
  11.  
  12.         FOR x = 0 TO w STEP s * 2
  13.  
  14.             'r = ((INT(RND * 2)) * 2) - 1 'returns  -1, 1
  15.  
  16.             IF r = 1 THEN r = -1: GOTO LL
  17.             IF r = -1 THEN r = 1: GOTO LL
  18.             ' r = 1
  19.  
  20.             LL:
  21.  
  22.             LINE (x - s * r, y)-(x, y + s)
  23.             LINE (x + s * r, y)-(x, y - s)
  24.  
  25.  
  26.             DO
  27.                 I$ = INKEY$
  28.                 IF I$ = CHR$(27) THEN END
  29.                 IF I$ = CHR$(32) THEN EXIT DO
  30.             LOOP
  31.  
  32.         NEXT x
  33.  
  34.     NEXT y
  35.     SLEEP
  36.  
  37.  

« Last Edit: January 22, 2021, 10:48:37 pm by NOVARSEG »

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Labyrinth Tiles
« Reply #14 on: January 23, 2021, 10:57:55 am »
Quote
This gives an idea of how to generate a grid of horizontal / vertical boxes.

Here is another way to see how 2 simple lines on 2 different tiles can make the "maze" by drawing the tile outlines.
Code: QB64: [Select]
  1. CONST w = 700, s = 20
  2. SCREEN _NEWIMAGE(w, w, 32)
  3.  
  4. FOR y = 0 TO w STEP s * 2
  5.     FOR x = 0 TO w STEP s * 2
  6.         r = ((INT(RND * 2)) * 2) - 1
  7.         LINE (x + s, y)-STEP(s * r, s)
  8.         LINE (x + s, y + (s * 2))-STEP(-s * r, -s)
  9.         LINE (x, y)-STEP(2 * s, 2 * s), , B
  10.     NEXT
  11.  

I did this to figure out how to move inside the "maze" with "arrow keys" on number pad
https://www.qb64.org/forum/index.php?topic=3498.msg128347#msg128347