QB64.org Forum

Active Forums => Programs => Topic started by: SierraKen on October 06, 2019, 12:05:39 am

Title: Paint Pixels 4
Post by: SierraKen on October 06, 2019, 12:05:39 am
Tonight I decided to finally spruce up and finish my old Paint Pixels saga. lol This is the drawing program I made over a month ago that uses the mouse to draw and an awesome color picker that B+ gave me to use. You can also save, load, and print on the printer. The reason I never finished it was because I was bummed that I had used the wrong code making JPG pictures. Instead I was just actually saving .bmp code as a .jpg name. So I changed it to only use .bmp pictures like the code is supposed to do. I also fixed one major problem I had with renaming the temp.bmp, which for some reason wouldn't change to the name you wanted if that name already existed. So I used SHELL to delete the old one and then rename temp.bmp to the new name you want it to be. Thanks also to B+ for the code I used on my calendar making program that rotates a picture 180 degrees to print on the printer as a landscape rather than what it was before and squishing your picture to a letter size on the paper. Thanks B+, I also kept your name as well as mine on the credits on the welcome screen. Plus I edited a tiny bit on some text within the program to make it look a little better. Please tell me what you think of this little program. I know Windows Paint is better, but I like how you can paint with this program on a FULL screen with nothing else on your entire screen as you paint. I am really happy it's finally finished, unless of course someone finds a problem with it that I need to fix. Thank you.
Here it is:
Code: QB64: [Select]
  1. 'This program was finished on October 5, 2019.
  2. 'Technical Notes:
  3. 'This program uses around 55 MB RAM and 1% of the CPU on my semi-new computer.
  4. 'Use at your own risk. I hold no responsibility for any problems whatsoever.
  5. '
  6. 'Thank you to B+ from the QB64.org forum for the color picker and the picture rotation code!
  7. '-------------------------------------------------------------------------------------------
  8. _LIMIT 100
  9. start:
  10. _TITLE "Paint Pixels 4"
  11. WIDTH 40, 43
  12. _SCREENMOVE 400, 200
  13. PRINT "        Paint Pixels 4"
  14. PRINT "       By Ken G. and B+"
  15. PRINT "Use your mouse to paint on a"
  16. PRINT "full screen."
  17. PRINT "You also can make lines: (R)ays,"
  18. PRINT "circles: (O)rbits, and (B)oxes."
  19. PRINT "You also can print to"
  20. PRINT "your USB printer as well as edit"
  21. PRINT "an old picture file."
  22. PRINT "It saves under .bmp files which can"
  23. PRINT "be used with most other programs."
  24. PRINT "Press the Space Bar to"
  25. PRINT "skip instructions."
  26. PRINT "Press Esc to end program."
  27. PRINT "Press any other key to continue."
  28. gggo:
  29. _LIMIT 100
  30. ecc$ = INKEY$
  31. IF ecc$ = " " THEN GOTO start2:
  32. IF ecc$ = CHR$(27) THEN END
  33. IF ecc$ = "" THEN GOTO gggo:
  34. PRINT "       Instructions"
  35. PRINT "(S)ave (L)oad (H)ome"
  36. PRINT "(R)ay coordinates for line."
  37. PRINT "Press R once to start line"
  38. PRINT "and again to finish it."
  39. PRINT "(O)rbit coordinates for circles."
  40. PRINT "Press O once to start circle."
  41. PRINT "and again to finish it."
  42. PRINT "The size of the circle depends"
  43. PRINT "on the length difference"
  44. PRINT "between where you pressed O"
  45. PRINT "both times. The center of the circle"
  46. PRINT "will be the first place you pressed O."
  47. PRINT "(B)oxes are the same way as (O)rbits."
  48. PRINT "(P)rints the picture on"
  49. PRINT "your printer. It will not work"
  50. PRINT "if you choose a black background"
  51. PRINT "because of heavy ink or toner use."
  52. PRINT "To go around that, choose a white"
  53. PRINT "background and on the color picker"
  54. PRINT "window, choose black and press F"
  55. PRINT "to fill entire window."
  56. PRINT "Esc to end program."
  57. PRINT "Space Bar clears the screen."
  58. PRINT "Left Mouse Button draws."
  59. PRINT "Right Mouse Button erases."
  60. PRINT "There is no Undo feature on"
  61. PRINT "this program."
  62. PRINT "Press Esc to end program or"
  63. PRINT "any other key to continue."
  64. ggggo:
  65. _LIMIT 100
  66. ecc2$ = INKEY$
  67. IF ecc2$ = CHR$(27) THEN END
  68. IF ecc2$ = "" THEN GOTO ggggo:
  69. PRINT "    Instructions Page 2"
  70. PRINT "(C)olor changes colors."
  71. PRINT "A window will come up to use"
  72. PRINT "your mouse to choose a color."
  73. PRINT "This will also happen when you"
  74. PRINT "first start your painting."
  75. PRINT "(B)oxes makes a filled box."
  76. PRINT "First press B once to start the"
  77. PRINT "box corner, then press B again"
  78. PRINT "to set the 2nd corner and size"
  79. PRINT "diagonally from the first one."
  80. PRINT "Paint slowly to leave out gaps."
  81. PRINT "When you press S to save,"
  82. PRINT "the program will create a temp.bmp"
  83. PRINT "of the screen and when asking you"
  84. PRINT "for a file name, it will rename temp.bmp"
  85. PRINT "to your chosen name."
  86. PRINT "Press Esc to end program or"
  87. PRINT "any other key to start."
  88. gggggo:
  89. _LIMIT 1000
  90. s$ = INKEY$
  91. IF s$ = "" THEN GOTO gggggo:
  92. IF s$ = CHR$(27) THEN END
  93. start2:
  94. begin = 1
  95. PRINT "Background Color"
  96. PRINT "(B)lack (W)hite"
  97. PRINT "Or Esc to end program."
  98. start3:
  99. _LIMIT 1000
  100. bcolor$ = INKEY$
  101. IF bcolor$ = CHR$(27) THEN END
  102. IF bcolor$ = "" THEN GOTO start3:
  103. IF bcolor$ = "w" OR bcolor$ = "W" THEN
  104.     s& = _NEWIMAGE(640, 480, 32)
  105.     SCREEN s&
  106.     LINE (0, 0)-(640, 480), _RGB(255, 255, 255), BF
  107.     GOTO more2:
  108. IF bcolor$ = "B" OR bcolor$ = "b" THEN
  109.     s& = _NEWIMAGE(640, 480, 32)
  110.     SCREEN s&
  111.     CLS
  112.     GOTO more2:
  113. GOTO start3:
  114. more2:
  115. begin = 1
  116. GOSUB chosencolor:
  117. '---------------------------------------------------
  118. 'Here is the main loop of the program when painting.
  119. '---------------------------------------------------
  120.     _LIMIT 1000
  121.         mouseX = _MOUSEX
  122.         mouseY = _MOUSEY
  123.         mouseLeftButton = _MOUSEBUTTON(1)
  124.         mouseRightButton = _MOUSEBUTTON(2)
  125.         mouseMiddleButton = _MOUSEBUTTON(3)
  126.     LOOP
  127.     IF mouseLeftButton = -1 THEN
  128.         LINE (mouseX, mouseY)-(mouseX + 1, mouseY + 1), clr~&, BF
  129.     END IF
  130.     IF mouseRightButton = -1 THEN
  131.         LINE (mouseX, mouseY)-(mouseX + 1, mouseY + 1), 0, BF
  132.     END IF
  133.     a$ = INKEY$
  134.     'Here is when someone whipes the screen blank with the space bar.
  135.     IF a$ = " " THEN GOTO start2:
  136.     IF a$ = CHR$(27) THEN END
  137.     IF a$ = "s" OR a$ = "S" THEN GOTO saving:
  138.     IF a$ = "l" OR a$ = "L" THEN GOSUB loading:
  139.     IF a$ = "h" OR a$ = "H" THEN GOTO start:
  140.     'Here is code needed to call up the Windows Color Picker.
  141.     'It also uses the code on top of this program and the Function at the end
  142.     'of this program.
  143.     IF a$ = "c" OR a$ = "C" THEN
  144.         chosencolor:
  145.         check$ = colorDialog$
  146.         IF check$ <> "" THEN clr~& = VAL(check$) ELSE clr~& = &HFF0000FF '<<< I am blue if colorDialog does not work
  147.  
  148.         IF begin = 1 THEN begin = 0: RETURN
  149.     END IF
  150.     'Here is the Ray Lines code.
  151.     IF a$ = "r" OR a$ = "R" THEN
  152.         ck = ck + 1
  153.         IF ck > 1 THEN GOTO ray:
  154.         xxx = mouseX: yyy = mouseY
  155.         LINE (mouseX, mouseY)-(mouseX + 1, mouseY + 1), clr~&, BF
  156.         GOTO firstray:
  157.         ray:
  158.         LINE (mouseX, mouseY)-(xxx, yyy), clr~&
  159.         xxx = 0: yyy = 0
  160.         ck = 0
  161.         firstray:
  162.     END IF
  163.     'Here is the Orbit Circles code.
  164.     IF a$ = "o" OR a$ = "O" THEN
  165.         ck2 = ck2 + 1
  166.         IF ck2 > 1 THEN GOTO orbit:
  167.         xxx2 = mouseX: yyy2 = mouseY
  168.         GOTO firstorbit:
  169.         orbit:
  170.         IF mouseX < xxx2 THEN size = xxx2 - mouseX
  171.         IF mouseX > xxx2 THEN size = mouseX - xxx2
  172.         IF mouseY < yyy2 THEN size2 = yyy2 - mouseY
  173.         IF mouseY > yyy2 THEN size2 = mouseY - yyy2
  174.         size3 = INT((size + size2) / 2)
  175.         CIRCLE (xxx2, yyy2), size3, clr~&
  176.         xxx2 = 0: yyy2 = 0
  177.         size = 0: size2 = 0: size3 = 0
  178.         ck2 = 0
  179.         firstorbit:
  180.     END IF
  181.     'Here is the Boxes code.
  182.     IF a$ = "b" OR a$ = "B" THEN
  183.         ck3 = ck3 + 1
  184.         IF ck3 > 1 THEN GOTO box:
  185.         xxx3 = mouseX: yyy3 = mouseY
  186.         GOTO firstbox:
  187.         box:
  188.         LINE (mouseX, mouseY)-(xxx3 + 1, yyy3 + 1), clr~&, BF
  189.         xxx3 = 0: yyy3 = 0
  190.         ck3 = 0
  191.         firstbox:
  192.     END IF
  193.     'Here is the Printing of the picture.
  194.     IF a$ = "p" OR a$ = "P" THEN
  195.         IF bcolor$ = "w" OR bcolor$ = "W" THEN
  196.             j& = _COPYIMAGE(0)
  197.             _DELAY .25
  198.             INPUT "Print on printer (Y/N)?", i$ 'print screen page on printer
  199.             CLS
  200.             SCREEN j&
  201.             _DELAY .25
  202.             IF LEFT$(i$, 1) = "y" OR LEFT$(i$, 1) = "Y" THEN
  203.                 'printer prep (code copied and pasted from bplus Free Calendar Program)
  204.                 YMAX = _HEIGHT: XMAX = _WIDTH
  205.                 landscape& = _NEWIMAGE(YMAX, XMAX, 32)
  206.                 _MAPTRIANGLE (XMAX, 0)-(0, 0)-(0, YMAX), 0 TO(0, 0)-(0, XMAX)-(YMAX, XMAX), landscape&
  207.                 _MAPTRIANGLE (XMAX, 0)-(XMAX, YMAX)-(0, YMAX), 0 TO(0, 0)-(YMAX, 0)-(YMAX, XMAX), landscape&
  208.                 _PRINTIMAGE landscape&
  209.                 _DELAY 2
  210.                 landscape& = 0
  211.                 j& = 0
  212.             END IF
  213.         END IF
  214.     END IF
  215.  
  216. 'Saving
  217. 'This section first saves your picture as temp.bmp and then
  218. 'asks you a name for your picture and then renames temp.bmp to your name.
  219. saving:
  220. 'Now we call up the SUB to save the image to BMP.
  221. SaveImage 0, "temp.bmp"
  222. _DELAY .25
  223. PRINT "                       Saving"
  224. PRINT "         Your bmp file will be saved in the"
  225. PRINT "         same directory as this program is."
  226. PRINT "         It can be used with almost any"
  227. PRINT "         other graphics program or website."
  228. PRINT "         It is saved using:"
  229. PRINT "         width: 640  height: 480 pixels."
  230. PRINT "         Type a name to save your picture"
  231. PRINT "         and press the Enter key. Do not"
  232. PRINT "         add .bmp at the end, the program"
  233. PRINT "         will do it automatically."
  234. PRINT "         Also do not use the name temp"
  235. PRINT "         because the program uses that name"
  236. PRINT "         and it would be erased the next time"
  237. PRINT "         you save a picture."
  238. PRINT "         Example: MyPic"
  239. PRINT "         Quit and Enter key ends program."
  240. INPUT "         ->"; nm$
  241. IF nm$ = "Quit" OR nm$ = "quit" OR nm$ = "QUIT" THEN END
  242. nm$ = nm$ + ".bmp"
  243. 'Checking to see if the file already exists on your computer.
  244. theFileExists = _FILEEXISTS(nm$)
  245. IF theFileExists = -1 THEN
  246.     PRINT "       File Already Exists"
  247.     PRINT "       Saving will delete your old"
  248.     PRINT "       bmp picture."
  249.     PRINT "       Would you like to still do it?"
  250.     PRINT "      (Y/N). Esc ends program."
  251.     llloop:
  252.     _LIMIT 100
  253.     ag2$ = INKEY$
  254.     IF ag2$ = CHR$(27) THEN END
  255.     IF ag2$ = "" THEN GOTO llloop:
  256.     IF ag2$ = "y" OR ag$ = "Y" THEN
  257.         SHELL _HIDE "DEL " + nm$
  258.         GOTO saving2:
  259.     END IF
  260.     GOTO llloop:
  261. saving2:
  262. SHELL _HIDE "REN " + "temp.bmp" + " " + nm$
  263. nm$ = ""
  264. FOR snd = 100 TO 700 STEP 100
  265.     SOUND snd, 2
  266. NEXT snd
  267. GOTO start:
  268. loading: 'This section loads your picture from your computer.
  269. PRINT "                    Loading"
  270. PRINT "         Do not add .bmp at the end."
  271. PRINT "         The bmp picture must be in the same"
  272. PRINT "         directory as this program is."
  273. PRINT "         You will not be able to edit your"
  274. PRINT "         picture file with this program."
  275. PRINT "         Type the name of your picture file"
  276. PRINT "         here and press the Enter key."
  277. PRINT "         Example: MyPic"
  278. PRINT "         Quit and Enter key ends program."
  279. INPUT "         ->"; nm$
  280. IF nm$ = "Quit" OR nm$ = "quit" OR nm$ = "QUIT" THEN END
  281. nm$ = nm$ + ".bmp"
  282. theFileExists = _FILEEXISTS(nm$)
  283. IF theFileExists = 0 THEN
  284.     PRINT "         File Does Not Exist."
  285.     PRINT "         Would you like to try again (Y/N)"
  286.     PRINT "         Esc ends program."
  287.     _LIMIT 100
  288.     llloop2:
  289.     ag$ = INKEY$
  290.     IF ag$ = "" THEN GOTO llloop2:
  291.     IF ag$ = "y" OR ag$ = "Y" THEN GOTO loading:
  292.     IF ag$ = CHR$(27) THEN END
  293.     GOTO start:
  294. l = 0
  295. i& = _LOADIMAGE(nm$, 32)
  296. FOR snd2 = 100 TO 700 STEP 100
  297.     SOUND snd2, 2
  298. NEXT snd2
  299. s& = i&
  300. i& = 0
  301.  
  302. 'Here is the SUB needed to save the image to BMP.
  303. SUB SaveImage (image AS LONG, filename AS STRING)
  304.     bytesperpixel& = _PIXELSIZE(image&)
  305.     IF bytesperpixel& = 0 THEN PRINT "Text modes unsupported!": END
  306.     IF bytesperpixel& = 1 THEN bpp& = 8 ELSE bpp& = 24
  307.     x& = _WIDTH(image&)
  308.     y& = _HEIGHT(image&)
  309.     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)
  310.     IF bytesperpixel& = 1 THEN
  311.         FOR c& = 0 TO 255 ' read BGR color settings from JPG image + 1 byte spacer(CHR$(0))
  312.             cv& = _PALETTECOLOR(c&, image&) ' color attribute to read.
  313.             b$ = b$ + CHR$(_BLUE32(cv&)) + CHR$(_GREEN32(cv&)) + CHR$(_RED32(cv&)) + CHR$(0) 'spacer byte
  314.         NEXT
  315.     END IF
  316.     MID$(b$, 11, 4) = MKL$(LEN(b$)) ' image pixel data offset(BMP header)
  317.     lastsource& = _SOURCE
  318.     _SOURCE image&
  319.     IF ((x& * 3) MOD 4) THEN padder$ = STRING$(4 - ((x& * 3) MOD 4), 0)
  320.     FOR py& = y& - 1 TO 0 STEP -1 ' read JPG image pixel color data
  321.         r$ = ""
  322.         FOR px& = 0 TO x& - 1
  323.             c& = POINT(px&, py&) 'POINT 32 bit values are large LONG values
  324.             IF bytesperpixel& = 1 THEN r$ = r$ + CHR$(c&) ELSE r$ = r$ + LEFT$(MKL$(c&), 3)
  325.         NEXT px&
  326.         d$ = d$ + r$ + padder$
  327.     NEXT py&
  328.     _SOURCE lastsource&
  329.     MID$(b$, 35, 4) = MKL$(LEN(d$)) ' image size(BMP header)
  330.     b$ = b$ + d$ ' total file data bytes to create file
  331.     MID$(b$, 3, 4) = MKL$(LEN(b$)) ' size of data file(BMP header)
  332.     IF LCASE$(RIGHT$(filename$, 4)) <> ".bmp" THEN ext$ = ".bmp"
  333.     f& = FREEFILE
  334.     OPEN filename$ + ext$ FOR OUTPUT AS #f&: CLOSE #f& ' erases an existing file
  335.     OPEN filename$ + ext$ FOR BINARY AS #f&
  336.     PUT #f&, , b$
  337.     CLOSE #f&
  338.  
  339. FUNCTION colorDialog$
  340.  
  341.     'first screen dimensions items to restore at exit
  342.     DIM curRow AS INTEGER, curCol AS INTEGER, autoDisplay AS INTEGER
  343.     DIM curScrn AS LONG, backScrn AS LONG 'some handles
  344.  
  345.     DIM cd AS LONG
  346.     DIM makeConst$, k$
  347.     DIM f AS SINGLE
  348.  
  349.     'save old settings to restore at end ofsub
  350.     curRow = CSRLIN
  351.     curCol = POS(0)
  352.     autoDisplay = _AUTODISPLAY
  353.     sw = _WIDTH
  354.     sh = _HEIGHT
  355.     fg = _DEFAULTCOLOR
  356.     bg = _BACKGROUNDCOLOR
  357.     _KEYCLEAR
  358.     'screen snapshot
  359.     curScrn = _DEST
  360.     backScrn = _NEWIMAGE(sw, sh, 32)
  361.     _PUTIMAGE , curScrn, backScrn
  362.  
  363.     cd = _NEWIMAGE(800, 600, 32)
  364.     SCREEN cd
  365.     r = 128: g = 128: b = 128: a = 128
  366.     COLOR &HFFDDDDDD, 0
  367.     DO
  368.         CLS
  369.         makeConst$ = "&H" + RIGHT$(STRING$(8, "0") + HEX$(_RGBA32(r, g, b, a)), 8)
  370.         slider 16, 10, r, "Red"
  371.         slider 16, 60, g, "Green"
  372.         slider 16, 110, b, "Blue"
  373.         slider 16, 160, a, "Alpha"
  374.         _PRINTSTRING (150, 260), "Press enter or spacebar, if you want to use the color: " + makeConst$
  375.         _PRINTSTRING (210, 280), "Press escape or q, to not use any color, returns 0."
  376.         LINE (90, 300)-(710, 590), , B
  377.         FOR i = 100 TO 700
  378.             f = 255 * (i - 100) / 600
  379.             LINE (i, 310)-STEP(0, 30), _RGB32(f, 0, 0): LINE (i, 310)-STEP(0, 20), VAL(makeConst$)
  380.             LINE (i, 340)-STEP(0, 30), _RGB32(0, f, 0): LINE (i, 340)-STEP(0, 20), VAL(makeConst$)
  381.             LINE (i, 370)-STEP(0, 30), _RGB32(0, 0, f): LINE (i, 370)-STEP(0, 20), VAL(makeConst$)
  382.             LINE (i, 400)-STEP(0, 30), _RGB32(f, f, 0): LINE (i, 400)-STEP(0, 20), VAL(makeConst$)
  383.             LINE (i, 430)-STEP(0, 30), _RGB32(0, f, f): LINE (i, 430)-STEP(0, 20), VAL(makeConst$)
  384.             LINE (i, 460)-STEP(0, 30), _RGB32(f, 0, f): LINE (i, 460)-STEP(0, 20), VAL(makeConst$)
  385.             LINE (i, 490)-STEP(0, 30), _RGB32(f, f, f): LINE (i, 490)-STEP(0, 20), VAL(makeConst$)
  386.             LINE (i, 520)-STEP(0, 30), _RGB32(0, 0, 0): LINE (i, 520)-STEP(0, 20), VAL(makeConst$)
  387.             LINE (i, 550)-STEP(0, 30), _RGB32(255, 255, 255): LINE (i, 550)-STEP(0, 20), VAL(makeConst$)
  388.         NEXT
  389.         WHILE _MOUSEINPUT: WEND
  390.         mb = _MOUSEBUTTON(1)
  391.         IF mb THEN 'clear it
  392.             mx = _MOUSEX: my = _MOUSEY
  393.             IF mx >= 16 AND mx <= 781 THEN
  394.                 IF my >= 10 AND my <= 50 THEN
  395.                     r = INT((mx - 16) / 3)
  396.                 ELSEIF my >= 60 AND my <= 100 THEN
  397.                     g = INT((mx - 16) / 3)
  398.                 ELSEIF my >= 110 AND my <= 150 THEN
  399.                     b = INT((mx - 16) / 3)
  400.                 ELSEIF my >= 160 AND my <= 200 THEN
  401.                     a = INT((mx - 16) / 3)
  402.                 END IF
  403.             END IF
  404.         END IF
  405.         k$ = INKEY$
  406.         IF LEN(k$) THEN
  407.             IF ASC(k$) = 27 OR k$ = "q" THEN EXIT DO
  408.             IF ASC(k$) = 13 OR k$ = " " THEN colorDialog$ = makeConst$: EXIT DO
  409.         END IF
  410.         _DISPLAY
  411.         _LIMIT 60
  412.     LOOP
  413.  
  414.     'put things back
  415.     SCREEN curScrn
  416.     COLOR _RGB32(255, 255, 255), _RGB32(0, 0, 0): CLS
  417.     _PUTIMAGE , backScrn
  418.     _DISPLAY
  419.     COLOR fg, bg
  420.     _FREEIMAGE backScrn
  421.     _FREEIMAGE cd
  422.     IF autoDisplay THEN _AUTODISPLAY
  423.     'clear key presses
  424.     _KEYCLEAR
  425.     'clear mouse clicks
  426.     mb = _MOUSEBUTTON(1)
  427.     IF mb THEN 'clear it
  428.         WHILE mb 'OK!
  429.             IF _MOUSEINPUT THEN mb = _MOUSEBUTTON(1)
  430.             _LIMIT 10
  431.         WEND
  432.     END IF
  433.     LOCATE curRow, curCol
  434.  
  435.  
  436. SUB slider (x, y, value, label$)
  437.     DIM c~&, s$
  438.     SELECT CASE label$
  439.         CASE "Red": c~& = &HFFFF0000
  440.         CASE "Green": c~& = &HFF008800
  441.         CASE "Blue": c~& = &HFF0000FF
  442.         CASE "Alpha": c~& = &H88FFFFFF
  443.     END SELECT
  444.     LINE (x, y)-STEP(765, 40), c~&, B
  445.     LINE (x, y)-STEP(3 * value, 40), c~&, BF
  446.     s2$ = STR$(value)
  447.     s3$ = LTRIM$(RTRIM$(s2$))
  448.     s$ = label$ + " = " + s3$
  449.     _PRINTSTRING (x + 384 - 4 * LEN(s$), y + 12), s$
  450.  


Title: Re: Paint Pixels 4
Post by: euklides on October 06, 2019, 03:46:38 am
Nothing happens when I press "space" or "enter"...
What is wrong ?

...
What interesting is, in this program, is the fact to choice easily a color and get his code.
Why not put this color code in the "_clipboard", for instance to use it when creating QB64 program using colors ? ...

Title: Re: Paint Pixels 4
Post by: bplus on October 06, 2019, 10:14:55 am

...
What interesting is, in this program, is the fact to choice easily a color and get his code.
Why not put this color code in the "_clipboard", for instance to use it when creating QB64 program using colors ? ...

;-))  done!  https://www.qb64.org/forum/index.php?topic=1755.msg109987#msg109987


Quote
Nothing happens when I press "space" or "enter"...
What is wrong ?

It took me a couple of tries = reads of Ken's instruction But if you press space bar at opening screen you will skip instructions, just as Ken instructed. You do have to read carefully, it is not super intuitive, but on my test all seems to work as Ken describes.

I was surprised that the Orbit draws half the radius or diameter I was expecting and is it circle or ellipse? I do like Ray drawing, maybe it could use LINE -STEP for repeating R's so don't have click start points all the time but draw next Ray from last point R was pressed?? Maybe go into a R mode with one R press and then draw line from point to point clicked of course then you need R press again to toggle R mode off, something like that? BTW THAT would also fill in all those dots when just sweeping the mouse around the screen.

(More): THEN with completely enclosed areas you could use PAINT to fill them in ie PAINT to border of last Color you draw with?



 

Title: Re: Paint Pixels 4
Post by: SierraKen on October 06, 2019, 12:13:02 pm
Thanks B+. Yeah awhile back I tried to fill things in but for some reason it doesn't work well, especially when the program often leaves gaps when you don't draw slow enough. I'll look into the rays and ovals better. They were just something I threw on there in the beginning. Going from point to point on the rays seems like a good idea, I will try to make it off and on, so people can turn it off and then go to a separate location and turn it back on if they want to put a ray somewhere else. Awesome idea, thanks!
Euk., I'm not sure why you are getting that problem, everything seems to work on my end, but I'll look into it later today.
Thanks you 2!

Edit: I think the hardest thing about using the PAINT command is that it requires the same color as the border around it. So if someone chooses a different color than the border, it won't work.
Title: Re: Paint Pixels 4
Post by: SierraKen on October 06, 2019, 05:44:58 pm
OK, I brightened the instructions and made it easier to read. I also changed the way the orbits (circles) are made that is a bit better. I used my SIN and COS code instead. But as I say in the instructions, the more diagonal your 2 presses of the key O are apart, the more of a circle it will be. If they are horizontal or vertical, they will be almost a straight line instead. I tried to change the Rays (lines) as off and on, but figured out that it would be too difficult to remember the right keys to press to turn off and on AND make the rays. You can't just use the R key for both, so I gave up on that. Thankfully it does leave a mark on where the line starts so you know where that is when you press the second R to make the line. I also changed the (H)ome key to (I)nstructions to make it easier to remember if you need to read the instructions again. That's all I've done so far. Here is the newest version:

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

Here is code change to make R toggle on and off and to draw straight lines from click to click while in R mode.

Code: QB64: [Select]
  1.     'Here is the Ray Lines code.
  2.     IF a$ = "r" OR a$ = "R" THEN
  3.         rMode = 1 - rMode
  4.         IF rMode THEN lastx = mouseX: lastY = mouseY 'set first lastx, lasty
  5.         'ck = ck + 1
  6.         'IF ck > 1 THEN GOTO ray:
  7.         'xxx = mouseX: yyy = mouseY
  8.         'LINE (mouseX, mouseY)-(mouseX + 1, mouseY + 1), clr~&, BF
  9.         'GOTO firstray:
  10.         'ray:
  11.         'LINE (mouseX, mouseY)-(xxx, yyy), clr~&
  12.         'xxx = 0: yyy = 0
  13.         'ck = 0
  14.         'firstray:
  15.     END IF
  16.     IF rMode AND mouseLeftButton THEN LINE (lastx, lastY)-(mouseX, mouseY), clr~&: lastx = mouseX: lastY = mouseY
  17.  

You can click straight lines or drag mouse around with left button pressed to draw continuous line.
Title: Re: Paint Pixels 4
Post by: SierraKen on October 06, 2019, 07:00:24 pm
That is so awesome. Thanks again B+!!! I added it to my program. I also drew 2 examples that people can do with this program. This program has turned from a simple experimental program to something pretty high-tech, in my opinion.

Here is the update:

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

Title: Re: Paint Pixels 4
Post by: bplus on October 06, 2019, 11:47:26 pm
Well I am grinning from ear to ear! Glad you liked it.
Title: Re: Paint Pixels 4
Post by: SierraKen on October 07, 2019, 12:26:17 am
I updated the instructions better for the new way to make rays (lines).

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

Have you realized yet, what we did for Rays we can also do also for Orbit (modeO or Omode) and Boxes (Bmode) when in those modes the first click sets the x1, y1 center for Orbit and the 2nd sets the corner for Box or Orbit Ellipse/Circle to draw.

PLUS!!!! you can _putimage of a snap shot / copy of the main screen at the beginning of a loop as back ground and then as mouse moves around in say the Rmode, you can show a ray from X1, y1 to MouseX, MouseY until user clicks the mouse again which will "set" the ray where mouse is permanently by taking a snapshot of the picture. You build the picture from snapshots at every second click in O or B mode and every click in R mode and every mouse move in No Mode.
Title: Re: Paint Pixels 4
Post by: SierraKen on October 07, 2019, 12:37:50 pm
Wow B+, I knew there was a way to do this, but I had no idea where to start. I will look into this real soon. That would make circles, boxes, and rays a LOT easier to work with. Thanks, I have to do some things but if I have time I'll get to it later today.
Title: Re: Paint Pixels 4
Post by: SierraKen on October 07, 2019, 05:41:15 pm
I am SOOO close! But I came to (hopefully) a small snag. I'm using _COPYIMAGE and _PUTIMAGE and whenever the finished image is put on the screen, that you place a ray with using the mouse, the whole screen moves down a couple of pixels. I have no idea why. I've looked the numbers over many times and don't understand why this is happening. Is it a fluke with _FULLSCREEN ? Anyway, please check it out and see if you can help me. I haven't done the orbits or boxes yet except I have put all of them in their own modes now, as you suggested, and they work great with those! I just want to use the mouse with _PUTIMAGE like you said. Thank you. If we can figure this out, then we can figure out the orbits and boxes very easily.
On a side note, I found a problem using the right mouse button to erase, so I fixed that. I think I never finished that part to begin with, so that's good now.
This will be called Paint Pixels 5.

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

Title: Re: Paint Pixels 4
Post by: SierraKen on October 07, 2019, 06:01:33 pm
I removed a COPYIMAGE and a PUTIMAGE since they were not needed, but it still does the same thing, pushing the bottom part of the screen down a few pixels every time I press R.

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

I don't think I want to wade through all your goto's :P

But on line 196 I see a CopyImage statement, that I thought you removed?

This is in the wrong place anyway. A snapshot of the screen should be after drawing a line with the end point clicked in.

Before then you are drawing lines from first click to mouse position but NOT saving the screen image.

To save a screen image, I prefer this method:
1. set up a new handle say picture&
picture& = _newimage(numbers same as screen setup) 'this is your storage container

when the 2nd point is clicked in for Ray:

_putimage , 0, picture&   'source to destination = screen to container

then at beginning of next drawing loop erase old screen by placing the image in picture& contain to screen:
_putimage , picture& , 0 ' container to screen  'always right after the start of loop

Code: QB64: [Select]
  1. 'Here is the Ray Lines code.
  2.     IF a$ = "r" OR a$ = "R" THEN
  3.         rMode = 1 - rMode
  4.         IF rMode THEN
  5.             lastx = mouseX: lastY = mouseY 'set first lastx, lasty
  6.             ''''''''''''''''''''''''''''''j& = _COPYIMAGE(0)
  7.         END IF
  8.     END IF
  9.  
  10.     IF rMode THEN
  11.         LINE (lastx, lastY)-(mouseX, mouseY), clr~&
  12.         '_display 'if you are using it
  13.         if mouseLeftButton = -1 then _putimage , 0, picture&
  14.     end if
  15.  
  16.  
Title: Re: Paint Pixels 4
Post by: SierraKen on October 07, 2019, 08:04:36 pm
Interesting. I think I just tried your code but when I move the mouse without pressing the mouse button, it just makes a bunch of lines without animating the line first before you place it. This is what I have so far for this section. I'm not sure if I have the _NEWIMAGE code in the right place either. 

Edit: See, I was using the _PUTIMAGE to put the entire screen back to where it was when you moved the line around without placing it yet.


Code: QB64: [Select]
  1.     'Here is the Ray Lines code.
  2.     IF a$ = "r" OR a$ = "R" THEN
  3.         rMode = 1 - rMode
  4.         IF rMode THEN
  5.             lastx = mouseX: lastY = mouseY 'set first lastx, lasty
  6.             picture& = _NEWIMAGE(640, 480, 32)
  7.         END IF
  8.     END IF
  9.     IF rMode THEN
  10.         LINE (lastx, lastY)-(mouseX, mouseY), clr~&
  11.         '_display 'if you are using it
  12.         IF mouseLeftButton = -1 THEN _PUTIMAGE , 0, picture&
  13.     END IF
  14.  
Title: Re: Paint Pixels 4
Post by: bplus on October 07, 2019, 08:23:12 pm
picture& = _NEWIMAGE(640, 480, 32)   near start of program

My code is right, need _putimage , picture&, 0

right after main loop starts over again.

Dang! not 5 mins of Browns Game, and another frickin 5 minutes of commercials!

Dang! touchdown on first play!

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

Browns are doing poorly
Title: Re: Paint Pixels 4
Post by: SierraKen on October 07, 2019, 09:13:36 pm
Am sorry to say that I did everything you said, but no luck. After you press R and just move the mouse, it makes a bunch of lines wherever you move the mouse and the lines stay there.
When you press the mouse button, then it starts to work right, the animated line starts. The R key seems to work fine because you can still use that to make different lines in different locations. The only problem is that as soon as you start a new location, the line doesn't animate, it just makes a bunch of them.


I put this on line 11 before the welcome text:

Code: QB64: [Select]
  1. picture& = _NEWIMAGE(640, 480, 32)    
  2.  

I put this right after the _LIMIT 1000 and right before that is the start of the main DO loop:

Code: QB64: [Select]
  1.   _PUTIMAGE , picture&, 0  
  2.  

And here is the Ray code:

Code: QB64: [Select]
  1.     'Here is the Ray Lines code.
  2.     IF a$ = "r" OR a$ = "R" THEN
  3.         rMode = 1 - rMode
  4.         IF rMode THEN
  5.             lastx = mouseX: lastY = mouseY 'set first lastx, lasty
  6.             picture& = _NEWIMAGE(640, 480, 32)
  7.         END IF
  8.     END IF
  9.     IF rMode THEN
  10.         LINE (lastx, lastY)-(mouseX, mouseY), clr~&
  11.         '_DISPLAY 'if you are using it
  12.         IF mouseLeftButton = -1 THEN _PUTIMAGE , 0, picture&
  13.     END IF
  14.  

And if anyone is interested, here's all of the code:

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

well it's working correctly (just the Ray stuff is all I changed and checked) in update in reply above.

Parts of interest:
Code: QB64: [Select]
  1. IF bcolor$ = "w" OR bcolor$ = "W" THEN
  2.     '_FULLSCREEN
  3.     s& = _NEWIMAGE(640, 480, 32)
  4.     picture& = _NEWIMAGE(640, 480, 32)  '<<<<<<<<<<<<<<<<<<
  5.  
  6.     LINE (0, 0)-(640, 480), _RGB(255, 255, 255), BF
  7.     _PUTIMAGE , s&, picture&  '<<<<<<<<<<<<<<<<<<<<<<<<< hmm, not tested and different than black?
  8.     GOTO more2:
  9. IF bcolor$ = "B" OR bcolor$ = "b" THEN
  10.     '_FULLSCREEN
  11.     s& = _NEWIMAGE(640, 480, 32)
  12.     picture& = _NEWIMAGE(640, 480, 32)  '<<<<<<<<<<<<<<<<<,
  13.  
  14.  
  15.     SCREEN s&
  16.     CLS
  17.     GOTO more2:
  18. GOTO start3:
  19. more2:
  20. begin = 1
  21. GOSUB chosencolor:
  22. '---------------------------------------------------
  23. 'Here is the main loop of the program when painting.
  24. '---------------------------------------------------
  25.     _LIMIT 1000
  26.     _PUTIMAGE , picture&, s& '<<<<<<<<<<<<<<<,
  27.     SCREEN s&                       '<<<<<<<<<<<<<<<
  28.  

Code: QB64: [Select]
  1.     'Here is the Ray Lines code.
  2.     IF a$ = "r" OR a$ = "R" THEN
  3.         rMode = 1 - rMode
  4.         IF rMode THEN lastx = mouseX: lastY = mouseY 'set first lastx, lasty
  5.     END IF
  6.     IF rMode THEN
  7.         LINE (lastx, lastY)-(mouseX, mouseY), clr~&
  8.         IF mouseLeftButton THEN lastx = mouseX: lastY = mouseY: _PUTIMAGE , s&, picture&
  9.     END IF
  10.  
Title: Re: Paint Pixels 4
Post by: bplus on October 07, 2019, 09:43:59 pm
OK White did need fixed:
Code: QB64: [Select]
  1. IF bcolor$ = "w" OR bcolor$ = "W" THEN
  2.     '_FULLSCREEN
  3.     s& = _NEWIMAGE(640, 480, 32)
  4.     picture& = _NEWIMAGE(640, 480, 32)
  5.     SCREEN s&
  6.     LINE (0, 0)-(640, 480), _RGB32(255, 255, 255), BF
  7.     _PUTIMAGE , s&, picture&
  8.     GOTO more2:
  9.  

BTW nothing else will draw but R mode until you set them up like Rmode.
Title: Re: Paint Pixels 4
Post by: SierraKen on October 07, 2019, 11:03:50 pm
AWESOME!!! Thanks B+!!! I got the lines down pact now. Now I will work on the rest. Also, I like how you commented out the FULLSCREEN, I like it as a window better too. Now I can add some things on the TITLE bar.
Title: Re: Paint Pixels 4
Post by: bplus on October 07, 2019, 11:15:52 pm
Good! sounds like you have it working. _DISPLAY just before the LOOP back around should stop the blinking.

Trouble is, once you start using display you have to _display everything you want seen until execution sees _DISPLAY again unless you switch it off with _AUTODISPLAY.
Title: Re: Paint Pixels 4
Post by: SierraKen on October 08, 2019, 01:59:28 am
Whew, I almost stayed up until midnight on this one, but I think I have finished it! I tried the _DISPLAY in a few different areas but couldn't get it right so I just left it out, there's no need for it.
Everything works just the way I want it I think. The funny thing is, it took me longer to re-make the welcome screens and _TITLE bar info than anything else tonight. When someone changes a Mode, the Title Bar says what mode it's in. It also says almost all the commands for people to easily use the program. The only things it doesn't say is Space Bar, Esc, and (I)nstructions but I have those explained in the welcome screens. I also re-arranged the welcome screens to look a lot better. Now people don't have to cherry pick through my endless text to find what they need. lol
Oh also, I did another printer test with it and it automatically changes a 640x480 picture to a full piece of paper just about, just so you know. Which is good in my opinion. It makes the pictures stand out.
So here it is!!! Almost 3 months in the making... Thanks again B+ for all the help. I'll put it on my website in a day or 2 most likely.

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

Title: Re: Paint Pixels 4
Post by: SierraKen on October 08, 2019, 03:13:28 pm
LOL like usual I spoke too soon. Working on the _TITLE stuff last night I put code the wrong locations. So I fixed it today and I also changed the size of the paint area to 800 x 600, which nowadays is the usual picture size for drawing. I also just ran another printer test and found out that the screen turns black after you print, so I fixed that. I made it so people can still draw on the same drawing after it prints on paper and the drawing is not lost.

Here is the fixed version:

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

I think if you use just use one variable for mode number, you can dump all the toggles, ie mode = 1 drawing, mode = 2 Rays mode = 3 Orbits... that way one variable tracks it all. When you change modes with keypress remember to initialize the lastX and lastY and of course the Title.
Title: Re: Paint Pixels 4
Post by: SierraKen on October 08, 2019, 06:15:01 pm
That's exactly what I did B+, m=1, m=2, m=3, m=4, and m=5 are all different modes. I did that so things don't get confused and also to say, ie. If m=4 and oMode=0 then... where I put a _TITLE with all the modes off. That's how I fixed it with the last update I posted earlier.
Title: Re: Paint Pixels 4
Post by: SierraKen on October 08, 2019, 07:48:54 pm
Paint Pixels 5 is now on my website and I consider it finished. I've tested it a lot and everything seems to work fine. Thank you again B+ for all your help. So unless someone finds a bad problem with it, I'm not going to work on it any time soon I think.

Here is my website with all 29 programs on it. There is a link to this program on the top of the list. I also added an example .bmp picture to show people what it can make. It's a 800 x 600 picture of a jet. I'm no artist but I think it's neat. :)

http://www.KensPrograms.com/ (http://www.KensPrograms.com/)

Thank you.
Title: Re: Paint Pixels 4
Post by: STxAxTIC on October 08, 2019, 08:38:48 pm
Had fun playing with this Ken - nice use of the alpha. Maybe version 6 will have a toolbar like paint?

Actually, come to think of it, with all the stuff QB64 can do with multiple pages, images, alpha, we could make a DANK photoshop clone. Well, "clone". You all know what I mean.

If anyone wants to frame this out, I can help with the parts that I'd be good at. I'm thinking curved gradients and stuff you want calculus for. But the rest is pure QB64 legwork. This can be that holy grail group project we've been wondering how to start. Any takers?
Title: Re: Paint Pixels 4
Post by: SierraKen on October 08, 2019, 09:49:25 pm
Thanks Static!
Wow that would be an amazing project. Feel free to use any of my code from Paint Pixels. But me being the lesser of the programmers in here, I would mostly just watch and test it for you guys. :))
Title: Re: Paint Pixels 4
Post by: Petr on October 09, 2019, 02:29:38 pm
Very interesting work. I'm interested in it. I did a bit of an ape after drawing in Windows, so far only a few things work, it has been a while since I wrote it. In the end I interrupted it, now I don't even know why...


  [ This attachment cannot be displayed inline in 'Print Page' view ]  
Title: Re: Paint Pixels 4
Post by: bplus on October 09, 2019, 05:04:49 pm
Hi Ken,

Here is how I would do Undo and some other things, mouse down starts draw object, mouse release is finishes:
Code: QB64: [Select]
  1. _TITLE "Quick Draw" 'b+ 2019-10-09
  2.  
  3. CONST xmax = 800, ymax = 600
  4. SCREEN _NEWIMAGE(xmax, ymax, 32)
  5. _SCREENMOVE 300, 100
  6. FOR i = 0 TO 9
  7.     d&(i) = _NEWIMAGE(xmax, ymax, 32)
  8.     _PUTIMAGE , 0, d&(i)
  9. t$ = "Menu: <L>ine <F>rame <B>ox <E>llipse <D>isk <C>olor CL<S> <U>ndo"
  10. m$ = "L": _TITLE t$ + "  Drawing Lines"
  11. p = 0
  12. _PUTIMAGE , 0, d&(p)
  13. c~& = &HFFFFFFFF
  14.     _PUTIMAGE , d&(p), 0
  15.     k$ = UCASE$(INKEY$)
  16.     IF k$ = "L" THEN ' rays
  17.         m$ = "L": _TITLE t$ + "  Drawing Lines"
  18.     ELSEIF k$ = "E" THEN ' orbits (cool name BTW)
  19.         m$ = "E": _TITLE t$ + "  Drawing Ellipse"
  20.     ELSEIF k$ = "F" THEN
  21.         m$ = "F": _TITLE t$ + "  Drawing Frames"
  22.     ELSEIF k$ = "B" THEN ' Boxes
  23.         m$ = "B": _TITLE t$ + "  Drawing Boxes"
  24.     ELSEIF k$ = "D" THEN
  25.         m$ = "D": _TITLE t$ + "  Drawing Disks"
  26.     ELSEIF k$ = "C" THEN
  27.         changeColor
  28.         CLS
  29.         _PUTIMAGE , d&(p), 0
  30.     ELSEIF k$ = "S" THEN
  31.         CLS
  32.         _PUTIMAGE , 0, d&(p)
  33.     ELSEIF k$ = "U" THEN
  34.         p = p - 1
  35.         IF p = -1 THEN p = 9
  36.     END IF
  37.     mxd = _MOUSEX: myd = _MOUSEY: mb = _MOUSEBUTTON(1): mxu = -1
  38.  
  39.     WHILE mb
  40.         mi = _MOUSEINPUT:
  41.         mxu = _MOUSEX: myu = _MOUSEY: mb = _MOUSEBUTTON(1)
  42.         CLS
  43.         _PUTIMAGE , d&(p), 0
  44.         IF mxu <> -1 THEN
  45.             SELECT CASE m$
  46.                 CASE "L": LINE (mxd, myd)-(mxu, myu), c~&
  47.                 CASE "F": LINE (mxd, myd)-(mxu, myu), c~&, B
  48.                 CASE "B": LINE (mxd, myd)-(mxu, myu), c~&, BF
  49.                 CASE "E"
  50.                     dx = ABS(mxd - mxu): dy = ABS(myd - myu)
  51.                     PSET (mxd, myd), &HFFFFFFFF
  52.                     Ell mxd, myd, dx, dy, 0
  53.                     LINE (mxd - dx, myd - dy)-STEP(2 * dx, 2 * dy), &HFFFFFFFF, B
  54.                 CASE "D"
  55.                     dx = ABS(mxd - mxu): dy = ABS(myd - myu)
  56.                     PSET (mxd, myd), &HFFFFFFFF
  57.                     Ell mxd, myd, dx, dy, 1
  58.                     LINE (mxd - dx, myd - dy)-STEP(2 * dx, 2 * dy), &HFFFFFFFF, B
  59.             END SELECT
  60.             _DISPLAY
  61.         END IF
  62.         _LIMIT 500
  63.     WEND
  64.     IF mxu <> -1 THEN
  65.         CLS
  66.         _PUTIMAGE , d&(p), 0
  67.         SELECT CASE m$
  68.             CASE "L": LINE (mxd, myd)-(mxu, myu), c~&
  69.             CASE "F": LINE (mxd, myd)-(mxu, myu), c~&, B
  70.             CASE "B": LINE (mxd, myd)-(mxu, myu), c~&, BF
  71.             CASE "E"
  72.                 dx = ABS(mxd - mxu): dy = ABS(myd - myu)
  73.                 Ell mxd, myd, dx, dy, 0
  74.             CASE "D"
  75.                 dx = ABS(mxd - mxu): dy = ABS(myd - myu)
  76.                 Ell mxd, myd, dx, dy, 1
  77.         END SELECT
  78.         _DISPLAY
  79.         p = (p + 1) MOD 10
  80.         _PUTIMAGE , 0, d&(p)
  81.     END IF
  82.     _DISPLAY
  83.     _LIMIT 20
  84.  
  85. SUB changeColor
  86.     r = 128: g = 128: b = 128: a = 128
  87.     COLOR &HFFFFFFFF, &HFF000000
  88.     DO
  89.         CLS
  90.         test~& = _RGBA32(r, g, b, a)
  91.         slider 16, 10, r, "Red"
  92.         slider 16, 60, g, "Green"
  93.         slider 16, 110, b, "Blue"
  94.         slider 16, 160, a, "Alpha"
  95.         _PRINTSTRING (140, 260), "Press spacebar or enter to accept color change, q or esc to cancel"
  96.         LINE (90, 300)-(710, 590), , B
  97.         LINE (100, 310)-(700, 580), test~&, BF
  98.         WHILE _MOUSEINPUT: WEND
  99.         mb = _MOUSEBUTTON(1)
  100.         IF mb THEN 'clear it
  101.             mx = _MOUSEX: my = _MOUSEY
  102.             IF mx >= 16 AND mx <= 784 THEN
  103.                 IF my >= 10 AND my <= 50 THEN
  104.                     r = _ROUND((mx - 16) / 3)
  105.                 ELSEIF my >= 60 AND my <= 100 THEN
  106.                     g = _ROUND((mx - 16) / 3)
  107.                 ELSEIF my >= 110 AND my <= 150 THEN
  108.                     b = _ROUND((mx - 16) / 3)
  109.                 ELSEIF my >= 160 AND my <= 200 THEN
  110.                     a = _ROUND((mx - 16) / 3)
  111.                 END IF
  112.             END IF
  113.         END IF
  114.         k$ = INKEY$
  115.         IF LEN(k$) THEN
  116.             IF ASC(k$) = 13 OR ASC(k$) = 32 THEN c~& = test~&: EXIT SUB
  117.             IF k$ = "q" OR ASC(k$) = 27 THEN EXIT SUB
  118.         END IF
  119.         _DISPLAY
  120.         _LIMIT 60
  121.     LOOP
  122.  
  123. SUB slider (x, y, value, label$)
  124.     SELECT CASE label$
  125.         CASE "Red": cr~& = &HFFFF0000
  126.         CASE "Green": cr~& = &HFF008800
  127.         CASE "Blue": cr~& = &HFF0000FF
  128.         CASE "Alpha": cr~& = &H88FFFFFF
  129.     END SELECT
  130.     LINE (x, y)-STEP(768, 40), cr~&, B
  131.     LINE (x, y)-STEP(3 * value, 40), cr~&, BF
  132.     COLOR &HFFFFFFFF, cr~&
  133.     s$ = label$ + " = " + _TRIM$(STR$(value))
  134.     _PRINTSTRING (x + 384 - 4 * LEN(s$), y + 12), s$
  135.     COLOR &HFFFFFFFF, &HFF000000
  136.  
  137. SUB Ell (CX AS LONG, CY AS LONG, xRadius AS LONG, yRadius AS LONG, fillTF)
  138.     DIM scale AS SINGLE, x AS LONG, y AS LONG, a AS SINGLE, xx AS SINGLE, yy AS SINGLE
  139.     scale = yRadius / xRadius
  140.     IF fillTF THEN
  141.         LINE (CX, CY - yRadius)-(CX, CY + yRadius), c~&, BF
  142.         FOR x = 1 TO xRadius
  143.             y = scale * SQR(xRadius * xRadius - x * x)
  144.             LINE (CX + x, CY - y)-(CX + x, CY + y), c~&, BF
  145.             LINE (CX - x, CY - y)-(CX - x, CY + y), c~&, BF
  146.         NEXT
  147.     ELSE
  148.         FOR a = 0 TO _PI(2.01) STEP .1
  149.             xx = CX + xRadius * COS(a)
  150.             yy = CY + yRadius * SIN(a)
  151.             IF a > 0 THEN LINE (lastx, lasty)-(xx, yy), c~&
  152.             lastx = xx: lasty = yy
  153.         NEXT
  154.     END IF
  155.  
  156.  
Title: Re: Paint Pixels 4
Post by: SierraKen on October 09, 2019, 07:34:46 pm
I kinda see what you did, and when I tried it, it sorta worked, but you had to press U a bunch of times. Then I added too much code and was lost in my own code lol. So I gave up and went back to where it was. I might try it next week more and see what I can come up with. I saved your code to a Notepad. I will be away from programming for a few days starting tomorrow and hopefully back in a few days. Thanks anyways B+. By the way, my modem broke this morning so thankfully I found one I had in my closet that works. So hopefully that will work for a long time.
Title: Re: Paint Pixels 4
Post by: TempodiBasic on October 13, 2019, 11:39:05 am
Hi Sierraken

you're creature is growing up to a more professional look!
Thanks to share!
Good job!

If you like I can give you some feedbacks...otherwise go to read some other responses
1. Initial window is not centered on the screen... you can do it with _SCREENMOVE
2. Orbist starts with the initial position of mouse without any left click
2.1 circle flickers while I  move mouse to decide the ray of the circle with the second left click
2.2 it may be useful to choose if I want a circle or an ellipse so that I draw that shape without spending more attention to what you see on the screen
2.3 As soon as I dothe second left click to define the ray of the circle/ellipse, the program starts to draw a second circle/ellipse with the centre in the second left click.... I think that this issue is related to the issue 2(.0)
3 Boxes starts with first angle to the actual mouse position and the second to the next position without left click
3.1 boxes are full
3.2 also box flickers while I move mouse to decide the dimensions of it
4. Ray does the same
4.1  it starts where is the mouse without any left click
4.2 the next ray starts at the end of the previous ray
4.3 ray flickers while I choose the second extremity of it

and I agree with
 STxAxTIC
Quote
Maybe version 6 will have a toolbar like paint?
this powers up your application to a more professional world
and  Bplus
Quote
Here is how I would do Undo and some other things, mouse down starts draw object, mouse release is finishes
Title: Re: Paint Pixels 4
Post by: TempodiBasic on October 13, 2019, 11:53:21 am
@Petr

Quote
it has been a while since I wrote it. In the end I interrupted it, now I don't even know why...
Mhhhmhhh...
let me say you that I have had a first unknown why,  just 18 years ago and he had brought me to leave hobbies and  to fall deep and deep in the work..
just some time ago that reason gave me a bridge by pc programming, we started together with Java (and in that time I found on the web QB64 and then Terry Ritchie and the this wonderful community).
But it has spent just little time   to change direction/interest, the hystory repeats itself. :-)