Author Topic: Paint Pixels 6  (Read 2242 times)

0 Members and 1 Guest are viewing this topic.

Offline SierraKen

  • Forum Resident
  • Posts: 1454
Paint Pixels 6
« on: December 17, 2019, 04:58:06 pm »
I think it was b+ that told me months ago that: "A program is never finished!"
I decided to update my Paint Pixels paint program with some new knowledge I gained recently with my recent programs. There is no changes for when you actually draw, but there are 4 big changes in it to make it worth keeping this one and tossing out the old version(s).
Here are the changes, I will copy/paste from the comments I have at the start of the code:

'This program was finished on December 17, 2019.
'Technical Notes:
'This version lets people save their .bmp files with spaces in their filenames.
'This version doesn't use the temp.bmp when saving anymore.
'This version jumps right to Draw mode when starting and also after Saving and Loading.
'This version lets you continue to draw on the same picture after Saving.

Edit: I just added a picture of a jet that was made with this if you wish to see.

Code: QB64: [Select]
  1. 'This program was finished on December 17, 2019.
  2. 'Technical Notes:
  3. 'This version lets people save their .bmp files with spaces in their filenames.
  4. 'This version doesn't use the temp.bmp when saving anymore.
  5. 'This version jumps right to Draw mode when starting and also after Saving and Loading.
  6. 'This version lets you continue to draw on the same picture after Saving.
  7. '
  8. 'This program uses around 55 MB RAM and 1% of the CPU on my semi-new computer.
  9. 'Use at your own risk. I hold no responsibility for any problems whatsoever.
  10. '
  11. 'Thank you to B+ from the QB64.org forum for the color picker, the picture rotation code,
  12. 'the ray line making code, and general help in making this program.
  13. '-------------------------------------------------------------------------------------------
  14. _LIMIT 100
  15. start:
  16. picture& = _NEWIMAGE(800, 600, 32)
  17. _TITLE "Paint Pixels 6"
  18. WIDTH 40, 43
  19. COLOR 15, 0
  20. _SCREENMOVE 400, 200
  21. PRINT "        Paint Pixels 6"
  22. PRINT "       By Ken G. and B+"
  23. PRINT "     Use your Mouse for:"
  24. PRINT "     (R)ays, (B)oxes, (O)rbits,"
  25. PRINT "     (D)raw, (E)rase, (C)olors,"
  26. PRINT "     (S)ave, (L)oad."
  27. PRINT "     (P)rint to your Printer."
  28. PRINT "     (I)nstructions - which will"
  29. PRINT "     cause your picture to be lost."
  30. PRINT "     Space Bar to erase picture."
  31. PRINT "     Press the Space Bar to"
  32. PRINT "     skip instructions."
  33. PRINT "     Press Esc to end."
  34. PRINT "   * Any other key to continue. *"
  35. gggo:
  36. _LIMIT 100
  37. ecc$ = INKEY$
  38. IF ecc$ = " " THEN GOTO start2:
  39. IF ecc$ = CHR$(27) THEN END
  40. IF ecc$ = "" THEN GOTO gggo:
  41. PRINT "               Page 2"
  42. PRINT "     Commands are self-explanatory"
  43. PRINT "     on Title Bar of Paint Window."
  44. PRINT "     Here are some others:"
  45. PRINT "     * Space Bar clears the screen."
  46. PRINT "     * A color choosing window"
  47. PRINT "       will come up right before"
  48. PRINT "       you start painting. It also"
  49. PRINT "       comes up when you press Space"
  50. PRINT "       Bar to clear the screen."
  51. PRINT "       Move the slides to the color"
  52. PRINT "       you wish to use."
  53. PRINT "     * Esc to end program."
  54. PRINT "     * Use Left Mouse Button"
  55. PRINT "     * (I)nstructions"
  56. PRINT "     - There is no Undo feature."
  57. PRINT " It saves under .bmp files which can"
  58. PRINT " be used with most other programs."
  59. PRINT " It saves as 800 x 600 pixels."
  60. PRINT "       Press Esc to end."
  61. PRINT "    *  Any other key to start. *"
  62. ggggo:
  63. _LIMIT 100
  64. ecc2$ = INKEY$
  65. IF ecc2$ = CHR$(27) THEN END
  66. IF ecc2$ = "" THEN GOTO ggggo:
  67. start2:
  68. begin = 1
  69. PRINT "         Background Color"
  70. PRINT "         (B)lack (W)hite"
  71. PRINT "         Or Esc to end program."
  72. start3:
  73. _LIMIT 1000
  74. bcolor$ = INKEY$
  75. IF bcolor$ = CHR$(27) THEN END
  76. IF bcolor$ = "" THEN GOTO start3:
  77. IF bcolor$ = "w" OR bcolor$ = "W" THEN
  78.     s& = _NEWIMAGE(800, 600, 32)
  79.     picture& = _NEWIMAGE(800, 600, 32)
  80.     bcol = 1
  81.     SCREEN s&
  82.     LINE (0, 0)-(800, 600), _RGB32(255, 255, 255), BF
  83.     _PUTIMAGE , s&, picture&
  84.     GOTO more2:
  85. IF bcolor$ = "B" OR bcolor$ = "b" THEN
  86.     s& = _NEWIMAGE(800, 600, 32)
  87.     picture& = _NEWIMAGE(800, 600, 32)
  88.     bcol = 2
  89.     SCREEN s&
  90.     CLS
  91.     GOTO more2:
  92. GOTO start3:
  93. more2:
  94. begin = 1
  95. dMode = 1
  96. m = 1
  97.  
  98. GOSUB chosencolor:
  99. _TITLE "(D)raw, (E)rase, (C)olors, (R)ays, (O)rbits, (B)oxes, (S)ave, (L)oad, (P)rint"
  100. '---------------------------------------------------
  101. 'Here is the main loop of the program when painting.
  102. '---------------------------------------------------
  103.     _LIMIT 1000
  104.     _PUTIMAGE , picture&, s&
  105.     SCREEN s&
  106.     a$ = INKEY$
  107.         mouseX = _MOUSEX
  108.         mouseY = _MOUSEY
  109.         mouseLeftButton = _MOUSEBUTTON(1)
  110.         mouseRightButton = _MOUSEBUTTON(2)
  111.         mouseMiddleButton = _MOUSEBUTTON(3)
  112.     LOOP
  113.     IF a$ = "d" OR a$ = "D" THEN
  114.         dMode = 1 - dMode
  115.         m = 1
  116.     END IF
  117.     IF dMode AND m = 1 THEN
  118.         _TITLE "Mode: (D)raw | (D)raw, (E)rase, (C)olors, (R)ays, (O)rbits, (B)oxes, (S)ave, (L)oad, (P)rint"
  119.         IF mouseLeftButton THEN
  120.             LINE (mouseX, mouseY)-(mouseX + 1, mouseY + 1), clr~&, BF
  121.             _PUTIMAGE , s&, picture&
  122.         END IF
  123.     END IF
  124.     IF m = 1 AND dMode = 0 THEN
  125.         _TITLE "(D)raw, (E)rase, (C)olors, (R)ays, (O)rbits, (B)oxes, (S)ave, (L)oad, (P)rint"
  126.     END IF
  127.     IF a$ = "e" OR a$ = "E" THEN
  128.         eMode = 1 - eMode
  129.         m = 2
  130.     END IF
  131.     IF eMode AND m = 2 THEN
  132.         _TITLE "Mode: (E)raser | (D)raw, (E)rase, (C)olors, (R)ays, (O)rbits, (B)oxes, (S)ave, (L)oad, (P)rint"
  133.         IF mouseLeftButton AND bcol = 1 THEN
  134.             LINE (mouseX, mouseY)-(mouseX + 1, mouseY + 1), _RGB32(255, 255, 255), BF
  135.             _PUTIMAGE , s&, picture&
  136.         END IF
  137.         IF mouseLeftButton AND bcol = 2 THEN
  138.             LINE (mouseX, mouseY)-(mouseX + 1, mouseY + 1), _RGB32(0, 0, 0), BF
  139.             _PUTIMAGE , s&, picture&
  140.         END IF
  141.     END IF
  142.     IF m = 2 AND eMode = 0 THEN
  143.         _TITLE "(D)raw, (E)rase, (C)olors, (R)ays, (O)rbits, (B)oxes, (S)ave, (L)oad, (P)rint"
  144.     END IF
  145.     'Here is when someone whipes the screen blank with the space bar.
  146.     IF a$ = " " THEN GOTO start2:
  147.     IF a$ = CHR$(27) THEN END
  148.     IF a$ = "s" OR a$ = "S" THEN GOTO saving:
  149.     IF a$ = "l" OR a$ = "L" THEN GOSUB loading:
  150.     IF a$ = "i" OR a$ = "I" THEN m = 0: GOTO start:
  151.     'Here is code needed to call up the Windows Color Picker.
  152.     'It also uses the code on top of this program and the Function at the end
  153.     'of this program.
  154.     IF a$ = "c" OR a$ = "C" THEN
  155.         chosencolor:
  156.         check$ = colorDialog$
  157.         IF check$ <> "" THEN clr~& = VAL(check$) ELSE clr~& = &HFF0000FF '<<< I am blue if colorDialog does not work
  158.         IF begin = 1 THEN begin = 0: RETURN
  159.     END IF
  160.     'Here is the Ray Lines code.
  161.     IF a$ = "r" OR a$ = "R" THEN
  162.         rMode = 1 - rMode
  163.         m = 3
  164.         IF rMode THEN lastx = mouseX: lastY = mouseY 'set first lastx, lasty
  165.     END IF
  166.     IF rMode AND m = 3 THEN
  167.         _TITLE "Mode: (R)ays | (D)raw, (E)rase, (C)olors, (R)ays, (O)rbits, (B)oxes, (S)ave, (L)oad, (P)rint"
  168.         LINE (lastx, lastY)-(mouseX, mouseY), clr~&
  169.         IF mouseLeftButton THEN
  170.             lastx = mouseX: lastY = mouseY
  171.             _PUTIMAGE , s&, picture&
  172.         END IF
  173.     END IF
  174.     IF m = 3 AND rMode = 0 THEN
  175.         _TITLE "(D)raw, (E)rase, (C)olors, (R)ays, (O)rbits, (B)oxes, (S)ave, (L)oad, (P)rint"
  176.     END IF
  177.     'Here is the Orbit Circles code.
  178.     IF a$ = "o" OR a$ = "O" THEN
  179.         oMode = 1 - oMode
  180.         m = 4
  181.         IF oMode THEN lastx = mouseX: lastY = mouseY
  182.     END IF
  183.     IF oMode AND m = 4 THEN
  184.         _TITLE "Mode: (O)rbits | (D)raw, (E)rase, (C)olors, (R)ays, (O)rbits, (B)oxes, (S)ave, (L)oad, (P)rint"
  185.         IF mouseX < lastx THEN size = lastx - mouseX
  186.         IF mouseX > lastx THEN size = mouseX - lastx
  187.         IF mouseY < lastY THEN size2 = lastY - mouseY
  188.         IF mouseY > lastY THEN size2 = mouseY - lastY
  189.         one:
  190.         seconds = seconds + .01
  191.         s = (60 - seconds) * 6 + size
  192.         x = INT(SIN(s / 180 * 3.141592) * size) + lastx
  193.         Y = INT(COS(s / 180 * 3.141592) * size2) + lastY
  194.         CIRCLE (x, Y), 1, clr~&
  195.         IF seconds > 60 THEN
  196.             seconds = 0
  197.             GOTO two:
  198.         END IF
  199.         GOTO one:
  200.         two:
  201.         size = 0: size2 = 0
  202.         IF mouseLeftButton THEN
  203.             lastx = mouseX
  204.             lastY = mouseY
  205.             _PUTIMAGE , s&, picture&
  206.         END IF
  207.     END IF
  208.     IF m = 4 AND oMode = 0 THEN
  209.         _TITLE "(D)raw, (E)rase, (C)olors, (R)ays, (O)rbits, (B)oxes, (S)ave, (L)oad, (P)rint"
  210.     END IF
  211.     'Here is the Boxes code.
  212.     IF a$ = "b" OR a$ = "B" THEN
  213.         bMode = 1 - bMode
  214.         m = 5
  215.         IF bMode THEN lastx = mouseX: lastY = mouseY
  216.     END IF
  217.     IF bMode AND m = 5 THEN
  218.         _TITLE "Mode: (B)oxes | (D)raw, (E)rase, (C)olors, (R)ays, (O)rbits, (B)oxes, (S)ave, (L)oad, (P)rint"
  219.         LINE (lastx, lastY)-(mouseX, mouseY), clr~&, BF
  220.         IF mouseLeftButton THEN
  221.             lastx = mouseX:
  222.             lastY = mouseY
  223.             _PUTIMAGE , s&, picture&
  224.         END IF
  225.     END IF
  226.     IF m = 5 AND bMode = 0 THEN
  227.         _TITLE "(D)raw, (E)rase, (C)olors, (R)ays, (O)rbits, (B)oxes, (S)ave, (L)oad, (P)rint"
  228.     END IF
  229.     'Here is the Printing of the picture.
  230.     IF a$ = "p" OR a$ = "P" THEN
  231.         _TITLE "Mode: (P)rint | (D)raw, (E)rase, (C)olors, (R)ays, (O)rbits, (B)oxes, (S)ave, (L)oad, (P)rint"
  232.         m = 0
  233.         IF bcolor$ = "w" OR bcolor$ = "W" THEN
  234.             j& = _COPYIMAGE(0)
  235.             _DELAY .25
  236.             INPUT "Print on printer (Y/N)?", i$ 'print screen page on printer
  237.             CLS
  238.             SCREEN j&
  239.             _DELAY .25
  240.             IF LEFT$(i$, 1) = "y" OR LEFT$(i$, 1) = "Y" THEN
  241.                 'printer prep (code copied and pasted from bplus Free Calendar Program)
  242.                 YMAX = _HEIGHT: XMAX = _WIDTH
  243.                 landscape& = _NEWIMAGE(YMAX, XMAX, 32)
  244.                 _MAPTRIANGLE (XMAX, 0)-(0, 0)-(0, YMAX), 0 TO(0, 0)-(0, XMAX)-(YMAX, XMAX), landscape&
  245.                 _MAPTRIANGLE (XMAX, 0)-(XMAX, YMAX)-(0, YMAX), 0 TO(0, 0)-(YMAX, 0)-(YMAX, XMAX), landscape&
  246.                 _PRINTIMAGE landscape&
  247.                 _DELAY 2
  248.                 landscape& = 0
  249.                 s& = j&
  250.                 _TITLE "(D)raw, (E)rase, (C)olors, (R)ays, (O)rbits, (B)oxes, (S)ave, (L)oad, (P)rint"
  251.             END IF
  252.         END IF
  253.     END IF
  254.  
  255. 'Saving
  256. 'This section first saves your picture as temp.bmp and then
  257. 'asks you a name for your picture and then renames temp.bmp to your name.
  258. saving:
  259. _TITLE "Mode: (S)ave | (D)raw, (E)rase, (C)olors, (R)ays, (O)rbits, (B)oxes, (S)ave, (L)oad, (P)rint"
  260. PRINT "                       Saving"
  261. PRINT "         Your bmp file will be saved in the"
  262. PRINT "         same directory as this program is."
  263. PRINT "         It can be used with almost any"
  264. PRINT "         other graphics program or website."
  265. PRINT "         It is saved using:"
  266. PRINT "         width: 800  height: 600 pixels."
  267. PRINT "         Type a name to save your picture"
  268. PRINT "         and press the Enter key. Do not"
  269. PRINT "         add .bmp at the end, the program"
  270. PRINT "         will do it automatically."
  271. PRINT "         Example: MyPic"
  272. PRINT "         Quit and Enter key ends program."
  273. INPUT "         ->"; nm$
  274. IF nm$ = "Quit" OR nm$ = "quit" OR nm$ = "QUIT" THEN END
  275. nm$ = nm$ + ".bmp"
  276. 'Checking to see if the file already exists on your computer.
  277. theFileExists = _FILEEXISTS(nm$)
  278. IF theFileExists = -1 THEN
  279.     PRINT
  280.     PRINT "       File Already Exists"
  281.     PRINT "       Saving will delete your old"
  282.     PRINT "       bmp picture."
  283.     PRINT "       Would you like to still do it?"
  284.     PRINT "      (Y/N)."
  285.     PRINT "      Esc goes to start screen."
  286.     llloop:
  287.     _LIMIT 100
  288.     ag2$ = INKEY$
  289.     IF ag2$ = CHR$(27) THEN GOTO start:
  290.     IF ag2$ = "" THEN GOTO llloop:
  291.     IF ag2$ = "y" OR ag$ = "Y" THEN
  292.         SHELL _HIDE "DEL " + nm$
  293.         GOTO saving2:
  294.     END IF
  295.     GOTO llloop:
  296. saving2:
  297. _PUTIMAGE , picture&, s&
  298. SaveImage 0, nm$
  299. nm$ = ""
  300. FOR snd = 100 TO 700 STEP 100
  301.     SOUND snd, 2
  302. NEXT snd
  303. GOTO more2:
  304.  
  305. 'This section loads your picture from your computer.
  306. loading:
  307. _TITLE "Mode: (L)oad | (D)raw, (E)rase, (C)olors, (R)ays, (O)rbits, (B)oxes, (S)ave, (L)oad, (P)rint"
  308. PRINT "                       Loading"
  309. PRINT "           Do not add .bmp at the end."
  310. PRINT "           The bmp picture must be in the same"
  311. PRINT "           directory as this program is."
  312. PRINT "           You will not be able to edit your"
  313. PRINT "           picture file with this program."
  314. PRINT "           Type the name of your picture file"
  315. PRINT "           here and press the Enter key."
  316. PRINT "           Example: MyPic"
  317. PRINT "           Quit and Enter key ends program."
  318. INPUT "           ->"; nm$
  319. IF nm$ = "Quit" OR nm$ = "quit" OR nm$ = "QUIT" THEN END
  320. nm$ = nm$ + ".bmp"
  321. theFileExists = _FILEEXISTS(nm$)
  322. IF theFileExists = 0 THEN
  323.     PRINT
  324.     PRINT "           File Does Not Exist."
  325.     PRINT "           Would you like to try again (Y/N)"
  326.     PRINT "           Esc goes to start screen."
  327.     _LIMIT 100
  328.     llloop2:
  329.     ag$ = INKEY$
  330.     IF ag$ = "" THEN GOTO llloop2:
  331.     IF ag$ = "y" OR ag$ = "Y" THEN GOTO loading:
  332.     IF ag$ = CHR$(27) THEN GOTO start:
  333.     GOTO start:
  334. l = 0
  335. i& = _LOADIMAGE(nm$, 32)
  336. FOR snd2 = 100 TO 700 STEP 100
  337.     SOUND snd2, 2
  338. NEXT snd2
  339. s& = i&
  340. i& = 0
  341. picture& = _NEWIMAGE(800, 600, 32)
  342. dMode = 1
  343. m = 1
  344.  
  345. 'Here is the SUB needed to save the image to BMP.
  346. SUB SaveImage (image AS LONG, filename AS STRING)
  347.     bytesperpixel& = _PIXELSIZE(image&)
  348.     IF bytesperpixel& = 0 THEN PRINT "Text modes unsupported!": END
  349.     IF bytesperpixel& = 1 THEN bpp& = 8 ELSE bpp& = 24
  350.     x& = _WIDTH(image&)
  351.     y& = _HEIGHT(image&)
  352.     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)
  353.     IF bytesperpixel& = 1 THEN
  354.         FOR c& = 0 TO 255 ' read BGR color settings from JPG image + 1 byte spacer(CHR$(0))
  355.             cv& = _PALETTECOLOR(c&, image&) ' color attribute to read.
  356.             b$ = b$ + CHR$(_BLUE32(cv&)) + CHR$(_GREEN32(cv&)) + CHR$(_RED32(cv&)) + CHR$(0) 'spacer byte
  357.         NEXT
  358.     END IF
  359.     MID$(b$, 11, 4) = MKL$(LEN(b$)) ' image pixel data offset(BMP header)
  360.     lastsource& = _SOURCE
  361.     _SOURCE image&
  362.     IF ((x& * 3) MOD 4) THEN padder$ = STRING$(4 - ((x& * 3) MOD 4), 0)
  363.     FOR py& = y& - 1 TO 0 STEP -1 ' read JPG image pixel color data
  364.         r$ = ""
  365.         FOR px& = 0 TO x& - 1
  366.             c& = POINT(px&, py&) 'POINT 32 bit values are large LONG values
  367.             IF bytesperpixel& = 1 THEN r$ = r$ + CHR$(c&) ELSE r$ = r$ + LEFT$(MKL$(c&), 3)
  368.         NEXT px&
  369.         d$ = d$ + r$ + padder$
  370.     NEXT py&
  371.     _SOURCE lastsource&
  372.     MID$(b$, 35, 4) = MKL$(LEN(d$)) ' image size(BMP header)
  373.     b$ = b$ + d$ ' total file data bytes to create file
  374.     MID$(b$, 3, 4) = MKL$(LEN(b$)) ' size of data file(BMP header)
  375.     IF LCASE$(RIGHT$(filename$, 4)) <> ".bmp" THEN ext$ = ".bmp"
  376.     f& = FREEFILE
  377.     OPEN filename$ + ext$ FOR OUTPUT AS #f&: CLOSE #f& ' erases an existing file
  378.     OPEN filename$ + ext$ FOR BINARY AS #f&
  379.     PUT #f&, , b$
  380.     CLOSE #f&
  381.  
  382. FUNCTION colorDialog$
  383.  
  384.     'first screen dimensions items to restore at exit
  385.     DIM curRow AS INTEGER, curCol AS INTEGER, autoDisplay AS INTEGER
  386.     DIM curScrn AS LONG, backScrn AS LONG 'some handles
  387.  
  388.     DIM cd AS LONG
  389.     DIM makeConst$, k$
  390.     DIM f AS SINGLE
  391.  
  392.     'save old settings to restore at end ofsub
  393.     curRow = CSRLIN
  394.     curCol = POS(0)
  395.     autoDisplay = _AUTODISPLAY
  396.     sw = _WIDTH
  397.     sh = _HEIGHT
  398.     fg = _DEFAULTCOLOR
  399.     bg = _BACKGROUNDCOLOR
  400.     _KEYCLEAR
  401.     'screen snapshot
  402.     curScrn = _DEST
  403.     backScrn = _NEWIMAGE(sw, sh, 32)
  404.     _PUTIMAGE , curScrn, backScrn
  405.  
  406.     cd = _NEWIMAGE(800, 600, 32)
  407.     SCREEN cd
  408.     r = 128: g = 128: b = 128: a = 128
  409.     COLOR &HFFDDDDDD, 0
  410.     DO
  411.         CLS
  412.         makeConst$ = "&H" + RIGHT$(STRING$(8, "0") + HEX$(_RGBA32(r, g, b, a)), 8)
  413.         slider 16, 10, r, "Red"
  414.         slider 16, 60, g, "Green"
  415.         slider 16, 110, b, "Blue"
  416.         slider 16, 160, a, "Alpha"
  417.         _PRINTSTRING (150, 260), "Press Enter or Spacebar, if you want to use the color: " + makeConst$
  418.         _PRINTSTRING (210, 280), "Press Escape or Q to not use any color, returns 0."
  419.         LINE (90, 300)-(710, 590), , B
  420.         FOR i = 100 TO 700
  421.             f = 255 * (i - 100) / 600
  422.             LINE (i, 310)-STEP(0, 30), _RGB32(f, 0, 0): LINE (i, 310)-STEP(0, 20), VAL(makeConst$)
  423.             LINE (i, 340)-STEP(0, 30), _RGB32(0, f, 0): LINE (i, 340)-STEP(0, 20), VAL(makeConst$)
  424.             LINE (i, 370)-STEP(0, 30), _RGB32(0, 0, f): LINE (i, 370)-STEP(0, 20), VAL(makeConst$)
  425.             LINE (i, 400)-STEP(0, 30), _RGB32(f, f, 0): LINE (i, 400)-STEP(0, 20), VAL(makeConst$)
  426.             LINE (i, 430)-STEP(0, 30), _RGB32(0, f, f): LINE (i, 430)-STEP(0, 20), VAL(makeConst$)
  427.             LINE (i, 460)-STEP(0, 30), _RGB32(f, 0, f): LINE (i, 460)-STEP(0, 20), VAL(makeConst$)
  428.             LINE (i, 490)-STEP(0, 30), _RGB32(f, f, f): LINE (i, 490)-STEP(0, 20), VAL(makeConst$)
  429.             LINE (i, 520)-STEP(0, 30), _RGB32(0, 0, 0): LINE (i, 520)-STEP(0, 20), VAL(makeConst$)
  430.             LINE (i, 550)-STEP(0, 30), _RGB32(255, 255, 255): LINE (i, 550)-STEP(0, 20), VAL(makeConst$)
  431.         NEXT
  432.         WHILE _MOUSEINPUT: WEND
  433.         mb = _MOUSEBUTTON(1)
  434.         IF mb THEN 'clear it
  435.             mx = _MOUSEX: my = _MOUSEY
  436.             IF mx >= 16 AND mx <= 781 THEN
  437.                 IF my >= 10 AND my <= 50 THEN
  438.                     r = INT((mx - 16) / 3)
  439.                 ELSEIF my >= 60 AND my <= 100 THEN
  440.                     g = INT((mx - 16) / 3)
  441.                 ELSEIF my >= 110 AND my <= 150 THEN
  442.                     b = INT((mx - 16) / 3)
  443.                 ELSEIF my >= 160 AND my <= 200 THEN
  444.                     a = INT((mx - 16) / 3)
  445.                 END IF
  446.             END IF
  447.         END IF
  448.         k$ = INKEY$
  449.         IF LEN(k$) THEN
  450.             IF ASC(k$) = 27 OR k$ = "q" THEN EXIT DO
  451.             IF ASC(k$) = 13 OR k$ = " " THEN colorDialog$ = makeConst$: EXIT DO
  452.         END IF
  453.         _DISPLAY
  454.         _LIMIT 60
  455.     LOOP
  456.  
  457.     'put things back
  458.     SCREEN curScrn
  459.     COLOR _RGB32(255, 255, 255), _RGB32(0, 0, 0): CLS
  460.     _PUTIMAGE , backScrn
  461.     _DISPLAY
  462.     COLOR fg, bg
  463.     _FREEIMAGE backScrn
  464.     _FREEIMAGE cd
  465.     IF autoDisplay THEN _AUTODISPLAY
  466.     'clear key presses
  467.     _KEYCLEAR
  468.     'clear mouse clicks
  469.     mb = _MOUSEBUTTON(1)
  470.     IF mb THEN 'clear it
  471.         WHILE mb 'OK!
  472.             IF _MOUSEINPUT THEN mb = _MOUSEBUTTON(1)
  473.             _LIMIT 10
  474.         WEND
  475.     END IF
  476.     LOCATE curRow, curCol
  477.  
  478.  
  479. SUB slider (x, y, value, label$)
  480.     DIM c~&, s$
  481.     SELECT CASE label$
  482.         CASE "Red": c~& = &HFFFF0000
  483.         CASE "Green": c~& = &HFF008800
  484.         CASE "Blue": c~& = &HFF0000FF
  485.         CASE "Alpha": c~& = &H88FFFFFF
  486.     END SELECT
  487.     LINE (x, y)-STEP(765, 40), c~&, B
  488.     LINE (x, y)-STEP(3 * value, 40), c~&, BF
  489.     s2$ = STR$(value)
  490.     s3$ = LTRIM$(RTRIM$(s2$))
  491.     s$ = label$ + " = " + s3$
  492.     _PRINTSTRING (x + 384 - 4 * LEN(s$), y + 12), s$
  493.  

Jet.bmp
* Jet.bmp (Filesize: 1.37 MB, Dimensions: 800x600, Views: 160)
« Last Edit: December 18, 2019, 02:51:19 pm by SierraKen »

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
Re: Paint Pixels 6
« Reply #1 on: December 21, 2019, 01:14:26 pm »
Hi Ken,

A comment about deciding to cancel or escape from ColorDialog:
Code: [Select]
    IF a$ = "c" OR a$ = "C" THEN
        chosencolor:
        check$ = colorDialog$
        IF check$ <> "" THEN clr~& = VAL(check$) ELSE clr~& = &HFF0000FF '<<< I am blue if colorDialog does not work
        IF begin = 1 THEN begin = 0: RETURN
    END IF

Like this:
Code: [Select]
    IF a$ = "c" OR a$ = "C" THEN
        chosencolor:
        check$ = colorDialog$
        IF check$ <> "" THEN clr~& = VAL(check$) 'ELSE <<< don't change drawing color
        IF begin = 1 THEN begin = 0: RETURN
    END IF


Offline SierraKen

  • Forum Resident
  • Posts: 1454
Re: Paint Pixels 6
« Reply #2 on: December 21, 2019, 01:31:17 pm »
Thanks bplus. I wondered about that months ago but just left it in there. Since I have people choose a color to start out with, this makes sense to me. Here is the updated code, I will also update my website today.

Code: QB64: [Select]
  1. 'This program was finished on December 17, 2019.
  2. 'Technical Notes:
  3. 'This version lets people save their .bmp files with spaces in their filenames.
  4. 'This version doesn't use the temp.bmp when saving anymore.
  5. 'This version jumps right to Draw mode when starting and also after Saving and Loading.
  6. 'This version lets you continue to draw on the same picture after Saving.
  7. '
  8. 'This program uses around 55 MB RAM and 1% of the CPU on my semi-new computer.
  9. 'Use at your own risk. I hold no responsibility for any problems whatsoever.
  10. '
  11. 'Thank you to B+ from the QB64.org forum for the color picker, the picture rotation code,
  12. 'the ray line making code, and general help in making this program.
  13. '-------------------------------------------------------------------------------------------
  14. _LIMIT 100
  15. start:
  16. picture& = _NEWIMAGE(800, 600, 32)
  17. _TITLE "Paint Pixels 6"
  18. WIDTH 40, 43
  19. COLOR 15, 0
  20. _SCREENMOVE 400, 200
  21. PRINT "        Paint Pixels 6"
  22. PRINT "       By Ken G. and B+"
  23. PRINT "     Use your Mouse for:"
  24. PRINT "     (R)ays, (B)oxes, (O)rbits,"
  25. PRINT "     (D)raw, (E)rase, (C)olors,"
  26. PRINT "     (S)ave, (L)oad."
  27. PRINT "     (P)rint to your Printer."
  28. PRINT "     (I)nstructions - which will"
  29. PRINT "     cause your picture to be lost."
  30. PRINT "     Space Bar to erase picture."
  31. PRINT "     Press the Space Bar to"
  32. PRINT "     skip instructions."
  33. PRINT "     Press Esc to end."
  34. PRINT "   * Any other key to continue. *"
  35. gggo:
  36. _LIMIT 100
  37. ecc$ = INKEY$
  38. IF ecc$ = " " THEN GOTO start2:
  39. IF ecc$ = CHR$(27) THEN END
  40. IF ecc$ = "" THEN GOTO gggo:
  41. PRINT "               Page 2"
  42. PRINT "     Commands are self-explanatory"
  43. PRINT "     on Title Bar of Paint Window."
  44. PRINT "     Here are some others:"
  45. PRINT "     * Space Bar clears the screen."
  46. PRINT "     * A color choosing window"
  47. PRINT "       will come up right before"
  48. PRINT "       you start painting. It also"
  49. PRINT "       comes up when you press Space"
  50. PRINT "       Bar to clear the screen."
  51. PRINT "       Move the slides to the color"
  52. PRINT "       you wish to use."
  53. PRINT "     * Esc to end program."
  54. PRINT "     * Use Left Mouse Button"
  55. PRINT "     * (I)nstructions"
  56. PRINT "     - There is no Undo feature."
  57. PRINT " It saves under .bmp files which can"
  58. PRINT " be used with most other programs."
  59. PRINT " It saves as 800 x 600 pixels."
  60. PRINT "       Press Esc to end."
  61. PRINT "    *  Any other key to start. *"
  62. ggggo:
  63. _LIMIT 100
  64. ecc2$ = INKEY$
  65. IF ecc2$ = CHR$(27) THEN END
  66. IF ecc2$ = "" THEN GOTO ggggo:
  67. start2:
  68. begin = 1
  69. PRINT "         Background Color"
  70. PRINT "         (B)lack (W)hite"
  71. PRINT "         Or Esc to end program."
  72. start3:
  73. _LIMIT 1000
  74. bcolor$ = INKEY$
  75. IF bcolor$ = CHR$(27) THEN END
  76. IF bcolor$ = "" THEN GOTO start3:
  77. IF bcolor$ = "w" OR bcolor$ = "W" THEN
  78.     s& = _NEWIMAGE(800, 600, 32)
  79.     picture& = _NEWIMAGE(800, 600, 32)
  80.     bcol = 1
  81.     SCREEN s&
  82.     LINE (0, 0)-(800, 600), _RGB32(255, 255, 255), BF
  83.     _PUTIMAGE , s&, picture&
  84.     GOTO more2:
  85. IF bcolor$ = "B" OR bcolor$ = "b" THEN
  86.     s& = _NEWIMAGE(800, 600, 32)
  87.     picture& = _NEWIMAGE(800, 600, 32)
  88.     bcol = 2
  89.     SCREEN s&
  90.     CLS
  91.     GOTO more2:
  92. GOTO start3:
  93. more2:
  94. begin = 1
  95. dMode = 1
  96. m = 1
  97.  
  98. GOSUB chosencolor:
  99. _TITLE "(D)raw, (E)rase, (C)olors, (R)ays, (O)rbits, (B)oxes, (S)ave, (L)oad, (P)rint"
  100. '---------------------------------------------------
  101. 'Here is the main loop of the program when painting.
  102. '---------------------------------------------------
  103.     _LIMIT 1000
  104.     _PUTIMAGE , picture&, s&
  105.     SCREEN s&
  106.     a$ = INKEY$
  107.         mouseX = _MOUSEX
  108.         mouseY = _MOUSEY
  109.         mouseLeftButton = _MOUSEBUTTON(1)
  110.         mouseRightButton = _MOUSEBUTTON(2)
  111.         mouseMiddleButton = _MOUSEBUTTON(3)
  112.     LOOP
  113.     IF a$ = "d" OR a$ = "D" THEN
  114.         dMode = 1 - dMode
  115.         m = 1
  116.     END IF
  117.     IF dMode AND m = 1 THEN
  118.         _TITLE "Mode: (D)raw | (D)raw, (E)rase, (C)olors, (R)ays, (O)rbits, (B)oxes, (S)ave, (L)oad, (P)rint"
  119.         IF mouseLeftButton THEN
  120.             LINE (mouseX, mouseY)-(mouseX + 1, mouseY + 1), clr~&, BF
  121.             _PUTIMAGE , s&, picture&
  122.         END IF
  123.     END IF
  124.     IF m = 1 AND dMode = 0 THEN
  125.         _TITLE "(D)raw, (E)rase, (C)olors, (R)ays, (O)rbits, (B)oxes, (S)ave, (L)oad, (P)rint"
  126.     END IF
  127.     IF a$ = "e" OR a$ = "E" THEN
  128.         eMode = 1 - eMode
  129.         m = 2
  130.     END IF
  131.     IF eMode AND m = 2 THEN
  132.         _TITLE "Mode: (E)raser | (D)raw, (E)rase, (C)olors, (R)ays, (O)rbits, (B)oxes, (S)ave, (L)oad, (P)rint"
  133.         IF mouseLeftButton AND bcol = 1 THEN
  134.             LINE (mouseX, mouseY)-(mouseX + 1, mouseY + 1), _RGB32(255, 255, 255), BF
  135.             _PUTIMAGE , s&, picture&
  136.         END IF
  137.         IF mouseLeftButton AND bcol = 2 THEN
  138.             LINE (mouseX, mouseY)-(mouseX + 1, mouseY + 1), _RGB32(0, 0, 0), BF
  139.             _PUTIMAGE , s&, picture&
  140.         END IF
  141.     END IF
  142.     IF m = 2 AND eMode = 0 THEN
  143.         _TITLE "(D)raw, (E)rase, (C)olors, (R)ays, (O)rbits, (B)oxes, (S)ave, (L)oad, (P)rint"
  144.     END IF
  145.     'Here is when someone whipes the screen blank with the space bar.
  146.     IF a$ = " " THEN GOTO start2:
  147.     IF a$ = CHR$(27) THEN END
  148.     IF a$ = "s" OR a$ = "S" THEN GOTO saving:
  149.     IF a$ = "l" OR a$ = "L" THEN GOSUB loading:
  150.     IF a$ = "i" OR a$ = "I" THEN m = 0: GOTO start:
  151.     'Here is code needed to call up the Windows Color Picker.
  152.     'It also uses the code on top of this program and the Function at the end
  153.     'of this program.
  154.     IF a$ = "c" OR a$ = "C" THEN
  155.         chosencolor:
  156.         check$ = colorDialog$
  157.         IF check$ <> "" THEN clr~& = VAL(check$) 'ELSE <<< don't change drawing color
  158.         IF begin = 1 THEN begin = 0: RETURN
  159.     END IF
  160.     'Here is the Ray Lines code.
  161.     IF a$ = "r" OR a$ = "R" THEN
  162.         rMode = 1 - rMode
  163.         m = 3
  164.         IF rMode THEN lastx = mouseX: lastY = mouseY 'set first lastx, lasty
  165.     END IF
  166.     IF rMode AND m = 3 THEN
  167.         _TITLE "Mode: (R)ays | (D)raw, (E)rase, (C)olors, (R)ays, (O)rbits, (B)oxes, (S)ave, (L)oad, (P)rint"
  168.         LINE (lastx, lastY)-(mouseX, mouseY), clr~&
  169.         IF mouseLeftButton THEN
  170.             lastx = mouseX: lastY = mouseY
  171.             _PUTIMAGE , s&, picture&
  172.         END IF
  173.     END IF
  174.     IF m = 3 AND rMode = 0 THEN
  175.         _TITLE "(D)raw, (E)rase, (C)olors, (R)ays, (O)rbits, (B)oxes, (S)ave, (L)oad, (P)rint"
  176.     END IF
  177.     'Here is the Orbit Circles code.
  178.     IF a$ = "o" OR a$ = "O" THEN
  179.         oMode = 1 - oMode
  180.         m = 4
  181.         IF oMode THEN lastx = mouseX: lastY = mouseY
  182.     END IF
  183.     IF oMode AND m = 4 THEN
  184.         _TITLE "Mode: (O)rbits | (D)raw, (E)rase, (C)olors, (R)ays, (O)rbits, (B)oxes, (S)ave, (L)oad, (P)rint"
  185.         IF mouseX < lastx THEN size = lastx - mouseX
  186.         IF mouseX > lastx THEN size = mouseX - lastx
  187.         IF mouseY < lastY THEN size2 = lastY - mouseY
  188.         IF mouseY > lastY THEN size2 = mouseY - lastY
  189.         one:
  190.         seconds = seconds + .01
  191.         s = (60 - seconds) * 6 + size
  192.         x = INT(SIN(s / 180 * 3.141592) * size) + lastx
  193.         Y = INT(COS(s / 180 * 3.141592) * size2) + lastY
  194.         CIRCLE (x, Y), 1, clr~&
  195.         IF seconds > 60 THEN
  196.             seconds = 0
  197.             GOTO two:
  198.         END IF
  199.         GOTO one:
  200.         two:
  201.         size = 0: size2 = 0
  202.         IF mouseLeftButton THEN
  203.             lastx = mouseX
  204.             lastY = mouseY
  205.             _PUTIMAGE , s&, picture&
  206.         END IF
  207.     END IF
  208.     IF m = 4 AND oMode = 0 THEN
  209.         _TITLE "(D)raw, (E)rase, (C)olors, (R)ays, (O)rbits, (B)oxes, (S)ave, (L)oad, (P)rint"
  210.     END IF
  211.     'Here is the Boxes code.
  212.     IF a$ = "b" OR a$ = "B" THEN
  213.         bMode = 1 - bMode
  214.         m = 5
  215.         IF bMode THEN lastx = mouseX: lastY = mouseY
  216.     END IF
  217.     IF bMode AND m = 5 THEN
  218.         _TITLE "Mode: (B)oxes | (D)raw, (E)rase, (C)olors, (R)ays, (O)rbits, (B)oxes, (S)ave, (L)oad, (P)rint"
  219.         LINE (lastx, lastY)-(mouseX, mouseY), clr~&, BF
  220.         IF mouseLeftButton THEN
  221.             lastx = mouseX:
  222.             lastY = mouseY
  223.             _PUTIMAGE , s&, picture&
  224.         END IF
  225.     END IF
  226.     IF m = 5 AND bMode = 0 THEN
  227.         _TITLE "(D)raw, (E)rase, (C)olors, (R)ays, (O)rbits, (B)oxes, (S)ave, (L)oad, (P)rint"
  228.     END IF
  229.     'Here is the Printing of the picture.
  230.     IF a$ = "p" OR a$ = "P" THEN
  231.         _TITLE "Mode: (P)rint | (D)raw, (E)rase, (C)olors, (R)ays, (O)rbits, (B)oxes, (S)ave, (L)oad, (P)rint"
  232.         m = 0
  233.         IF bcolor$ = "w" OR bcolor$ = "W" THEN
  234.             j& = _COPYIMAGE(0)
  235.             _DELAY .25
  236.             INPUT "Print on printer (Y/N)?", i$ 'print screen page on printer
  237.             CLS
  238.             SCREEN j&
  239.             _DELAY .25
  240.             IF LEFT$(i$, 1) = "y" OR LEFT$(i$, 1) = "Y" THEN
  241.                 'printer prep (code copied and pasted from bplus Free Calendar Program)
  242.                 YMAX = _HEIGHT: XMAX = _WIDTH
  243.                 landscape& = _NEWIMAGE(YMAX, XMAX, 32)
  244.                 _MAPTRIANGLE (XMAX, 0)-(0, 0)-(0, YMAX), 0 TO(0, 0)-(0, XMAX)-(YMAX, XMAX), landscape&
  245.                 _MAPTRIANGLE (XMAX, 0)-(XMAX, YMAX)-(0, YMAX), 0 TO(0, 0)-(YMAX, 0)-(YMAX, XMAX), landscape&
  246.                 _PRINTIMAGE landscape&
  247.                 _DELAY 2
  248.                 landscape& = 0
  249.                 s& = j&
  250.                 _TITLE "(D)raw, (E)rase, (C)olors, (R)ays, (O)rbits, (B)oxes, (S)ave, (L)oad, (P)rint"
  251.             END IF
  252.         END IF
  253.     END IF
  254.  
  255. 'Saving
  256. 'This section first saves your picture as temp.bmp and then
  257. 'asks you a name for your picture and then renames temp.bmp to your name.
  258. saving:
  259. _TITLE "Mode: (S)ave | (D)raw, (E)rase, (C)olors, (R)ays, (O)rbits, (B)oxes, (S)ave, (L)oad, (P)rint"
  260. PRINT "                       Saving"
  261. PRINT "         Your bmp file will be saved in the"
  262. PRINT "         same directory as this program is."
  263. PRINT "         It can be used with almost any"
  264. PRINT "         other graphics program or website."
  265. PRINT "         It is saved using:"
  266. PRINT "         width: 800  height: 600 pixels."
  267. PRINT "         Type a name to save your picture"
  268. PRINT "         and press the Enter key. Do not"
  269. PRINT "         add .bmp at the end, the program"
  270. PRINT "         will do it automatically."
  271. PRINT "         Example: MyPic"
  272. PRINT "         Quit and Enter key ends program."
  273. INPUT "         ->"; nm$
  274. IF nm$ = "Quit" OR nm$ = "quit" OR nm$ = "QUIT" THEN END
  275. nm$ = nm$ + ".bmp"
  276. 'Checking to see if the file already exists on your computer.
  277. theFileExists = _FILEEXISTS(nm$)
  278. IF theFileExists = -1 THEN
  279.     PRINT
  280.     PRINT "       File Already Exists"
  281.     PRINT "       Saving will delete your old"
  282.     PRINT "       bmp picture."
  283.     PRINT "       Would you like to still do it?"
  284.     PRINT "      (Y/N)."
  285.     PRINT "      Esc goes to start screen."
  286.     llloop:
  287.     _LIMIT 100
  288.     ag2$ = INKEY$
  289.     IF ag2$ = CHR$(27) THEN GOTO start:
  290.     IF ag2$ = "" THEN GOTO llloop:
  291.     IF ag2$ = "y" OR ag$ = "Y" THEN
  292.         SHELL _HIDE "DEL " + nm$
  293.         GOTO saving2:
  294.     END IF
  295.     GOTO llloop:
  296. saving2:
  297. _PUTIMAGE , picture&, s&
  298. SaveImage 0, nm$
  299. nm$ = ""
  300. FOR snd = 100 TO 700 STEP 100
  301.     SOUND snd, 2
  302. NEXT snd
  303. GOTO more2:
  304.  
  305. 'This section loads your picture from your computer.
  306. loading:
  307. _TITLE "Mode: (L)oad | (D)raw, (E)rase, (C)olors, (R)ays, (O)rbits, (B)oxes, (S)ave, (L)oad, (P)rint"
  308. PRINT "                       Loading"
  309. PRINT "           Do not add .bmp at the end."
  310. PRINT "           The bmp picture must be in the same"
  311. PRINT "           directory as this program is."
  312. PRINT "           You will not be able to edit your"
  313. PRINT "           picture file with this program."
  314. PRINT "           Type the name of your picture file"
  315. PRINT "           here and press the Enter key."
  316. PRINT "           Example: MyPic"
  317. PRINT "           Quit and Enter key ends program."
  318. INPUT "           ->"; nm$
  319. IF nm$ = "Quit" OR nm$ = "quit" OR nm$ = "QUIT" THEN END
  320. nm$ = nm$ + ".bmp"
  321. theFileExists = _FILEEXISTS(nm$)
  322. IF theFileExists = 0 THEN
  323.     PRINT
  324.     PRINT "           File Does Not Exist."
  325.     PRINT "           Would you like to try again (Y/N)"
  326.     PRINT "           Esc goes to start screen."
  327.     _LIMIT 100
  328.     llloop2:
  329.     ag$ = INKEY$
  330.     IF ag$ = "" THEN GOTO llloop2:
  331.     IF ag$ = "y" OR ag$ = "Y" THEN GOTO loading:
  332.     IF ag$ = CHR$(27) THEN GOTO start:
  333.     GOTO start:
  334. l = 0
  335. i& = _LOADIMAGE(nm$, 32)
  336. FOR snd2 = 100 TO 700 STEP 100
  337.     SOUND snd2, 2
  338. NEXT snd2
  339. s& = i&
  340. i& = 0
  341. picture& = _NEWIMAGE(800, 600, 32)
  342. dMode = 1
  343. m = 1
  344.  
  345. 'Here is the SUB needed to save the image to BMP.
  346. SUB SaveImage (image AS LONG, filename AS STRING)
  347.     bytesperpixel& = _PIXELSIZE(image&)
  348.     IF bytesperpixel& = 0 THEN PRINT "Text modes unsupported!": END
  349.     IF bytesperpixel& = 1 THEN bpp& = 8 ELSE bpp& = 24
  350.     x& = _WIDTH(image&)
  351.     y& = _HEIGHT(image&)
  352.     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)
  353.     IF bytesperpixel& = 1 THEN
  354.         FOR c& = 0 TO 255 ' read BGR color settings from JPG image + 1 byte spacer(CHR$(0))
  355.             cv& = _PALETTECOLOR(c&, image&) ' color attribute to read.
  356.             b$ = b$ + CHR$(_BLUE32(cv&)) + CHR$(_GREEN32(cv&)) + CHR$(_RED32(cv&)) + CHR$(0) 'spacer byte
  357.         NEXT
  358.     END IF
  359.     MID$(b$, 11, 4) = MKL$(LEN(b$)) ' image pixel data offset(BMP header)
  360.     lastsource& = _SOURCE
  361.     _SOURCE image&
  362.     IF ((x& * 3) MOD 4) THEN padder$ = STRING$(4 - ((x& * 3) MOD 4), 0)
  363.     FOR py& = y& - 1 TO 0 STEP -1 ' read JPG image pixel color data
  364.         r$ = ""
  365.         FOR px& = 0 TO x& - 1
  366.             c& = POINT(px&, py&) 'POINT 32 bit values are large LONG values
  367.             IF bytesperpixel& = 1 THEN r$ = r$ + CHR$(c&) ELSE r$ = r$ + LEFT$(MKL$(c&), 3)
  368.         NEXT px&
  369.         d$ = d$ + r$ + padder$
  370.     NEXT py&
  371.     _SOURCE lastsource&
  372.     MID$(b$, 35, 4) = MKL$(LEN(d$)) ' image size(BMP header)
  373.     b$ = b$ + d$ ' total file data bytes to create file
  374.     MID$(b$, 3, 4) = MKL$(LEN(b$)) ' size of data file(BMP header)
  375.     IF LCASE$(RIGHT$(filename$, 4)) <> ".bmp" THEN ext$ = ".bmp"
  376.     f& = FREEFILE
  377.     OPEN filename$ + ext$ FOR OUTPUT AS #f&: CLOSE #f& ' erases an existing file
  378.     OPEN filename$ + ext$ FOR BINARY AS #f&
  379.     PUT #f&, , b$
  380.     CLOSE #f&
  381.  
  382. FUNCTION colorDialog$
  383.  
  384.     'first screen dimensions items to restore at exit
  385.     DIM curRow AS INTEGER, curCol AS INTEGER, autoDisplay AS INTEGER
  386.     DIM curScrn AS LONG, backScrn AS LONG 'some handles
  387.  
  388.     DIM cd AS LONG
  389.     DIM makeConst$, k$
  390.     DIM f AS SINGLE
  391.  
  392.     'save old settings to restore at end ofsub
  393.     curRow = CSRLIN
  394.     curCol = POS(0)
  395.     autoDisplay = _AUTODISPLAY
  396.     sw = _WIDTH
  397.     sh = _HEIGHT
  398.     fg = _DEFAULTCOLOR
  399.     bg = _BACKGROUNDCOLOR
  400.     _KEYCLEAR
  401.     'screen snapshot
  402.     curScrn = _DEST
  403.     backScrn = _NEWIMAGE(sw, sh, 32)
  404.     _PUTIMAGE , curScrn, backScrn
  405.  
  406.     cd = _NEWIMAGE(800, 600, 32)
  407.     SCREEN cd
  408.     r = 128: g = 128: b = 128: a = 128
  409.     COLOR &HFFDDDDDD, 0
  410.     DO
  411.         CLS
  412.         makeConst$ = "&H" + RIGHT$(STRING$(8, "0") + HEX$(_RGBA32(r, g, b, a)), 8)
  413.         slider 16, 10, r, "Red"
  414.         slider 16, 60, g, "Green"
  415.         slider 16, 110, b, "Blue"
  416.         slider 16, 160, a, "Alpha"
  417.         _PRINTSTRING (150, 260), "Press Enter or Spacebar, if you want to use the color: " + makeConst$
  418.         _PRINTSTRING (210, 280), "Press Escape or Q to not use any color, returns 0."
  419.         LINE (90, 300)-(710, 590), , B
  420.         FOR i = 100 TO 700
  421.             f = 255 * (i - 100) / 600
  422.             LINE (i, 310)-STEP(0, 30), _RGB32(f, 0, 0): LINE (i, 310)-STEP(0, 20), VAL(makeConst$)
  423.             LINE (i, 340)-STEP(0, 30), _RGB32(0, f, 0): LINE (i, 340)-STEP(0, 20), VAL(makeConst$)
  424.             LINE (i, 370)-STEP(0, 30), _RGB32(0, 0, f): LINE (i, 370)-STEP(0, 20), VAL(makeConst$)
  425.             LINE (i, 400)-STEP(0, 30), _RGB32(f, f, 0): LINE (i, 400)-STEP(0, 20), VAL(makeConst$)
  426.             LINE (i, 430)-STEP(0, 30), _RGB32(0, f, f): LINE (i, 430)-STEP(0, 20), VAL(makeConst$)
  427.             LINE (i, 460)-STEP(0, 30), _RGB32(f, 0, f): LINE (i, 460)-STEP(0, 20), VAL(makeConst$)
  428.             LINE (i, 490)-STEP(0, 30), _RGB32(f, f, f): LINE (i, 490)-STEP(0, 20), VAL(makeConst$)
  429.             LINE (i, 520)-STEP(0, 30), _RGB32(0, 0, 0): LINE (i, 520)-STEP(0, 20), VAL(makeConst$)
  430.             LINE (i, 550)-STEP(0, 30), _RGB32(255, 255, 255): LINE (i, 550)-STEP(0, 20), VAL(makeConst$)
  431.         NEXT
  432.         WHILE _MOUSEINPUT: WEND
  433.         mb = _MOUSEBUTTON(1)
  434.         IF mb THEN 'clear it
  435.             mx = _MOUSEX: my = _MOUSEY
  436.             IF mx >= 16 AND mx <= 781 THEN
  437.                 IF my >= 10 AND my <= 50 THEN
  438.                     r = INT((mx - 16) / 3)
  439.                 ELSEIF my >= 60 AND my <= 100 THEN
  440.                     g = INT((mx - 16) / 3)
  441.                 ELSEIF my >= 110 AND my <= 150 THEN
  442.                     b = INT((mx - 16) / 3)
  443.                 ELSEIF my >= 160 AND my <= 200 THEN
  444.                     a = INT((mx - 16) / 3)
  445.                 END IF
  446.             END IF
  447.         END IF
  448.         k$ = INKEY$
  449.         IF LEN(k$) THEN
  450.             IF ASC(k$) = 27 OR k$ = "q" THEN EXIT DO
  451.             IF ASC(k$) = 13 OR k$ = " " THEN colorDialog$ = makeConst$: EXIT DO
  452.         END IF
  453.         _DISPLAY
  454.         _LIMIT 60
  455.     LOOP
  456.  
  457.     'put things back
  458.     SCREEN curScrn
  459.     COLOR _RGB32(255, 255, 255), _RGB32(0, 0, 0): CLS
  460.     _PUTIMAGE , backScrn
  461.     _DISPLAY
  462.     COLOR fg, bg
  463.     _FREEIMAGE backScrn
  464.     _FREEIMAGE cd
  465.     IF autoDisplay THEN _AUTODISPLAY
  466.     'clear key presses
  467.     _KEYCLEAR
  468.     'clear mouse clicks
  469.     mb = _MOUSEBUTTON(1)
  470.     IF mb THEN 'clear it
  471.         WHILE mb 'OK!
  472.             IF _MOUSEINPUT THEN mb = _MOUSEBUTTON(1)
  473.             _LIMIT 10
  474.         WEND
  475.     END IF
  476.     LOCATE curRow, curCol
  477.  
  478.  
  479. SUB slider (x, y, value, label$)
  480.     DIM c~&, s$
  481.     SELECT CASE label$
  482.         CASE "Red": c~& = &HFFFF0000
  483.         CASE "Green": c~& = &HFF008800
  484.         CASE "Blue": c~& = &HFF0000FF
  485.         CASE "Alpha": c~& = &H88FFFFFF
  486.     END SELECT
  487.     LINE (x, y)-STEP(765, 40), c~&, B
  488.     LINE (x, y)-STEP(3 * value, 40), c~&, BF
  489.     s2$ = STR$(value)
  490.     s3$ = LTRIM$(RTRIM$(s2$))
  491.     s$ = label$ + " = " + s3$
  492.     _PRINTSTRING (x + 384 - 4 * LEN(s$), y + 12), s$
  493.  
  494.