Author Topic: Circular Maze Generator  (Read 1929 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 SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
Circular Maze Generator
« on: June 13, 2020, 07:35:15 pm »
Here's a circular maze generator I made today. I figured this kind might be easier to make and it was.. sorta. lol. The walls aren't the best but it's the best I know how to do. Tell me what you think and enjoy it. Also put it in its own folder to save mazes as bmp pictures. I might make a JPG version later on but I'm out of energy. lol You can make colorized versions or black and white (to print).
Attached is a color version I made. Oh also, you cannot print the colorized version because it would take too much ink or toner. I set it so it would be impossible to within the app itself.

- Deleted the code until I fix it...

* CircleMaze1.bmp (Filesize: 1.37 MB, Dimensions: 800x600, Views: 677)
« Last Edit: June 13, 2020, 08:24:56 pm by SierraKen »

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Circular Maze Generator
« Reply #1 on: June 13, 2020, 08:31:15 pm »
I fix your walls:
Code: QB64: [Select]
  1. 'Circular Mazes
  2. 'By Sierraken on June 13, 2020.  Mod B+ wall fix
  3. _LIMIT 300
  4. begin:
  5. _TITLE "Circular Maze Generator"
  6. picture& = _NEWIMAGE(800, 600, 32)
  7. PRINT "                         Circular Maze Generator"
  8. PRINT "                              by Sierraken"
  9. PRINT "This app will create random circular mazes like the kind you see using shrubs."
  10. PRINT "You can (s)ave a maze as .bmp and/or (p)rint a black and white version."
  11. 'PRINT: PRINT
  12. 'PRINT "Choose a difficulty:"
  13. 'PRINT "(1) Easy"
  14. 'PRINT "(2) Medium"
  15. 'PRINT "(3) Hard"
  16. 'PRINT
  17. 'INPUT "->"; dif
  18. dif = 3
  19. IF dif < 1 OR dif > 3 OR dif <> INT(dif) THEN GOTO begin:
  20. 'INPUT "Do you want (c)olor or (b)lack and white"; c$
  21. 'IF LEFT$(c$, 1) = "c" OR LEFT$(c$, 1) = "C" THEN col = 1: GOTO start:
  22. 'IF LEFT$(c$, 1) = "b" OR LEFT$(c$, 1) = "b" THEN col = 0: GOTO start:
  23. c$ = "b"
  24. 'GOTO begin:
  25. start:
  26. IF dif = 1 THEN circles = 4
  27. IF dif = 2 THEN circles = 8
  28. IF dif = 3 THEN circles = 12
  29. _TITLE "Space Bar to make new maze, (S)ave, (P)rint, Esc to quit."
  30. s& = _NEWIMAGE(800, 600, 32)
  31. SCREEN s&, picture&
  32. IF col = 0 THEN PAINT (1, 1), _RGB32(255, 255, 255)
  33. sz = 250
  34. x = 400: y = 300
  35. r2 = .25
  36. IF col = 1 THEN cc = 125
  37. IF col = 0 THEN cc = 0
  38. FOR cir = 1 TO circles
  39.     r1 = (RND * 5) + 1
  40.     IF cir > 10 THEN r2 = .5
  41.     IF col = 1 THEN cl = cir * 21
  42.     IF col = 0 THEN cl = cir
  43.     CIRCLE (x, y), sz, _RGB32(cc, cl, cc), r1, r1 - r2
  44.     _DELAY .25
  45.     IF dif = 1 THEN sz = sz - 26.67: wsz = 25.67
  46.     IF dif = 2 THEN sz = sz - 23.33: wsz = 22.33
  47.     IF dif = 3 THEN sz = sz - 20: wsz = 19
  48. NEXT cir
  49. sz = 250
  50. FOR wall = 1 TO circles - 1
  51.     ra = _PI(2) * RND
  52.     LINE (x + sz * COS(ra), y + sz * SIN(ra))-(x + (sz - 20) * COS(ra), y + (sz - 20) * SIN(ra)), _RGB32(0)
  53.     sz = sz - 20
  54.  
  55. 'FOR wall = 1 TO circles - 2
  56. '    go:
  57. '    xx = INT(RND * 800) + 1
  58. '    yy = INT(RND * 600) + 1
  59. '    IF col = 1 THEN cl2 = wall * 21
  60. '    IF col = 0 THEN cl2 = wall
  61. '    IF POINT(xx, yy) = _RGB32(cc, cl2, cc) THEN
  62. '        go2:
  63. '        IF xx > 400 THEN xx2 = xx - wsz: GOTO nex:
  64. '        IF xx < 400 THEN xx2 = xx + wsz
  65. '        nex:
  66. '        IF yy > 300 THEN yy2 = yy - wsz: GOTO nex2:
  67. '        IF yy < 300 THEN yy2 = yy + wsz: GOTO nex2:
  68. '        GOTO go2:
  69. '    END IF
  70. '    GOTO go:
  71. '    nex2:
  72. '    LINE (xx, yy)-(xx2, yy2), _RGB32(cc, cl2, cc)
  73. 'NEXT wall
  74. _PUTIMAGE , s&, picture&
  75. IF sav = 1 THEN SaveImage 0, nm$: sav = 0
  76.     a$ = INKEY$
  77.     IF a$ = CHR$(27) THEN END
  78.     IF a$ = " " THEN GOTO begin:
  79.     IF a$ = "p" OR a$ = "P" THEN
  80.         IF col = 0 THEN
  81.             j& = _COPYIMAGE(0)
  82.             _DELAY .25
  83.             INPUT "Print on printer (Y/N)?", i$ 'print screen page on printer
  84.             CLS
  85.             SCREEN j&
  86.             _DELAY .25
  87.             IF LEFT$(i$, 1) = "y" OR LEFT$(i$, 1) = "Y" THEN
  88.                 'printer prep (code copied and pasted from bplus Free Calendar Program)
  89.                 YMAX = _HEIGHT: XMAX = _WIDTH
  90.                 landscape& = _NEWIMAGE(YMAX, XMAX, 32)
  91.                 _MAPTRIANGLE (XMAX, 0)-(0, 0)-(0, YMAX), 0 TO(0, 0)-(0, XMAX)-(YMAX, XMAX), landscape&
  92.                 _MAPTRIANGLE (XMAX, 0)-(XMAX, YMAX)-(0, YMAX), 0 TO(0, 0)-(YMAX, 0)-(YMAX, XMAX), landscape&
  93.                 _PRINTIMAGE landscape&
  94.                 _DELAY 2
  95.                 landscape& = 0
  96.                 s& = j&
  97.             END IF
  98.         END IF
  99.     END IF
  100.     IF a$ = " " THEN GOTO start:
  101.     IF a$ = CHR$(27) THEN END
  102.     IF a$ = "S" OR a$ = "s" THEN GOTO saving:
  103.  
  104. saving:
  105. PRINT "                       Saving"
  106. PRINT "         Your bmp file will be saved in the"
  107. PRINT "         same directory as this program is."
  108. PRINT "         It can be used with almost any"
  109. PRINT "         other graphics program or website."
  110. PRINT "         It is saved using:"
  111. PRINT "         width: 800  height: 600 pixels."
  112. PRINT "         Type a name to save your picture"
  113. PRINT "         and press the Enter key. Do not"
  114. PRINT "         add .bmp at the end, the program"
  115. PRINT "         will do it automatically."
  116. PRINT "         Example: MyPic"
  117. PRINT "         Quit and Enter key ends program."
  118. INPUT "         ->"; nm$
  119. IF nm$ = "Quit" OR nm$ = "quit" OR nm$ = "QUIT" THEN END
  120. nm$ = nm$ + ".bmp"
  121. 'Checking to see if the file already exists on your computer.
  122. theFileExists = _FILEEXISTS(nm$)
  123. IF theFileExists = -1 THEN
  124.     PRINT
  125.     PRINT "       File Already Exists"
  126.     PRINT "       Saving will delete your old"
  127.     PRINT "       bmp picture."
  128.     PRINT "       Would you like to still do it?"
  129.     PRINT "      (Y/N)."
  130.     PRINT "      Esc goes to start screen."
  131.     llloop:
  132.     _LIMIT 100
  133.     ag2$ = INKEY$
  134.     IF ag2$ = CHR$(27) THEN GOTO start:
  135.     IF ag2$ = "" THEN GOTO llloop:
  136.     IF ag2$ = "y" OR ag$ = "Y" THEN
  137.         SHELL _HIDE "DEL " + nm$
  138.         GOTO saving2:
  139.     END IF
  140.     GOTO llloop:
  141. saving2:
  142. sav = 1
  143. FOR snd = 100 TO 700 STEP 100
  144.     SOUND snd, 2
  145. NEXT snd
  146. GOTO start:
  147.  
  148. 'Here is the SUB needed to save the image to BMP.
  149. SUB SaveImage (image AS LONG, filename AS STRING)
  150.     bytesperpixel& = _PIXELSIZE(image&)
  151.     IF bytesperpixel& = 0 THEN PRINT "Text modes unsupported!": END
  152.     IF bytesperpixel& = 1 THEN bpp& = 8 ELSE bpp& = 24
  153.     x& = _WIDTH(image&)
  154.     y& = _HEIGHT(image&)
  155.     b$ = "BM????QB64????" + MKL$(40) + MKL$(x&) + MKL$(y&) + MKI$(1) + MKI$(bpp&) + MKL$(0) + "????" + STRING$(16, 0) 'partial BMP header info(???? to be filled later)
  156.     IF bytesperpixel& = 1 THEN
  157.         FOR c& = 0 TO 255 ' read BGR color settings from JPG image + 1 byte spacer(CHR$(0))
  158.             cv& = _PALETTECOLOR(c&, image&) ' color attribute to read.
  159.             b$ = b$ + CHR$(_BLUE32(cv&)) + CHR$(_GREEN32(cv&)) + CHR$(_RED32(cv&)) + CHR$(0) 'spacer byte
  160.         NEXT
  161.     END IF
  162.     MID$(b$, 11, 4) = MKL$(LEN(b$)) ' image pixel data offset(BMP header)
  163.     lastsource& = _SOURCE
  164.     _SOURCE image&
  165.     IF ((x& * 3) MOD 4) THEN padder$ = STRING$(4 - ((x& * 3) MOD 4), 0)
  166.     FOR py& = y& - 1 TO 0 STEP -1 ' read JPG image pixel color data
  167.         r$ = ""
  168.         FOR px& = 0 TO x& - 1
  169.             c& = POINT(px&, py&) 'POINT 32 bit values are large LONG values
  170.             IF bytesperpixel& = 1 THEN r$ = r$ + CHR$(c&) ELSE r$ = r$ + LEFT$(MKL$(c&), 3)
  171.         NEXT px&
  172.         d$ = d$ + r$ + padder$
  173.     NEXT py&
  174.     _SOURCE lastsource&
  175.     MID$(b$, 35, 4) = MKL$(LEN(d$)) ' image size(BMP header)
  176.     b$ = b$ + d$ ' total file data bytes to create file
  177.     MID$(b$, 3, 4) = MKL$(LEN(b$)) ' size of data file(BMP header)
  178.     IF LCASE$(RIGHT$(filename$, 4)) <> ".bmp" THEN ext$ = ".bmp"
  179.     f& = FREEFILE
  180.     OPEN filename$ + ext$ FOR OUTPUT AS #f&: CLOSE #f& ' erases an existing file
  181.     OPEN filename$ + ext$ FOR BINARY AS #f&
  182.     PUT #f&, , b$
  183.     CLOSE #f&
  184.  
  185.  
  186.  

 
wall fix.PNG
« Last Edit: June 13, 2020, 08:34:15 pm by bplus »

Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
Re: Circular Maze Generator
« Reply #2 on: June 13, 2020, 08:53:04 pm »
Thanks B+!!!! I just have one more problem though, it's not saving the right picture, instead of the first one it's saving the next one it makes after you give it a name. Can you help me with this too? It always takes me at least a half an hour or more to find the right areas to put the _PUTIMAGE and SCREEN, etc. even though I've made these before. It's like a puzzle to me every time. lol Oh and I do agree, I'll stick with just the black and white, the colorized walls were too dark to see that good. I also agree with just having the Hard setting.
Here is what I have so far.. there was 2 conflicting lines as well that I put on accident in the DO Inkey$ LOOP area, so I removed those.

Code: QB64: [Select]
  1. 'Circular Mazes
  2. 'By Sierraken on June 13, 2020.  Mod B+ wall fix
  3. _LIMIT 300
  4. begin:
  5. _TITLE "Circular Maze Generator"
  6. picture& = _NEWIMAGE(800, 600, 32)
  7. PRINT "                         Circular Maze Generator"
  8. PRINT "                              by Sierraken"
  9. PRINT "This app will create random circular mazes like the kind you see using shrubs."
  10. PRINT "You can (s)ave a maze as .bmp and/or (p)rint a black and white version."
  11. 'PRINT: PRINT
  12. 'PRINT "Choose a difficulty:"
  13. 'PRINT "(1) Easy"
  14. 'PRINT "(2) Medium"
  15. 'PRINT "(3) Hard"
  16. 'PRINT
  17. 'INPUT "->"; dif
  18. dif = 3
  19. IF dif < 1 OR dif > 3 OR dif <> INT(dif) THEN GOTO begin:
  20. 'INPUT "Do you want (c)olor or (b)lack and white"; c$
  21. 'IF LEFT$(c$, 1) = "c" OR LEFT$(c$, 1) = "C" THEN col = 1: GOTO start:
  22. 'IF LEFT$(c$, 1) = "b" OR LEFT$(c$, 1) = "b" THEN col = 0: GOTO start:
  23. c$ = "b"
  24. 'GOTO begin:
  25. start:
  26. IF dif = 1 THEN circles = 4
  27. IF dif = 2 THEN circles = 8
  28. IF dif = 3 THEN circles = 12
  29. _TITLE "Space Bar to make new maze, (S)ave, (P)rint, Esc to quit."
  30. s& = _NEWIMAGE(800, 600, 32)
  31. SCREEN s&, picture&
  32. IF col = 0 THEN PAINT (1, 1), _RGB32(255, 255, 255)
  33. sz = 250
  34. x = 400: y = 300
  35. r2 = .25
  36. IF col = 1 THEN cc = 125
  37. IF col = 0 THEN cc = 0
  38. FOR cir = 1 TO circles
  39.     r1 = (RND * 5) + 1
  40.     IF cir > 10 THEN r2 = .5
  41.     IF col = 1 THEN cl = cir * 21
  42.     IF col = 0 THEN cl = cir
  43.     CIRCLE (x, y), sz, _RGB32(cc, cl, cc), r1, r1 - r2
  44.     _DELAY .25
  45.     IF dif = 1 THEN sz = sz - 26.67: wsz = 25.67
  46.     IF dif = 2 THEN sz = sz - 23.33: wsz = 22.33
  47.     IF dif = 3 THEN sz = sz - 20: wsz = 19
  48. NEXT cir
  49. sz = 250
  50. FOR wall = 1 TO circles - 1
  51.     ra = _PI(2) * RND
  52.     LINE (x + sz * COS(ra), y + sz * SIN(ra))-(x + (sz - 20) * COS(ra), y + (sz - 20) * SIN(ra)), _RGB32(0)
  53.     sz = sz - 20
  54.  
  55. _PUTIMAGE , s&, picture&
  56. IF sav = 1 THEN SaveImage 0, nm$: sav = 0
  57.     a$ = INKEY$
  58.     IF a$ = CHR$(27) THEN END
  59.     IF a$ = " " THEN GOTO begin:
  60.     IF a$ = "p" OR a$ = "P" THEN
  61.         IF col = 0 THEN
  62.             j& = _COPYIMAGE(0)
  63.             _DELAY .25
  64.             INPUT "Print on printer (Y/N)?", i$ 'print screen page on printer
  65.             CLS
  66.             SCREEN j&
  67.             _DELAY .25
  68.             IF LEFT$(i$, 1) = "y" OR LEFT$(i$, 1) = "Y" THEN
  69.                 'printer prep (code copied and pasted from bplus Free Calendar Program)
  70.                 YMAX = _HEIGHT: XMAX = _WIDTH
  71.                 landscape& = _NEWIMAGE(YMAX, XMAX, 32)
  72.                 _MAPTRIANGLE (XMAX, 0)-(0, 0)-(0, YMAX), 0 TO(0, 0)-(0, XMAX)-(YMAX, XMAX), landscape&
  73.                 _MAPTRIANGLE (XMAX, 0)-(XMAX, YMAX)-(0, YMAX), 0 TO(0, 0)-(YMAX, 0)-(YMAX, XMAX), landscape&
  74.                 _PRINTIMAGE landscape&
  75.                 _DELAY 2
  76.                 landscape& = 0
  77.                 s& = j&
  78.             END IF
  79.         END IF
  80.     END IF
  81.     IF a$ = "S" OR a$ = "s" THEN GOTO saving:
  82.  
  83. saving:
  84. PRINT "                       Saving"
  85. PRINT "         Your bmp file will be saved in the"
  86. PRINT "         same directory as this program is."
  87. PRINT "         It can be used with almost any"
  88. PRINT "         other graphics program or website."
  89. PRINT "         It is saved using:"
  90. PRINT "         width: 800  height: 600 pixels."
  91. PRINT "         Type a name to save your picture"
  92. PRINT "         and press the Enter key. Do not"
  93. PRINT "         add .bmp at the end, the program"
  94. PRINT "         will do it automatically."
  95. PRINT "         Example: MyPic"
  96. PRINT "         Quit and Enter key ends program."
  97. INPUT "         ->"; nm$
  98. IF nm$ = "Quit" OR nm$ = "quit" OR nm$ = "QUIT" THEN END
  99. nm$ = nm$ + ".bmp"
  100. 'Checking to see if the file already exists on your computer.
  101. theFileExists = _FILEEXISTS(nm$)
  102. IF theFileExists = -1 THEN
  103.     PRINT
  104.     PRINT "       File Already Exists"
  105.     PRINT "       Saving will delete your old"
  106.     PRINT "       bmp picture."
  107.     PRINT "       Would you like to still do it?"
  108.     PRINT "      (Y/N)."
  109.     PRINT "      Esc goes to start screen."
  110.     llloop:
  111.     _LIMIT 100
  112.     ag2$ = INKEY$
  113.     IF ag2$ = CHR$(27) THEN GOTO start:
  114.     IF ag2$ = "" THEN GOTO llloop:
  115.     IF ag2$ = "y" OR ag$ = "Y" THEN
  116.         SHELL _HIDE "DEL " + nm$
  117.         GOTO saving2:
  118.     END IF
  119.     GOTO llloop:
  120. saving2:
  121. sav = 1
  122. FOR snd = 100 TO 700 STEP 100
  123.     SOUND snd, 2
  124. NEXT snd
  125. GOTO start:
  126.  
  127. 'Here is the SUB needed to save the image to BMP.
  128. SUB SaveImage (image AS LONG, filename AS STRING)
  129.     bytesperpixel& = _PIXELSIZE(image&)
  130.     IF bytesperpixel& = 0 THEN PRINT "Text modes unsupported!": END
  131.     IF bytesperpixel& = 1 THEN bpp& = 8 ELSE bpp& = 24
  132.     x& = _WIDTH(image&)
  133.     y& = _HEIGHT(image&)
  134.     b$ = "BM????QB64????" + MKL$(40) + MKL$(x&) + MKL$(y&) + MKI$(1) + MKI$(bpp&) + MKL$(0) + "????" + STRING$(16, 0) 'partial BMP header info(???? to be filled later)
  135.     IF bytesperpixel& = 1 THEN
  136.         FOR c& = 0 TO 255 ' read BGR color settings from JPG image + 1 byte spacer(CHR$(0))
  137.             cv& = _PALETTECOLOR(c&, image&) ' color attribute to read.
  138.             b$ = b$ + CHR$(_BLUE32(cv&)) + CHR$(_GREEN32(cv&)) + CHR$(_RED32(cv&)) + CHR$(0) 'spacer byte
  139.         NEXT
  140.     END IF
  141.     MID$(b$, 11, 4) = MKL$(LEN(b$)) ' image pixel data offset(BMP header)
  142.     lastsource& = _SOURCE
  143.     _SOURCE image&
  144.     IF ((x& * 3) MOD 4) THEN padder$ = STRING$(4 - ((x& * 3) MOD 4), 0)
  145.     FOR py& = y& - 1 TO 0 STEP -1 ' read JPG image pixel color data
  146.         r$ = ""
  147.         FOR px& = 0 TO x& - 1
  148.             c& = POINT(px&, py&) 'POINT 32 bit values are large LONG values
  149.             IF bytesperpixel& = 1 THEN r$ = r$ + CHR$(c&) ELSE r$ = r$ + LEFT$(MKL$(c&), 3)
  150.         NEXT px&
  151.         d$ = d$ + r$ + padder$
  152.     NEXT py&
  153.     _SOURCE lastsource&
  154.     MID$(b$, 35, 4) = MKL$(LEN(d$)) ' image size(BMP header)
  155.     b$ = b$ + d$ ' total file data bytes to create file
  156.     MID$(b$, 3, 4) = MKL$(LEN(b$)) ' size of data file(BMP header)
  157.     IF LCASE$(RIGHT$(filename$, 4)) <> ".bmp" THEN ext$ = ".bmp"
  158.     f& = FREEFILE
  159.     OPEN filename$ + ext$ FOR OUTPUT AS #f&: CLOSE #f& ' erases an existing file
  160.     OPEN filename$ + ext$ FOR BINARY AS #f&
  161.     PUT #f&, , b$
  162.     CLOSE #f&
  163.  
« Last Edit: June 13, 2020, 08:57:31 pm by SierraKen »

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Circular Maze Generator
« Reply #3 on: June 13, 2020, 09:43:23 pm »
Hi Ken,

Remind me what line 36 is doing.

Seems to me you can just draw the picture and then save it, no need to switch between image pages.

For printing, I guess you need to transfer to an image handle to turn page but do that in the printing part of code.
« Last Edit: June 13, 2020, 09:49:10 pm by bplus »

Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
Re: Circular Maze Generator
« Reply #4 on: June 13, 2020, 09:53:27 pm »
LOL B+ you just saved the day again! I switched it from s& to picture& and now it works! I also cleaned up all the unnecessary code so I believe this might be good! Thank you!

Code: QB64: [Select]
  1. 'Circular Mazes
  2. 'By Sierraken on June 13, 2020.  Mod B+ wall fix and some help.
  3. _LIMIT 300
  4. begin:
  5. _TITLE "Circular Maze Generator"
  6. picture& = _NEWIMAGE(800, 600, 32)
  7. s& = _NEWIMAGE(800, 600, 32)
  8. c$ = "b"
  9. start:
  10. circles = 12
  11. _TITLE "Space Bar to make new maze, (S)ave, (P)rint, Esc to quit."
  12. PAINT (1, 1), _RGB32(255, 255, 255)
  13. sz = 250
  14. x = 400: y = 300
  15. r2 = .25
  16. FOR cir = 1 TO circles
  17.     r1 = (RND * 5) + 1
  18.     IF cir > 10 THEN r2 = .5
  19.     cl = cir
  20.     CIRCLE (x, y), sz, _RGB32(0, cl, 0), r1, r1 - r2
  21.     _DELAY .25
  22.     sz = sz - 20: wsz = 19
  23. NEXT cir
  24. sz = 250
  25. FOR wall = 1 TO circles - 1
  26.     ra = _PI(2) * RND
  27.     LINE (x + sz * COS(ra), y + sz * SIN(ra))-(x + (sz - 20) * COS(ra), y + (sz - 20) * SIN(ra)), _RGB32(0)
  28.     sz = sz - 20
  29. keys:
  30. _PUTIMAGE , s&, picture&
  31. SCREEN picture&
  32. IF sav = 1 THEN SaveImage 0, nm$: sav = 0
  33.  
  34.     a$ = INKEY$
  35.     IF a$ = CHR$(27) THEN END
  36.     IF a$ = " " THEN GOTO begin:
  37.     IF a$ = "p" OR a$ = "P" THEN
  38.         IF col = 0 THEN
  39.             j& = _COPYIMAGE(0)
  40.             _DELAY .25
  41.             INPUT "Print on printer (Y/N)?", i$ 'print screen page on printer
  42.             CLS
  43.             SCREEN j&
  44.             _DELAY .25
  45.             IF LEFT$(i$, 1) = "y" OR LEFT$(i$, 1) = "Y" THEN
  46.                 'printer prep (code copied and pasted from bplus Free Calendar Program)
  47.                 YMAX = _HEIGHT: XMAX = _WIDTH
  48.                 landscape& = _NEWIMAGE(YMAX, XMAX, 32)
  49.                 _MAPTRIANGLE (XMAX, 0)-(0, 0)-(0, YMAX), 0 TO(0, 0)-(0, XMAX)-(YMAX, XMAX), landscape&
  50.                 _MAPTRIANGLE (XMAX, 0)-(XMAX, YMAX)-(0, YMAX), 0 TO(0, 0)-(YMAX, 0)-(YMAX, XMAX), landscape&
  51.                 _PRINTIMAGE landscape&
  52.                 _DELAY 2
  53.                 landscape& = 0
  54.                 s& = j&
  55.             END IF
  56.         END IF
  57.     END IF
  58.     IF a$ = "S" OR a$ = "s" THEN GOTO saving:
  59.  
  60. saving:
  61. picture& = _COPYIMAGE(0)
  62. PRINT "                       Saving"
  63. PRINT "         Your bmp file will be saved in the"
  64. PRINT "         same directory as this program is."
  65. PRINT "         It can be used with almost any"
  66. PRINT "         other graphics program or website."
  67. PRINT "         It is saved using:"
  68. PRINT "         width: 800  height: 600 pixels."
  69. PRINT "         Type a name to save your picture"
  70. PRINT "         and press the Enter key. Do not"
  71. PRINT "         add .bmp at the end, the program"
  72. PRINT "         will do it automatically."
  73. PRINT "         Example: MyPic"
  74. PRINT "         Quit and Enter key ends program."
  75. INPUT "         ->"; nm$
  76. IF nm$ = "Quit" OR nm$ = "quit" OR nm$ = "QUIT" THEN END
  77. nm$ = nm$ + ".bmp"
  78. 'Checking to see if the file already exists on your computer.
  79. theFileExists = _FILEEXISTS(nm$)
  80. IF theFileExists = -1 THEN
  81.     PRINT
  82.     PRINT "       File Already Exists"
  83.     PRINT "       Saving will delete your old"
  84.     PRINT "       bmp picture."
  85.     PRINT "       Would you like to still do it?"
  86.     PRINT "      (Y/N)."
  87.     PRINT "      Esc goes to start screen."
  88.     llloop:
  89.     _LIMIT 100
  90.     ag2$ = INKEY$
  91.     IF ag2$ = CHR$(27) THEN GOTO start:
  92.     IF ag2$ = "" THEN GOTO llloop:
  93.     IF ag2$ = "y" OR ag$ = "Y" THEN
  94.         SHELL _HIDE "DEL " + nm$
  95.         GOTO saving2:
  96.     END IF
  97.     GOTO llloop:
  98. saving2:
  99. sav = 1
  100. FOR snd = 100 TO 700 STEP 100
  101.     SOUND snd, 2
  102. NEXT snd
  103. GOTO keys:
  104.  
  105. 'Here is the SUB needed to save the image to BMP.
  106. SUB SaveImage (image AS LONG, filename AS STRING)
  107.     bytesperpixel& = _PIXELSIZE(image&)
  108.     IF bytesperpixel& = 0 THEN PRINT "Text modes unsupported!": END
  109.     IF bytesperpixel& = 1 THEN bpp& = 8 ELSE bpp& = 24
  110.     x& = _WIDTH(image&)
  111.     y& = _HEIGHT(image&)
  112.     b$ = "BM????QB64????" + MKL$(40) + MKL$(x&) + MKL$(y&) + MKI$(1) + MKI$(bpp&) + MKL$(0) + "????" + STRING$(16, 0) 'partial BMP header info(???? to be filled later)
  113.     IF bytesperpixel& = 1 THEN
  114.         FOR c& = 0 TO 255 ' read BGR color settings from JPG image + 1 byte spacer(CHR$(0))
  115.             cv& = _PALETTECOLOR(c&, image&) ' color attribute to read.
  116.             b$ = b$ + CHR$(_BLUE32(cv&)) + CHR$(_GREEN32(cv&)) + CHR$(_RED32(cv&)) + CHR$(0) 'spacer byte
  117.         NEXT
  118.     END IF
  119.     MID$(b$, 11, 4) = MKL$(LEN(b$)) ' image pixel data offset(BMP header)
  120.     lastsource& = _SOURCE
  121.     _SOURCE image&
  122.     IF ((x& * 3) MOD 4) THEN padder$ = STRING$(4 - ((x& * 3) MOD 4), 0)
  123.     FOR py& = y& - 1 TO 0 STEP -1 ' read JPG image pixel color data
  124.         r$ = ""
  125.         FOR px& = 0 TO x& - 1
  126.             c& = POINT(px&, py&) 'POINT 32 bit values are large LONG values
  127.             IF bytesperpixel& = 1 THEN r$ = r$ + CHR$(c&) ELSE r$ = r$ + LEFT$(MKL$(c&), 3)
  128.         NEXT px&
  129.         d$ = d$ + r$ + padder$
  130.     NEXT py&
  131.     _SOURCE lastsource&
  132.     MID$(b$, 35, 4) = MKL$(LEN(d$)) ' image size(BMP header)
  133.     b$ = b$ + d$ ' total file data bytes to create file
  134.     MID$(b$, 3, 4) = MKL$(LEN(b$)) ' size of data file(BMP header)
  135.     IF LCASE$(RIGHT$(filename$, 4)) <> ".bmp" THEN ext$ = ".bmp"
  136.     f& = FREEFILE
  137.     OPEN filename$ + ext$ FOR OUTPUT AS #f&: CLOSE #f& ' erases an existing file
  138.     OPEN filename$ + ext$ FOR BINARY AS #f&
  139.     PUT #f&, , b$
  140.     CLOSE #f&
  141.  

Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
Re: Circular Maze Generator
« Reply #5 on: June 13, 2020, 09:54:26 pm »
Ahh, maybe I can do without switching, I haven't tried that. I am just glad it works as it is.

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Circular Maze Generator
« Reply #6 on: June 13, 2020, 10:50:04 pm »
LOL, what's the saying? If it works don't fix it.

Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
Re: Circular Maze Generator
« Reply #7 on: June 13, 2020, 10:56:31 pm »
Well I got bored... lol... so I saw if you were right and you were, I didn't need to use switches. Here is the updated code with just 1 (besides the printing code).

Code: QB64: [Select]
  1. 'Circular Mazes
  2. 'By Sierraken on June 13, 2020.  Mod B+ wall fix and some help.
  3. _LIMIT 300
  4. begin:
  5. _TITLE "Circular Maze Generator"
  6. s& = _NEWIMAGE(800, 600, 32)
  7. c$ = "b"
  8. start:
  9. circles = 12
  10. _TITLE "Space Bar to make new maze, (S)ave, (P)rint, Esc to quit."
  11. PAINT (1, 1), _RGB32(255, 255, 255)
  12. sz = 250
  13. x = 400: y = 300
  14. r2 = .25
  15. FOR cir = 1 TO circles
  16.     r1 = (RND * 5) + 1
  17.     IF cir > 10 THEN r2 = .5
  18.     cl = cir
  19.     CIRCLE (x, y), sz, _RGB32(0, cl, 0), r1, r1 - r2
  20.     _DELAY .25
  21.     sz = sz - 20: wsz = 19
  22. NEXT cir
  23. sz = 250
  24. FOR wall = 1 TO circles - 1
  25.     ra = _PI(2) * RND
  26.     LINE (x + sz * COS(ra), y + sz * SIN(ra))-(x + (sz - 20) * COS(ra), y + (sz - 20) * SIN(ra)), _RGB32(0)
  27.     sz = sz - 20
  28. keys:
  29. IF sav = 1 THEN SaveImage 0, nm$: sav = 0
  30.  
  31.     a$ = INKEY$
  32.     IF a$ = CHR$(27) THEN END
  33.     IF a$ = " " THEN GOTO begin:
  34.     IF a$ = "p" OR a$ = "P" THEN
  35.         IF col = 0 THEN
  36.             j& = _COPYIMAGE(0)
  37.             _DELAY .25
  38.             INPUT "Print on printer (Y/N)?", i$ 'print screen page on printer
  39.             CLS
  40.             SCREEN j&
  41.             _DELAY .25
  42.             IF LEFT$(i$, 1) = "y" OR LEFT$(i$, 1) = "Y" THEN
  43.                 'printer prep (code copied and pasted from bplus Free Calendar Program)
  44.                 YMAX = _HEIGHT: XMAX = _WIDTH
  45.                 landscape& = _NEWIMAGE(YMAX, XMAX, 32)
  46.                 _MAPTRIANGLE (XMAX, 0)-(0, 0)-(0, YMAX), 0 TO(0, 0)-(0, XMAX)-(YMAX, XMAX), landscape&
  47.                 _MAPTRIANGLE (XMAX, 0)-(XMAX, YMAX)-(0, YMAX), 0 TO(0, 0)-(YMAX, 0)-(YMAX, XMAX), landscape&
  48.                 _PRINTIMAGE landscape&
  49.                 _DELAY 2
  50.                 landscape& = 0
  51.                 s& = j&
  52.             END IF
  53.         END IF
  54.     END IF
  55.     IF a$ = "S" OR a$ = "s" THEN GOTO saving:
  56.  
  57. saving:
  58. s& = _COPYIMAGE(0)
  59. PRINT "                       Saving"
  60. PRINT "         Your bmp file will be saved in the"
  61. PRINT "         same directory as this program is."
  62. PRINT "         It can be used with almost any"
  63. PRINT "         other graphics program or website."
  64. PRINT "         It is saved using:"
  65. PRINT "         width: 800  height: 600 pixels."
  66. PRINT "         Type a name to save your picture"
  67. PRINT "         and press the Enter key. Do not"
  68. PRINT "         add .bmp at the end, the program"
  69. PRINT "         will do it automatically."
  70. PRINT "         Example: MyPic"
  71. PRINT "         Quit and Enter key ends program."
  72. INPUT "         ->"; nm$
  73. IF nm$ = "Quit" OR nm$ = "quit" OR nm$ = "QUIT" THEN END
  74. nm$ = nm$ + ".bmp"
  75. 'Checking to see if the file already exists on your computer.
  76. theFileExists = _FILEEXISTS(nm$)
  77. IF theFileExists = -1 THEN
  78.     PRINT
  79.     PRINT "       File Already Exists"
  80.     PRINT "       Saving will delete your old"
  81.     PRINT "       bmp picture."
  82.     PRINT "       Would you like to still do it?"
  83.     PRINT "      (Y/N)."
  84.     PRINT "      Esc goes to start screen."
  85.     llloop:
  86.     _LIMIT 100
  87.     ag2$ = INKEY$
  88.     IF ag2$ = CHR$(27) THEN GOTO start:
  89.     IF ag2$ = "" THEN GOTO llloop:
  90.     IF ag2$ = "y" OR ag$ = "Y" THEN
  91.         SHELL _HIDE "DEL " + nm$
  92.         GOTO saving2:
  93.     END IF
  94.     GOTO llloop:
  95. saving2:
  96. sav = 1
  97. FOR snd = 100 TO 700 STEP 100
  98.     SOUND snd, 2
  99. NEXT snd
  100. GOTO keys:
  101.  
  102. 'Here is the SUB needed to save the image to BMP.
  103. SUB SaveImage (image AS LONG, filename AS STRING)
  104.     bytesperpixel& = _PIXELSIZE(image&)
  105.     IF bytesperpixel& = 0 THEN PRINT "Text modes unsupported!": END
  106.     IF bytesperpixel& = 1 THEN bpp& = 8 ELSE bpp& = 24
  107.     x& = _WIDTH(image&)
  108.     y& = _HEIGHT(image&)
  109.     b$ = "BM????QB64????" + MKL$(40) + MKL$(x&) + MKL$(y&) + MKI$(1) + MKI$(bpp&) + MKL$(0) + "????" + STRING$(16, 0) 'partial BMP header info(???? to be filled later)
  110.     IF bytesperpixel& = 1 THEN
  111.         FOR c& = 0 TO 255 ' read BGR color settings from JPG image + 1 byte spacer(CHR$(0))
  112.             cv& = _PALETTECOLOR(c&, image&) ' color attribute to read.
  113.             b$ = b$ + CHR$(_BLUE32(cv&)) + CHR$(_GREEN32(cv&)) + CHR$(_RED32(cv&)) + CHR$(0) 'spacer byte
  114.         NEXT
  115.     END IF
  116.     MID$(b$, 11, 4) = MKL$(LEN(b$)) ' image pixel data offset(BMP header)
  117.     lastsource& = _SOURCE
  118.     _SOURCE image&
  119.     IF ((x& * 3) MOD 4) THEN padder$ = STRING$(4 - ((x& * 3) MOD 4), 0)
  120.     FOR py& = y& - 1 TO 0 STEP -1 ' read JPG image pixel color data
  121.         r$ = ""
  122.         FOR px& = 0 TO x& - 1
  123.             c& = POINT(px&, py&) 'POINT 32 bit values are large LONG values
  124.             IF bytesperpixel& = 1 THEN r$ = r$ + CHR$(c&) ELSE r$ = r$ + LEFT$(MKL$(c&), 3)
  125.         NEXT px&
  126.         d$ = d$ + r$ + padder$
  127.     NEXT py&
  128.     _SOURCE lastsource&
  129.     MID$(b$, 35, 4) = MKL$(LEN(d$)) ' image size(BMP header)
  130.     b$ = b$ + d$ ' total file data bytes to create file
  131.     MID$(b$, 3, 4) = MKL$(LEN(b$)) ' size of data file(BMP header)
  132.     IF LCASE$(RIGHT$(filename$, 4)) <> ".bmp" THEN ext$ = ".bmp"
  133.     f& = FREEFILE
  134.     OPEN filename$ + ext$ FOR OUTPUT AS #f&: CLOSE #f& ' erases an existing file
  135.     OPEN filename$ + ext$ FOR BINARY AS #f&
  136.     PUT #f&, , b$
  137.     CLOSE #f&
  138.  
« Last Edit: June 13, 2020, 10:57:44 pm by SierraKen »

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Circular Maze Generator
« Reply #8 on: June 13, 2020, 10:59:21 pm »
and it's OK with printout?

Never mind I found the printer section and it does it's own thing with image as it should.
« Last Edit: June 13, 2020, 11:00:55 pm by bplus »

Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
Re: Circular Maze Generator
« Reply #9 on: June 13, 2020, 11:02:28 pm »
Yep, I didn't touch the printing code. But I did check to make sure I was using the right one for the printing code. I tested a few on my printer.

Marked as best answer by SierraKen on June 13, 2020, 07:30:26 pm

Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
Re: Circular Maze Generator
« Reply #10 on: June 13, 2020, 11:21:22 pm »
I just used Steve's 2 JPG libraries that he posted the other day and now this saves as a real JPG picture! My first ever! Thanks to all of you guys for the help! I will include the 2 library files that should be in the same folder as this .bas program (I believe). I'll also mention it in that JPG libraries forum thread. Included in the attachments is also the .bas program.

Thank you!



* SaveImage.BI (Filesize: 7.35 KB, Downloads: 155)
* SaveImage.BM (Filesize: 61.53 KB, Downloads: 148)
* Kens Circular Maze Generator JPG.bas (Filesize: 3.62 KB, Downloads: 171)
« Last Edit: June 13, 2020, 11:26:59 pm by SierraKen »