Author Topic: Dice Roller, Ping Pong, Conversion Calculator, Timer, List Aphabetizer  (Read 8365 times)

0 Members and 1 Guest are viewing this topic.

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Thanks Kenneth,

I see QB64 has compile error:
Probably this is problem:
Code: QB64: [Select]
  1.         DECLARE LIBRARY
  2.             FUNCTION FindWindow& (BYVAL ClassName AS _OFFSET, WindowName$) ' To get hWnd handle
  3.         END DECLARE

I will look over code tomorrow.

BTW I have great Air Hockey game because mouse wouldn't stay on track for Ping Pong. ;-))

I’d say it’s the issue too.  Try this:

Code: QB64: [Select]
  1.        
  2. $IF 32BIT THEN
  3.             FUNCTION FindWindow& (BYVAL ClassName AS _OFFSET, WindowName$) ' To get hWnd handle
  4.             FUNCTION FindWindow&& (BYVAL ClassName AS _OFFSET, WindowName$) ' To get hWnd handle
  5.  

Return a 32-bit value on QB64x32, and return a 64-bit value on QB64x64 versions.
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Thanks Steve, that gets me past compile error.

When I press B or W for Black or White Background, that's it full screen with Black or White.

escape key press works.

Color is probably not being set because no color dialog ever comes up. Some funky GOTO's too!

Well could make my own color dialog... is it worth it? ;-))
« Last Edit: June 21, 2019, 10:51:37 am by bplus »

Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
LOL thanks guys! I will switch over to that code today. Bplus, you have to have Windows/System it says to use the color dialog window. Maybe even in C: I don't know. I don't know probably 1/2 the code in that entire program. But I got the color dialog, the JPG save, the printer code, and probably others from the Wiki pages.
« Last Edit: June 21, 2019, 12:22:56 pm by SierraKen »

Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
Bplus, the color dialog box didn't open even after SMcNeill's code? It's supposed to popup when the drawing window comes up, but it can take a few seconds. Try it again and wait about 5 seconds or so. It pops up before you can draw so you can choose a color to start out with.

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Bplus, the color dialog box didn't open even after SMcNeill's code? It's supposed to popup when the drawing window comes up, but it can take a few seconds. Try it again and wait about 5 seconds or so. It pops up before you can draw so you can choose a color to start out with.

I waited and waited... I started my own color dialog which might work in another OS besides Windows.

Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
Ahh OK, well thanks for telling me. I won't put that Paint program on my website, it's just too dependent on Windows stuff, etc. And it's not the best in painting, although you can have it if you want. All of my programs I put online are free for anyone to use. I'm going to start a new forum thread now about the analog clock I just made. :)

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
My new Color Dialog works fine in your Paint program!

So now it is better than ever because not limited to Windows.
Code: QB64: [Select]
  1. 'This program took on a life of its own starting from a basic mouse
  2. 'drawing program to then saving it as its own type of data file to
  3. 'then BMP pictures and now JPG pictures.
  4. 'Then other things were added such as rays, orbits, paint fill ins,
  5. 'boxes, printer support, Windows color picker, and editing.
  6. 'This program was made using QB64 and will always be Freeware.
  7. 'Paint PIxels was made by Kenneth Green with some help from
  8. 'the QB64 website Wiki pages.
  9. 'I want to thank the people who made and take care of the QB64 website
  10. 'and computer language. I have wanted to make a program like this for
  11. 'a very long time.
  12. 'It took 1 week to make this program and finished on June 5, 2019.
  13. 'Feel free to use any of its code below for your own creations but
  14. 'please don't copy more than half of it and sell it. Thank you.
  15. 'Just remember, there are much better graphics programs out there
  16. 'that can do much more than this can, but to me this is my pride and joy.
  17. 'One big thing I like a lot about this program is that it uses the
  18. 'entire computer screen to draw with. Also remember, I am no professional,
  19. 'just a guy who has loved BASIC programming for over 30 years.
  20. '
  21. 'Technical Notes:
  22. 'This program uses around 55 MB RAM and 1% of the CPU on my semi-new computer.
  23. 'Use at your own risk. I hold no responsibility for any problems whatsoever.
  24.  
  25. 'Here is the code needed for the Color Picker. The Function code
  26. 'is also at the end of this program.
  27. CONST CC_RGBINIT = &H1& ' Sets the initial color (don't know how to set it)
  28. CONST CC_FULLOPEN = &H2& ' Opens all dialog sections such as the custom color selector
  29. CONST CC_PREVENTFULLOPEN = &H4& ' Prevents the user from opening the custom color selector
  30. CONST CC_SHOWHELP = &H8& ' Shows the help button (USELESS!)
  31. '----------------------------------------------------------------------------------------
  32. 'TYPE COLORDIALOGTYPE
  33. '    lStructSize AS LONG ' Length of this TYPE structure
  34. '    hwndOwner AS LONG 'Dialog owner's handle
  35. '    hInstance AS LONG '  ?
  36. '    rgbResult AS LONG ' The RGB color the user selected
  37. '    lpCustColors AS _OFFSET ' Pointer to an array of 16 custom colors (will be changed by user)
  38. '    flags AS LONG ' Dialog flags
  39. '    lCustData AS LONG ' Custom data
  40. '    lpfnHook AS LONG ' Hook
  41. '    lpTemplateName AS _OFFSET ' Custom template
  42. 'END TYPE
  43. DIM ColorString AS STRING * 64 '?
  44.  
  45. _LIMIT 500
  46. start:
  47. _TITLE "Paint Pixels"
  48. WIDTH 40, 43
  49. _SCREENMOVE 400, 200
  50. PRINT "         Paint Pixels"
  51. PRINT "         By Ken G."
  52. PRINT "This is a little program that you"
  53. PRINT "can draw using your mouse and"
  54. PRINT "save the picture and load it."
  55. PRINT "You also can make lines (Rays),"
  56. PRINT "circles (Orbits), and fill in the"
  57. PRINT "same color. You also can print to"
  58. PRINT "your USB printer as well as edit"
  59. PRINT "an old picture file."
  60. PRINT "It saves under .jpg files which can"
  61. PRINT "be used with most other programs."
  62. PRINT "Press the Space Bar to"
  63. PRINT "skip instructions."
  64. PRINT "Press Esc to end program."
  65. PRINT "Press any other key to continue."
  66. gggo:
  67. ecc$ = INKEY$
  68. IF ecc$ = " " THEN GOTO start2:
  69. IF ecc$ = CHR$(27) THEN END
  70. IF ecc$ = "" THEN GOTO gggo:
  71. PRINT "       Instructions"
  72. PRINT "(S)ave (L)oad (H)ome"
  73. PRINT "(R)ay coordinates for line."
  74. PRINT "Press R once to start line"
  75. PRINT "and again to finish it."
  76. PRINT "(O)rbit coordinates for circles."
  77. PRINT "Press O once to start circle."
  78. PRINT "and again to finish it."
  79. PRINT "The size of the circle depends"
  80. PRINT "on the length difference"
  81. PRINT "between where you pressed O"
  82. PRINT "both times. The center of the circle"
  83. PRINT "will be the first place you pressed O."
  84. PRINT "(P)rints the picture on"
  85. PRINT "your printer. It will not work"
  86. PRINT "if you choose a black background"
  87. PRINT "because of heavy ink or toner use."
  88. PRINT "To go around that, choose a white"
  89. PRINT "background and on the color picker"
  90. PRINT "window, choose black and press F"
  91. PRINT "to fill entire window."
  92. PRINT "The paper printed outcome will NOT"
  93. PRINT "be proportionate to the screen."
  94. PRINT "Esc to end program."
  95. PRINT "Space Bar clears the screen."
  96. PRINT "Left Mouse Button draws."
  97. PRINT "Right Mouse Button erases."
  98. PRINT "There is no Undo feature on"
  99. PRINT "this program."
  100. PRINT "Press Esc to end program or"
  101. PRINT "any other key to continue."
  102. ggggo:
  103. ecc2$ = INKEY$
  104. IF ecc2$ = CHR$(27) THEN END
  105. IF ecc2$ = "" THEN GOTO ggggo:
  106. PRINT "    Instructions Page 2"
  107. PRINT "(C)olor changes colors."
  108. PRINT "A window will popup to use"
  109. PRINT "your mouse to choose a color."
  110. PRINT "This will also happen when you"
  111. PRINT "first start your painting."
  112. PRINT "(F)ill fills in a color between"
  113. PRINT "the lines of the same color only."
  114. PRINT "Also close any gaps or it will"
  115. PRINT "fill the whole screen."
  116. PRINT "(B)oxes makes a box."
  117. PRINT "First press B once to start the"
  118. PRINT "box corner, then press B again"
  119. PRINT "to set the 2nd corner and size"
  120. PRINT "diagonally from the first one."
  121. PRINT "Paint slowly to leave out gaps."
  122. PRINT "When you press S to save,"
  123. PRINT "the program will create a temp.jpg"
  124. PRINT "of the screen and when asking you"
  125. PRINT "for a file name, it will rename temp.jpg"
  126. PRINT "to your chosen name."
  127. PRINT "Press Esc to end program or"
  128. PRINT "any other key to start."
  129. gggggo:
  130. s$ = INKEY$
  131. IF s$ = "" THEN GOTO gggggo:
  132. IF s$ = CHR$(27) THEN END
  133. start2:
  134. begin = 1
  135. PRINT "Background Color"
  136. PRINT "(B)lack (W)hite"
  137. PRINT "Or Esc to end program."
  138. start3:
  139. bcolor$ = INKEY$
  140. IF bcolor$ = CHR$(27) THEN END
  141. IF bcolor$ = "" THEN GOTO start3:
  142. IF bcolor$ = "w" OR bcolor$ = "W" THEN
  143.     s& = _NEWIMAGE(640, 480, 32)
  144.     SCREEN s&
  145.     LINE (0, 0)-(640, 480), _RGB(255, 255, 255), BF
  146.     GOTO more2:
  147. IF bcolor$ = "B" OR bcolor$ = "b" THEN
  148.     s& = _NEWIMAGE(640, 480, 32)
  149.     SCREEN s&
  150.     CLS
  151.     GOTO more2:
  152. GOTO start3:
  153. more2:
  154. begin = 1
  155. GOSUB chosencolor:
  156. '---------------------------------------------------
  157. 'Here is the main loop of the program when painting.
  158. '---------------------------------------------------
  159.     _LIMIT 500
  160.         mouseX = _MOUSEX
  161.         mouseY = _MOUSEY
  162.         mouseLeftButton = _MOUSEBUTTON(1)
  163.         mouseRightButton = _MOUSEBUTTON(2)
  164.         mouseMiddleButton = _MOUSEBUTTON(3)
  165.     LOOP
  166.     IF mouseLeftButton = -1 THEN
  167.         LINE (mouseX, mouseY)-(mouseX + 1, mouseY + 1), clr~&, BF
  168.     END IF
  169.     IF mouseRightButton = -1 THEN
  170.         LINE (mouseX, mouseY)-(mouseX + 1, mouseY + 1), 0, BF
  171.     END IF
  172.     a$ = INKEY$
  173.     'Here is when someone whipes the screen blank with the space bar.
  174.     IF a$ = " " THEN GOTO start2:
  175.     IF a$ = CHR$(27) THEN END
  176.     IF a$ = "s" OR a$ = "S" THEN GOTO saving:
  177.     IF a$ = "l" OR a$ = "L" THEN GOSUB loading:
  178.     IF a$ = "h" OR a$ = "H" THEN GOTO start:
  179.     'Here is code needed to call up the Windows Color Picker.
  180.     'It also uses the code on top of this program and the Function at the end
  181.     'of this program.
  182.     IF a$ = "c" OR a$ = "C" THEN
  183.         chosencolor:
  184.         ''Color Dialog flag constants (use + or OR to use more than 1 flag)
  185.         'ColorString = "FFFFFFFFFF" 'not sure how this works?
  186.         'DECLARE DYNAMIC LIBRARY "comdlg32"
  187.         '    FUNCTION ChooseColorA& (DIALOGPARAMS AS COLORDIALOGTYPE) ' Yet the also famous color dialog box
  188.         'END DECLARE
  189.  
  190.         'DECLARE LIBRARY
  191.         '    $IF 32BIT THEN
  192.         '    FUNCTION FindWindow& (BYVAL ClassName AS _OFFSET, WindowName$) ' To get hWnd handle
  193.         '    $ELSE
  194.         '        FUNCTION FindWindow&& (BYVAL ClassName AS _OFFSET, WindowName$) ' To get hWnd handle
  195.         '    $END IF
  196.         'END DECLARE
  197.  
  198.         '' SCREEN _NEWIMAGE(640, 480, 12) '32 or 16 or 256 color screen modes
  199.         '_TITLE "Paint Pixels" 'set Title of program
  200.         'hWnd& = FindWindow(0, "Paint Pixels" + CHR$(0)) 'get window handle using _TITLE string
  201.         'clr~& = ChooseColor&(_RGB32(0, 0, 0), ColorString$, Cancel, CC_FULLOPEN, hWnd&)
  202.  
  203.         check$ = colorDialog$
  204.         IF check$ <> "" THEN clr~& = VAL(check$) ELSE clr~& = &HFF0000FF '<<< I am blue if colorDialog does not work
  205.  
  206.         IF begin = 1 THEN begin = 0: RETURN
  207.     END IF
  208.     'Here is the Ray Lines code.
  209.     IF a$ = "r" OR a$ = "R" THEN
  210.         ck = ck + 1
  211.         IF ck > 1 THEN GOTO ray:
  212.         xxx = mouseX: yyy = mouseY
  213.         LINE (mouseX, mouseY)-(mouseX + 1, mouseY + 1), clr~&, BF
  214.         GOTO firstray:
  215.         ray:
  216.         LINE (mouseX, mouseY)-(xxx, yyy), clr~&
  217.         xxx = 0: yyy = 0
  218.         ck = 0
  219.         firstray:
  220.     END IF
  221.     'Here is the Orbit Circles code.
  222.     IF a$ = "o" OR a$ = "O" THEN
  223.         ck2 = ck2 + 1
  224.         IF ck2 > 1 THEN GOTO orbit:
  225.         xxx2 = mouseX: yyy2 = mouseY
  226.         GOTO firstorbit:
  227.         orbit:
  228.         IF mouseX < xxx2 THEN size = xxx2 - mouseX
  229.         IF mouseX > xxx2 THEN size = mouseX - xxx2
  230.         IF mouseY < yyy2 THEN size2 = yyy2 - mouseY
  231.         IF mouseY > yyy2 THEN size2 = mouseY - yyy2
  232.         size3 = INT((size + size2) / 2)
  233.         CIRCLE (xxx2, yyy2), size3, clr~&
  234.         xxx2 = 0: yyy2 = 0
  235.         size = 0: size2 = 0: size3 = 0
  236.         ck2 = 0
  237.         firstorbit:
  238.     END IF
  239.     'Here is the Fill-in code.
  240.     IF a$ = "f" OR a$ = "F" THEN
  241.         PAINT (mouseX, mouseY), clr~&
  242.     END IF
  243.     'Here is the Boxes code.
  244.     IF a$ = "b" OR a$ = "B" THEN
  245.         ck3 = ck3 + 1
  246.         IF ck3 > 1 THEN GOTO box:
  247.         xxx3 = mouseX: yyy3 = mouseY
  248.         GOTO firstbox:
  249.         box:
  250.         LINE (mouseX, mouseY)-(xxx3 + 1, yyy3 + 1), clr~&, B
  251.         xxx3 = 0: yyy3 = 0
  252.         ck3 = 0
  253.         firstbox:
  254.     END IF
  255.     'Here is the Printing of the picture.
  256.     IF a$ = "p" OR a$ = "P" THEN
  257.         IF bcolor$ = "w" OR bcolor$ = "W" THEN
  258.             j& = _COPYIMAGE(0)
  259.             _DELAY .25
  260.             INPUT "Print on printer (Y/N)?", i$ 'print screen page on printer
  261.             CLS
  262.             SCREEN j&
  263.             _DELAY .25
  264.             IF UCASE$(i$) = "Y" THEN _PRINTIMAGE j&
  265.             _DELAY 2
  266.             j& = 0
  267.         END IF
  268.     END IF
  269.  
  270. 'Saving
  271. 'This section first saves your picture as temp.jpg and then
  272. 'asks you a name for your picture and then renames temp.jpg to your name.
  273. saving:
  274. 'Now we call up the SUB to save the image to JPG.
  275. SaveImage 0, "temp.jpg"
  276. _DELAY .25
  277. PRINT "            Saving"
  278. PRINT "Your jpg file will be saved in the"
  279. PRINT "same directory as this program is."
  280. PRINT "It can be used with almost any"
  281. PRINT "other graphics program or website."
  282. PRINT "It is saved using:"
  283. PRINT "width: 640  height: 480 pixels."
  284. PRINT "Type a name to save your picture"
  285. PRINT "and press the Enter key. Do not"
  286. PRINT "add .jpg at the end, the program"
  287. PRINT "will do it automatically."
  288. PRINT "Also do not use the name temp"
  289. PRINT "because the program uses that name"
  290. PRINT "and it would be erased the next time"
  291. PRINT "you save a picture."
  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$ + ".jpg"
  297. 'Checking to see if the file already exists on your computer.
  298. theFileExists = _FILEEXISTS(nm$)
  299. IF theFileExists = -1 THEN
  300.     PRINT "File Already Exists"
  301.     PRINT "Saving will delete your old"
  302.     PRINT "jpg picture."
  303.     PRINT "Would you like to still do it?"
  304.     PRINT "(Y/N). Esc ends program."
  305.     llloop:
  306.     _LIMIT 10
  307.     ag2$ = INKEY$
  308.     IF ag2$ = "" THEN GOTO llloop:
  309.     IF ag2$ = "y" OR ag$ = "Y" THEN GOTO saving2:
  310.     IF ag2$ = CHR$(27) THEN END
  311.     GOTO saving:
  312. saving2:
  313. NAME "temp.jpg" AS nm$
  314.  
  315. nm$ = ""
  316. FOR snd = 100 TO 700 STEP 100
  317.     SOUND snd, 2
  318. NEXT snd
  319. GOTO start:
  320. loading: 'This section loads your picture from your computer.
  321. PRINT "           Loading"
  322. PRINT "Do not add .jpg at the end."
  323. PRINT "The jpg picture must be in the same"
  324. PRINT "directory as this program is."
  325. PRINT "You will not be able to edit your"
  326. PRINT "picture file with this program."
  327. PRINT "Type the name of your picture file"
  328. PRINT "here and press the Enter key."
  329. PRINT "Example: MyPic"
  330. PRINT "Quit and Enter key ends program."
  331. INPUT "->"; nm$
  332. IF nm$ = "Quit" OR nm$ = "quit" OR nm$ = "QUIT" THEN END
  333. nm$ = nm$ + ".jpg"
  334. theFileExists = _FILEEXISTS(nm$)
  335. IF theFileExists = 0 THEN
  336.     PRINT "File Does Not Exist."
  337.     PRINT "Would you like to try again (Y/N)"
  338.     PRINT "Esc ends program."
  339.     _LIMIT 10
  340.     llloop2:
  341.     ag$ = INKEY$
  342.     IF ag$ = "" THEN GOTO llloop2:
  343.     IF ag$ = "y" OR ag$ = "Y" THEN GOTO loading:
  344.     IF ag$ = CHR$(27) THEN END
  345.     GOTO start:
  346. l = 0
  347. i& = _LOADIMAGE(nm$, 32)
  348. 'j& = _COPYIMAGE(0)
  349. FOR snd2 = 100 TO 700 STEP 100
  350.     SOUND snd2, 2
  351. NEXT snd2
  352. s& = i&
  353. i& = 0
  354.  
  355. ''Here is the function for the Windows Color Picker,
  356. 'FUNCTION ChooseColor& (InitialColor&, CustomColors$, Cancel, Flags&, hWnd&)
  357. '    ' Parameters:
  358. '    ' InitialColor& - The initial color used, will take effect if CC_RGBINIT flag is specified
  359. '    ' CustomColors$ - A 64-byte string where the user's custom colors will be stored (4 bytes per color in RGB0 format).
  360. '    ' Cancel - Variable where the cancel flag will be stored.
  361. '    ' Flags& - Dialog flags
  362. '    ' hWnd& - Your program's window handle that should be aquired by the FindWindow function.
  363. '    DIM ColorCall AS COLORDIALOGTYPE
  364. '    ColorCall.rgbResult = _RGB32(_BLUE32(InitialColor&), _GREEN32(InitialColor&), _RED32(InitialColor&))
  365. '    ColorCall.lStructSize = LEN(ColorCall)
  366. '    ColorCall.hwndOwner = hWnd&
  367. '    ColorCall.flags = Flags&
  368. '    ColorCall.lpCustColors = _OFFSET(CustomColors$)
  369. '    ' Do dialog call
  370. '    Result = ChooseColorA(ColorCall)
  371. '    IF Result THEN
  372. '        rgbResult& = ColorCall.rgbResult
  373. '        ' Swap RED and BLUE color intensity values using _RGB
  374. '        ChooseColor& = _RGB(_BLUE32(rgbResult&), _GREEN32(rgbResult&), _RED32(rgbResult&))
  375. '    ELSE
  376. '        Cancel = -1
  377. '    END IF
  378. 'END FUNCTION
  379.  
  380. 'Here is the SUB needed to save the image to JPG.
  381. 'It also can be used for BMP pictures on your own program.
  382. SUB SaveImage (image AS LONG, filename AS STRING)
  383.     bytesperpixel& = _PIXELSIZE(image&)
  384.     IF bytesperpixel& = 0 THEN PRINT "Text modes unsupported!": END
  385.     IF bytesperpixel& = 1 THEN bpp& = 8 ELSE bpp& = 24
  386.     x& = _WIDTH(image&)
  387.     y& = _HEIGHT(image&)
  388.     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)
  389.     IF bytesperpixel& = 1 THEN
  390.         FOR c& = 0 TO 255 ' read BGR color settings from JPG image + 1 byte spacer(CHR$(0))
  391.             cv& = _PALETTECOLOR(c&, image&) ' color attribute to read.
  392.             b$ = b$ + CHR$(_BLUE32(cv&)) + CHR$(_GREEN32(cv&)) + CHR$(_RED32(cv&)) + CHR$(0) 'spacer byte
  393.         NEXT
  394.     END IF
  395.     MID$(b$, 11, 4) = MKL$(LEN(b$)) ' image pixel data offset(BMP header)
  396.     lastsource& = _SOURCE
  397.     _SOURCE image&
  398.     IF ((x& * 3) MOD 4) THEN padder$ = STRING$(4 - ((x& * 3) MOD 4), 0)
  399.     FOR py& = y& - 1 TO 0 STEP -1 ' read JPG image pixel color data
  400.         r$ = ""
  401.         FOR px& = 0 TO x& - 1
  402.             c& = POINT(px&, py&) 'POINT 32 bit values are large LONG values
  403.             IF bytesperpixel& = 1 THEN r$ = r$ + CHR$(c&) ELSE r$ = r$ + LEFT$(MKL$(c&), 3)
  404.         NEXT px&
  405.         d$ = d$ + r$ + padder$
  406.     NEXT py&
  407.     _SOURCE lastsource&
  408.     MID$(b$, 35, 4) = MKL$(LEN(d$)) ' image size(BMP header)
  409.     b$ = b$ + d$ ' total file data bytes to create file
  410.     MID$(b$, 3, 4) = MKL$(LEN(b$)) ' size of data file(BMP header)
  411.     IF LCASE$(RIGHT$(filename$, 4)) <> ".jpg" THEN ext$ = ".jpg"
  412.     f& = FREEFILE
  413.     OPEN filename$ + ext$ FOR OUTPUT AS #f&: CLOSE #f& ' erases an existing file
  414.     OPEN filename$ + ext$ FOR BINARY AS #f&
  415.     PUT #f&, , b$
  416.     CLOSE #f&
  417.  
  418. FUNCTION colorDialog$
  419.  
  420.     'first screen dimensions items to restore at exit
  421.     DIM curRow AS INTEGER, curCol AS INTEGER, autoDisplay AS INTEGER
  422.     DIM curScrn AS LONG, backScrn AS LONG 'some handles
  423.  
  424.     DIM cd AS LONG
  425.     DIM makeConst$, k$
  426.     DIM f AS SINGLE
  427.  
  428.     'save old settings to restore at end ofsub
  429.     curRow = CSRLIN
  430.     curCol = POS(0)
  431.     autoDisplay = _AUTODISPLAY
  432.     sw = _WIDTH
  433.     sh = _HEIGHT
  434.     fg = _DEFAULTCOLOR
  435.     bg = _BACKGROUNDCOLOR
  436.     _KEYCLEAR
  437.     'screen snapshot
  438.     curScrn = _DEST
  439.     backScrn = _NEWIMAGE(sw, sh, 32)
  440.     _PUTIMAGE , curScrn, backScrn
  441.  
  442.     cd = _NEWIMAGE(800, 600, 32)
  443.     SCREEN cd
  444.     r = 128: g = 128: b = 128: a = 128
  445.     COLOR &HFFDDDDDD, 0
  446.     DO
  447.         CLS
  448.         makeConst$ = "&H" + RIGHT$(STRING$(8, "0") + HEX$(_RGBA32(r, g, b, a)), 8)
  449.         slider 16, 10, r, "Red"
  450.         slider 16, 60, g, "Green"
  451.         slider 16, 110, b, "Blue"
  452.         slider 16, 160, a, "Alpha"
  453.         _PRINTSTRING (150, 260), "Press enter or spacenbar, if you want to use the color: " + makeConst$
  454.         _PRINTSTRING (210, 280), "Press escape or q, to not use any color, returns 0."
  455.         LINE (90, 300)-(710, 590), , B
  456.         FOR i = 100 TO 700
  457.             f = 255 * (i - 100) / 600
  458.             LINE (i, 310)-STEP(0, 30), _RGB32(f, 0, 0): LINE (i, 310)-STEP(0, 20), VAL(makeConst$)
  459.             LINE (i, 340)-STEP(0, 30), _RGB32(0, f, 0): LINE (i, 340)-STEP(0, 20), VAL(makeConst$)
  460.             LINE (i, 370)-STEP(0, 30), _RGB32(0, 0, f): LINE (i, 370)-STEP(0, 20), VAL(makeConst$)
  461.             LINE (i, 400)-STEP(0, 30), _RGB32(f, f, 0): LINE (i, 400)-STEP(0, 20), VAL(makeConst$)
  462.             LINE (i, 430)-STEP(0, 30), _RGB32(0, f, f): LINE (i, 430)-STEP(0, 20), VAL(makeConst$)
  463.             LINE (i, 460)-STEP(0, 30), _RGB32(f, 0, f): LINE (i, 460)-STEP(0, 20), VAL(makeConst$)
  464.             LINE (i, 490)-STEP(0, 30), _RGB32(f, f, f): LINE (i, 490)-STEP(0, 20), VAL(makeConst$)
  465.             LINE (i, 520)-STEP(0, 30), _RGB32(0, 0, 0): LINE (i, 520)-STEP(0, 20), VAL(makeConst$)
  466.             LINE (i, 550)-STEP(0, 30), _RGB32(255, 255, 255): LINE (i, 550)-STEP(0, 20), VAL(makeConst$)
  467.         NEXT
  468.         WHILE _MOUSEINPUT: WEND
  469.         mb = _MOUSEBUTTON(1)
  470.         IF mb THEN 'clear it
  471.             mx = _MOUSEX: my = _MOUSEY
  472.             IF mx >= 16 AND mx <= 781 THEN
  473.                 IF my >= 10 AND my <= 50 THEN
  474.                     r = INT((mx - 16) / 3)
  475.                 ELSEIF my >= 60 AND my <= 100 THEN
  476.                     g = INT((mx - 16) / 3)
  477.                 ELSEIF my >= 110 AND my <= 150 THEN
  478.                     b = INT((mx - 16) / 3)
  479.                 ELSEIF my >= 160 AND my <= 200 THEN
  480.                     a = INT((mx - 16) / 3)
  481.                 END IF
  482.             END IF
  483.         END IF
  484.         k$ = INKEY$
  485.         IF LEN(k$) THEN
  486.             IF ASC(k$) = 27 OR k$ = "q" THEN EXIT DO
  487.             IF ASC(k$) = 13 OR k$ = " " THEN colorDialog$ = makeConst$: EXIT DO
  488.         END IF
  489.         _DISPLAY
  490.         _LIMIT 60
  491.     LOOP
  492.  
  493.     'put things back
  494.     SCREEN curScrn
  495.     COLOR _RGB32(255, 255, 255), _RGB32(0, 0, 0): CLS
  496.     _PUTIMAGE , backScrn
  497.     _DISPLAY
  498.     COLOR fg, bg
  499.     _FREEIMAGE backScrn
  500.     _FREEIMAGE cd
  501.     IF autoDisplay THEN _AUTODISPLAY
  502.     'clear key presses
  503.     _KEYCLEAR
  504.     'clear mouse clicks
  505.     mb = _MOUSEBUTTON(1)
  506.     IF mb THEN 'clear it
  507.         WHILE mb 'OK!
  508.             IF _MOUSEINPUT THEN mb = _MOUSEBUTTON(1)
  509.             _LIMIT 10
  510.         WEND
  511.     END IF
  512.     LOCATE curRow, curCol
  513.  
  514.  
  515. SUB slider (x, y, value, label$)
  516.     DIM c~&, s$
  517.     SELECT CASE label$
  518.         CASE "Red": c~& = &HFFFF0000
  519.         CASE "Green": c~& = &HFF008800
  520.         CASE "Blue": c~& = &HFF0000FF
  521.         CASE "Alpha": c~& = &H88FFFFFF
  522.     END SELECT
  523.     LINE (x, y)-STEP(765, 40), c~&, B
  524.     LINE (x, y)-STEP(3 * value, 40), c~&, BF
  525.     s$ = label$ + " = " + _TRIM$(STR$(value))
  526.     _PRINTSTRING (x + 384 - 4 * LEN(s$), y + 12), s$
  527.  
  528.  

 
Hi_2_Kennith.jpg
« Last Edit: June 21, 2019, 06:11:10 pm by bplus »

Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
Really cool B+! I'm glad it works for you, but I'm getting 1 error with it on my computer.
Line 586 "Invalid name on current line".
Code: QB64: [Select]
  1. s$ = label$ + " = " + _TRIM$(STR$(value))
  2.  
I don't know if it has to do with me having Windows 10 64 bit version of QB64 or what it could be. So weird. Maybe we can fix it?
If I can get it to work on my computer, I'll add your name to it and put it on my website.



Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
I believe I fixed it. It runs fine so far, I made a picture in 1 color and saved it and loaded it. THANKS!!!! I'll put it up on my page in a little bit after I run a few more tests.
I replaced that error line by breaking it up into 3 lines. The _TRIM function you used either doesn't work on my computer or something is off. So I did it the old fashioned way and did this:
Code: QB64: [Select]
  1.     s2$ = STR$(value)
  2.     s3$ = LTRIM$(RTRIM$(s2$))
  3.     s$ = label$ + " = " + s3$
  4.  

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
I believe I fixed it. It runs fine so far, I made a picture in 1 color and saved it and loaded it. THANKS!!!! I'll put it up on my page in a little bit after I run a few more tests.
I replaced that error line by breaking it up into 3 lines. The _TRIM function you used either doesn't work on my computer or something is off. So I did it the old fashioned way and did this:
Code: QB64: [Select]
  1.     s2$ = STR$(value)
  2.     s3$ = LTRIM$(RTRIM$(s2$))
  3.     s$ = label$ + " = " + s3$
  4.  

Your fix is exactly what _TRIM$ would do! I was happy to see the .JPG files working from your program. I tried a Printing but did not know about Black backgrounds until too late (nice safety feature), then one thing and another and hadn't had a chance to get back to test printing again.

The _TRIM$ function comes in QB64 version 1.3, It's worth updating just for that! :)
I have been wondering if your computer is 32 bit or 64? Just curious...

And thanks for the thanks, very encouraging... :)

Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
Oh wow I didn't know there was already another update, I just have 1.2 and I got this about a month ago. I just checked out Paint Pixels and everything works except the Fill (Paint command). For some reason it always fills the entire screen now. But that's OK, it would only work with boxes anyway so I removed the (F)ill and just turned the boxes into filled boxes (BF). I put your name on it and also on the website with the program and renamed it to Paint Pixels 2. :) This is great! Thanks again. The website is here: http://ken.x10host.com/qb64/

Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
Oh I think I know why the Paint command doesn't work now, because your colors use a translucent see-though type. But that's even better because the colors look even better when you can see them partially behind other colors. Especially with the boxes. Actually, I just tried the regular drawing over other drawings and I think it's only the BF that is translucent. So I'm not sure what happened. But it's cool. :)
« Last Edit: June 22, 2019, 07:44:29 pm by SierraKen »