Author Topic: Grid Paper Maker  (Read 1161 times)

0 Members and 1 Guest are viewing this topic.

Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
Grid Paper Maker
« on: June 08, 2020, 08:33:46 pm »
I've always wanted to make this. It lets you set the size per width of the boxes which calculates how many boxes you will get on the grid. Then you can save it as .bmp to your computer and/or print it on your printer. Your boxes can be from 2 to 200 pixels wide and long. Some of you might have already made something like this, but this is a tool everyone might use someday. It can be used for math or mapping or anything else that needs a grid. The colors are a white background with black lines. I included an example picture below. I suggest putting it in its own directory so your saved images are easy to find.

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

* gridtest2000.bmp (Filesize: 1.37 MB, Dimensions: 800x600, Views: 518)

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Grid Paper Maker
« Reply #1 on: June 08, 2020, 08:55:33 pm »
In my younger days, I did one of these for Sudoku puzzles, using a light checker color pattern to distinguish the 9 cell blocks. 6 puzzles fit on an 8.5 x 11.

Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
Re: Grid Paper Maker
« Reply #2 on: June 08, 2020, 09:50:57 pm »
At first I was seeing if I could make a random maze generator. I wish I knew how. I did make one last year but all it did really was make open gaps all over the place and sometimes people could solve the maze, sometimes it was impossible. lol I used to have an app that did mazes, I might still. But to make one myself would be an incredible accomplishment.