Author Topic: Paint Pixels 4  (Read 8564 times)

0 Members and 1 Guest are viewing this topic.

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

Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
Paint Pixels 4
« 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.  


« Last Edit: October 06, 2019, 12:07:42 am by SierraKen »

Offline euklides

  • Forum Regular
  • Posts: 128
    • View Profile
Re: Paint Pixels 4
« Reply #1 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 ? ...

Why not yes ?

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Paint Pixels 4
« Reply #2 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?



 

« Last Edit: October 06, 2019, 11:26:01 am by bplus »

Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
Re: Paint Pixels 4
« Reply #3 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.
« Last Edit: October 06, 2019, 12:17:09 pm by SierraKen »

Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
Re: Paint Pixels 4
« Reply #4 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.  

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Paint Pixels 4
« Reply #5 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.

Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
Re: Paint Pixels 4
« Reply #6 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.  

KenFunk.bmp
* KenFunk.bmp (Filesize: 900.05 KB, Dimensions: 640x480, Views: 198)
ThankYouBPlus.bmp
* ThankYouBPlus.bmp (Filesize: 900.05 KB, Dimensions: 640x480, Views: 191)
« Last Edit: October 06, 2019, 07:09:59 pm by SierraKen »

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Paint Pixels 4
« Reply #7 on: October 06, 2019, 11:47:26 pm »
Well I am grinning from ear to ear! Glad you liked it.

Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
Re: Paint Pixels 4
« Reply #8 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.  

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Paint Pixels 4
« Reply #9 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.

Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
Re: Paint Pixels 4
« Reply #10 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.

Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
Re: Paint Pixels 4
« Reply #11 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.  


Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
Re: Paint Pixels 4
« Reply #12 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.  

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Paint Pixels 4
« Reply #13 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.  
« Last Edit: October 07, 2019, 07:28:56 pm by bplus »

Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
Re: Paint Pixels 4
« Reply #14 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.  
« Last Edit: October 07, 2019, 08:09:26 pm by SierraKen »