QB64.org Forum

Active Forums => Programs => Topic started by: SierraKen on June 19, 2019, 09:30:36 pm

Title: Dice Roller, Ping Pong, Conversion Calculator, Timer, List Aphabetizer
Post by: SierraKen on June 19, 2019, 09:30:36 pm
I have 5 QB64 programs on my little website so far. Only the code is there so you can copy/paste it to your own. They are: Dice Roller (without graphics), Ping Pong (like Pong but a little harder), Conversion Calculator (converts KM<>Miles, Gallons <> Liters, Fahrenheit <> Celsius, MPH <> KM/h), a simple count up or count down Timer, and a List Alphabetizer. All of mine are for a Microsoft Windows computer. The code can be found here: http://ken.x10host.com/qb64/                Thanks! - Ken G.
Title: Re: Dice Roller, Ping Pong, Conversion Calculator, Timer, List Aphabetizer
Post by: bplus on June 19, 2019, 11:07:30 pm
Hi Kenneth,

Welcome to the forum.

I tried your Ping Pong. That paddle action sucks! and it is disconcerting to see the ball go through the paddle.

I fixed both:
Code: QB64: [Select]
  1. 'Updated by Kenneth on May 27, 2019.
  2. _TITLE "PING PONG"
  3. begin:
  4. PRINT "               PING PONG"
  5. PRINT "By Kenneth G."
  6. PRINT "Use the up and down arrow keys to move"
  7. PRINT "the left paddle. If the ball passes the"
  8. PRINT "computer's paddle, you get a point."
  9. PRINT "Whoever gets 10 points first wins."
  10. PRINT "Use the right and left arrow keys to"
  11. PRINT "stop your paddle."
  12. PRINT "Press Esc to end anytime."
  13. INPUT "(F)ast, (M)edium, (S)low, (Q)uit:"; sp$
  14. IF sp$ = "F" OR sp$ = "f" OR sp$ = "FAST" OR sp$ = "fast" OR sp$ = "Fast" THEN sd = 30
  15. IF sp$ = "M" OR sp$ = "m" OR sp$ = "MEDIUM" OR sp$ = "medium" OR sp$ = "Medium" THEN sd = 20
  16. IF sp$ = "S" OR sp$ = "s" OR sp$ = "SLOW" OR sp$ = "slow" OR sp$ = "Slow" THEN sd = 10
  17. IF sp$ = "Q" OR sp$ = "q" OR sp$ = "QUIT" OR sp$ = "quit" OR sp$ = "Quit" THEN CLEAR: END
  18. IF sd = 0 THEN sd = 10
  19. INPUT "Press enter to start."; st$
  20. start:
  21. x = 10: y = 100
  22. x2 = 305: y2 = 100
  23. a = 140: b = 100
  24. d = 0: po1 = 0: po2 = 0
  25. l = 1: r = 0
  26. dr$ = ""
  27. ky:
  28. LOCATE 1, 1: PRINT "You:"; p: LOCATE 1, 25: PRINT "Computer:"; p2
  29. a$ = INKEY$
  30. LINE (x, y)-(x + 2, y + 15), 0, BF
  31. IF a$ = CHR$(0) + CHR$(72) THEN y = y - 10 ': dr$ = "up"
  32. IF a$ = CHR$(0) + CHR$(80) THEN y = y + 10 ' : dr$ = "down"
  33. IF a$ = CHR$(0) + CHR$(75) THEN dr$ = "stop"
  34. IF a$ = CHR$(0) + CHR$(77) THEN dr$ = "stop"
  35. IF a$ = CHR$(27) THEN CLEAR: END
  36. IF dr$ = "up" THEN y = y - 5
  37. IF dr$ = "down" THEN y = y + 5
  38. IF y < 10 THEN y = 10
  39. IF y > 170 THEN y = 170
  40. LINE (x, y)-(x + 2, y + 15), 4, BF
  41. ball:
  42. CIRCLE (a, b), 3, 0
  43. IF a > x2 - 6 THEN l = 1: r = 0: RANDOMIZE TIMER: d = INT(RND * 10) - 5: PLAY "l30c"
  44. IF a < x + 6 THEN r = 1: l = 0: RANDOMIZE TIMER: d = INT(RND * 10) - 5: PLAY "l30c"
  45. IF l = 1 THEN a = a - 5: b = b + d
  46. IF r = 1 THEN a = a + 5: b = b + d
  47. IF b < 20 THEN RANDOMIZE TIMER: d = INT(RND * 5) + 1
  48. IF b > 170 THEN RANDOMIZE TIMER: d = INT(RND * 5) - 5
  49. IF b > y + 16 OR b < y - 1 THEN po1 = 1
  50. IF b > y2 + 16 OR b < y2 - 1 THEN po2 = 1
  51. GOTO chk
  52. ball2:
  53. CIRCLE (a, b), 3, 15
  54. computer:
  55. LINE (x2, y2)-(x2 + 2, y2 + 15), 4, BF
  56. IF l = 1 THEN GOTO tim:
  57. LINE (x2, y2)-(x2 + 2, y2 + 15), 0, BF
  58. IF d < 0 THEN y2 = y2 - 6
  59. IF d > 0 THEN y2 = y2 + 6
  60. IF b < y2 THEN y2 = y2 - 7
  61. IF b > y2 + 15 THEN y2 = y2 + 7
  62. IF y2 < 10 THEN dr2$ = "down"
  63. IF y2 > 170 THEN dr2$ = "up"
  64. IF dr2$ = "down" THEN
  65.     rad = INT(RND * 3) + 2
  66.     y2 = y2 + rad
  67. IF dr2$ = "up" THEN
  68.     rad = INT(RND * 3) + 2
  69.     y2 = y2 - rad
  70. LINE (x2, y2)-(x2 + 2, y2 + 15), 4, BF
  71. tim:
  72. GOTO ky:
  73. chk:
  74. IF a > x2 + 2 AND po2 = 1 THEN p = p + 1
  75. IF a < x - 2 AND po1 = 1 THEN p2 = p2 + 1
  76. IF p = 10 THEN
  77.     LOCATE 1, 1: PRINT "You:"; p: LOCATE 1, 25: PRINT "Computer:"; p2
  78.     PRINT "YOU WIN"
  79.     PRINT
  80.     PRINT
  81.     INPUT "Press enter to go to main menu."; mm$
  82.     GOTO begin:
  83. IF p2 = 10 THEN
  84.     LOCATE 1, 1: PRINT "You:"; p: LOCATE 1, 25: PRINT "Computer:"; p2
  85.     PRINT "COMPUTER WINS"
  86.     PRINT
  87.     PRINT
  88.     INPUT "Press enter to go to main menu."; mm$
  89.     GOTO begin:
  90. IF a > x2 + 2 AND po2 = 1 THEN GOTO start
  91. IF a < x - 2 AND po1 = 1 THEN GOTO start
  92. po2 = 0
  93. po1 = 0
  94. GOTO ball2
  95.  
  96.  

BTW does the computer ever miss? :D
Title: Re: Dice Roller, Ping Pong, Conversion Calculator, Timer, List Aphabetizer
Post by: bplus on June 19, 2019, 11:13:19 pm
Here is my Infinite Pong the Movie:
Code: QB64: [Select]
  1. _TITLE "Infinite Pong the Movie.bas for QB64 B+ 2018-09-16"
  2. p1y = 1: p2y = 25 'paddle y
  3. bx = 30: by = 10: bdx = 2: bdy = 1 'ball x, y, dx, dy
  4.     CLS
  5.     FOR row = 2 TO 24
  6.         LOCATE row, 5: PRINT "|";
  7.         LOCATE row, 75: PRINT "|";
  8.     NEXT
  9.     p1x = bx - 5: _PRINTSTRING (p1x, p1y), "1111111111" ' draw paddle 1
  10.     p2x = bx - 5: _PRINTSTRING (p2x, p2y), "2222222222" ' draw paddle 2
  11.     IF bx + bdx < 6 THEN bdx = bdx * -1 + INT(RND * 3) - 1
  12.     IF bx + bdx > 74 THEN bdx = bdx * -1 + INT(RND * 3) - 1
  13.     IF by + bdy < 2 THEN bdy = bdy * -1: bdx = bdx + INT(RND * 3) - 1
  14.     IF by + bdy > 24 THEN bdy = bdy * -1: bdx = bdx + INT(RND * 3) - 1
  15.     bx = bx + bdx: by = by + bdy
  16.     _PRINTSTRING (bx, by), "O"
  17.     _LIMIT 10
  18.  
  19.  
Title: Re: Dice Roller, Ping Pong, Conversion Calculator, Timer, List Aphabetizer
Post by: SierraKen on June 20, 2019, 01:27:39 am
Thanks. Yeah I've known the ball can go through the paddle at certain times, but I couldn't figure out how to fix it. I tried your code and for some reason the ball always bounces off the walls and nobody ever gets a point. But I really like your Pong the Movie! Pretty good for not too much code you made. Also, I want to keep my paddle always moving unless the user presses the right or left arrow key, which stops your paddle. Yeah it's really hard, I've only beaten it once or twice out of many tries. The computer sometimes misses if you play enough. Also, the highest speed is usually in the user's favor for some reason. I made about 90% of this program back in 1996 so who knows what I was thinking, but I think it's kinda cool so that's why I plopped it on my website. lol Thanks for the critique though, I appreciate it.
Title: Re: Dice Roller, Ping Pong, Conversion Calculator, Timer, List Aphabetizer
Post by: bplus on June 20, 2019, 01:35:58 am
Hi Kenneth,

I did work on your game some more, if you like paddles always moving sorry :) but ball looks like it's bouncing pretty close to correct places and I handicapped the computer a bit.

Code: QB64: [Select]
  1. 'Updated by Kenneth on May 27, 2019.
  2. _TITLE "PING PONG"
  3. begin:
  4. PRINT "               PING PONG"
  5. PRINT "By Kenneth G."
  6. PRINT "Use the up and down arrow keys to move"
  7. PRINT "the left paddle. If the ball passes the"
  8. PRINT "computer's paddle, you get a point."
  9. PRINT "Whoever gets 10 points first wins."
  10. PRINT "Press Esc to end anytime."
  11. INPUT "(F)ast, (M)edium, (S)low, (Q)uit:"; sp$
  12. IF sp$ = "F" OR sp$ = "f" OR sp$ = "FAST" OR sp$ = "fast" OR sp$ = "Fast" THEN sd = 30
  13. IF sp$ = "M" OR sp$ = "m" OR sp$ = "MEDIUM" OR sp$ = "medium" OR sp$ = "Medium" THEN sd = 20
  14. IF sp$ = "S" OR sp$ = "s" OR sp$ = "SLOW" OR sp$ = "slow" OR sp$ = "Slow" THEN sd = 10
  15. IF sp$ = "Q" OR sp$ = "q" OR sp$ = "QUIT" OR sp$ = "quit" OR sp$ = "Quit" THEN CLEAR: END
  16. IF sd = 0 THEN sd = 10
  17. INPUT "Press enter to start."; st$
  18. start:
  19. x = 10: y = 100
  20. x2 = 305: y2 = 100
  21. a = 140: b = 100
  22. d = 0: po1 = 0: po2 = 0
  23. l = 1: r = 0
  24. dr$ = ""
  25.     'LINE (0, 15)-(400, 15), 3
  26.     'LINE (0, 176)-(400, 176), 3
  27.     CLS
  28.     LINE (10, 15)-(305, 176), 1, BF
  29.     LOCATE 1, 5: PRINT "You:"; p: LOCATE 1, 25: PRINT "Computer:"; p2
  30.     a$ = INKEY$
  31.     IF a$ = CHR$(27) THEN CLEAR: END
  32.  
  33.     'your paddle
  34.     'LINE (x, y)-(x + 2, y + 15), 0, BF 'why 2 times black out old redrw new
  35.     IF a$ = CHR$(0) + CHR$(72) THEN y = y - 10
  36.     IF a$ = CHR$(0) + CHR$(80) THEN y = y + 10
  37.     IF y < 10 THEN y = 10
  38.     IF y > 170 THEN y = 170
  39.     LINE (x, y)-(x + 2, y + 15), 4, BF
  40.  
  41.     ball:
  42.     'CIRCLE (a, b), 3, 0 'black out
  43.     'IF a > x2 - 6 THEN l = 1: r = 0:  d = INT(RND * 10) - 5: PLAY "l30c"
  44.     'IF a = x + 5 AND po1 THEN r = 1: l = 0:  d = INT(RND * 10) - 5: PLAY "l30c"
  45.  
  46.     'the ball is always moving left or right in inc of 5
  47.     IF l = 1 THEN a = a - 5: b = b + d
  48.     IF r = 1 THEN a = a + 5: b = b + d
  49.  
  50.     IF a = x + 5 THEN
  51.         IF b < y + 16 AND b > y - 1 THEN 'paddle hit ball   send it back
  52.             r = 1
  53.             l = 0
  54.             d = INT(RND * 10) - 5: PLAY "l30c"
  55.         END IF
  56.     END IF
  57.  
  58.     IF b < 20 THEN d = RND * 5 + 1
  59.     IF b > 170 THEN d = RND * 5 - 5
  60.     IF b > y + 16 OR b < y - 1 THEN po1 = 1 'ball misses paddle on
  61.     IF b > y2 + 16 OR b < y2 - 1 THEN po2 = 1
  62.     IF a = x2 - 5 THEN
  63.         IF b < y2 + 16 AND b > y2 - 1 THEN 'paddle hit ball   send it back
  64.             r = 0
  65.             l = 1
  66.             d = INT(RND * 10) - 5: PLAY "l30c"
  67.         END IF
  68.     END IF
  69.     IF a < x + 5 AND po1 = 1 THEN p2 = p2 + 1 'ball misses paddle on x spot
  70.     IF a >= x2 AND po2 = 1 THEN p = p + 1
  71.     IF p = 10 THEN
  72.         LOCATE 1, 1: PRINT "You:"; p: LOCATE 1, 25: PRINT "Computer:"; p2
  73.         PRINT "YOU WIN, ";
  74.         INPUT "Press enter."; mm$
  75.         GOTO begin:
  76.     END IF
  77.     IF p2 = 10 THEN
  78.         LOCATE 1, 1: PRINT "You:"; p: LOCATE 1, 25: PRINT "Computer:"; p2
  79.         PRINT "COMPUTER WINS, ";
  80.         INPUT "Press enter."; mm$
  81.         GOTO begin:
  82.     END IF
  83.     IF a >= x2 AND po2 = 1 THEN GOTO start
  84.     IF a <= x AND po1 = 1 THEN GOTO start
  85.     po2 = 0
  86.     po1 = 0
  87.     CIRCLE (a, b), 3, 15
  88.  
  89.     computer:
  90.     LINE (x2, y2)-(x2 + 2, y2 + 15), 4, BF
  91.     IF l = 1 THEN GOTO tim:
  92.     'LINE (x2, y2)-(x2 + 2, y2 + 15), 0, BF
  93.     IF d < 0 THEN y2 = y2 - 6
  94.     IF d > 0 THEN y2 = y2 + 6
  95.     IF RND < .90 THEN '<<<<<<<<<<<<<<<<<<<<<<< sorry computer you are too perfect
  96.         IF b < y2 THEN y2 = y2 - 7
  97.         IF b > y2 + 15 THEN y2 = y2 + 7
  98.     END IF
  99.     IF y2 < 10 THEN dr2$ = "down"
  100.     IF y2 > 170 THEN dr2$ = "up"
  101.     IF dr2$ = "down" THEN
  102.         RANDOMIZE TIMER
  103.         rad = INT(RND * 3) + 2
  104.         y2 = y2 + rad
  105.     END IF
  106.     IF dr2$ = "up" THEN
  107.         RANDOMIZE TIMER
  108.         rad = INT(RND * 3) + 2
  109.         y2 = y2 - rad
  110.     END IF
  111.     LINE (x2, y2)-(x2 + 2, y2 + 15), 4, BF
  112.     tim:
  113.     _DISPLAY
  114.     _LIMIT sd
  115.  
  116.  
Title: Re: Dice Roller, Ping Pong, Conversion Calculator, Timer, List Aphabetizer
Post by: SierraKen on June 20, 2019, 12:37:02 pm
WOW Thanks!!! I added credit to you in the game too and in the top code remark. I will add it to my website sometime later today most likely. I did notice one small problem which also happened before you worked on it, is that the ball also sometimes goes through the computer's paddle. I'm not sure if that is intentional or not, like if we want to make it easier to play on the user's part. If you want, you can keep working on it and I will just update the website again if you make another version. I'm going to also call this: Ping Pong 2.
Title: Re: Dice Roller, Ping Pong, Conversion Calculator, Timer, List Aphabetizer
Post by: SierraKen on June 20, 2019, 03:41:34 pm
I got your name on the updated version on the program and on the website, thanks again.
http://ken.x10host.com/qb64/
Title: Re: Dice Roller, Ping Pong, Conversion Calculator, Timer, List Aphabetizer
Post by: SierraKen on June 20, 2019, 04:27:23 pm
I just found a way to stop the ball from going through the Computer's paddle. Once in awhile it will still stop before the paddle but I'm not going to worry about that. What I did was change Line 68 to this: IF a > x2 - 5 AND a < x2 + 2 THEN       
I updated the new code to the website.
Title: Re: Dice Roller, Ping Pong, Conversion Calculator, Timer, List Aphabetizer
Post by: OldMoses on June 20, 2019, 04:39:25 pm
I'm going to have to scrutinize your computer "player" algorithm. I've never written anything that put a computer as an opponent. All I've concentrated on was number crunchers, so I don't have a clue how to go about it.
Title: Re: Dice Roller, Ping Pong, Conversion Calculator, Timer, List Aphabetizer
Post by: bplus on June 20, 2019, 05:31:26 pm
For contrast and curiosity, I wrote up a Ping Pong Game totally structured such that ... well look! :-))

Oh, also if you are a constant paddle mover, no problem because this paddle runs off mouse.

Code: QB64: [Select]
  1. _TITLE "Ping Pong" 'try a modern structured approach 2019-06-20 by B+
  2. CONST xmax = 800, ymax = 600
  3. SCREEN _NEWIMAGE(xmax, ymax, 32)
  4. _SCREENMOVE 300, 40
  5.  
  6. TYPE XYType
  7.     x AS SINGLE
  8.     y AS SINGLE
  9. TYPE Rectangle
  10.     xy AS XYType
  11.     w AS SINGLE
  12.     h AS SINGLE
  13.     clr AS _UNSIGNED LONG
  14.     xy AS XYType
  15.     dx AS SINGLE
  16.     dy AS SINGLE
  17.     r AS INTEGER
  18.     clr AS _UNSIGNED LONG
  19. TYPE player
  20.     id AS STRING
  21.     pdl AS Rectangle
  22.     pts AS INTEGER
  23. TYPE game
  24.     human AS player
  25.     computer AS player
  26.     ball AS circle
  27.     table AS Rectangle
  28. DIM SHARED g AS game '<<< all game data is in here
  29. initGame
  30. playGame
  31.  
  32. SUB initGame 'most of thses remain constant                                         start with table
  33.     g.table.xy.x = 50: g.table.xy.y = 150: g.table.w = 700: g.table.h = 400: g.table.clr = &HFF005038
  34.     g.computer.id = "Computer": g.computer.pts = 0 '                            computer on the left
  35.     g.computer.pdl.w = 15: g.computer.pdl.h = 40: g.computer.pdl.clr = &HFF0000FF
  36.     g.computer.pdl.xy.x = g.table.xy.x - g.computer.pdl.w
  37.     g.human.id = "Human": g.human.pts = 0 '                                      player on the right
  38.     g.human.pdl.w = 15: g.human.pdl.h = 40: g.human.pdl.clr = &HFFFF0000
  39.     g.human.pdl.xy.x = g.table.xy.x + g.table.w '                                      player paddle
  40.     g.ball.r = 5: g.ball.clr = &HFFFFFFFF '                                                     ball
  41.  
  42. SUB playGame
  43.     DIM my, inbounds
  44.     DO
  45.         getBallRolling
  46.         inbounds = 1
  47.         WHILE inbounds
  48.             WHILE _MOUSEINPUT: WEND '                                                              update human paddle
  49.             my = _MOUSEY
  50.             IF my > g.table.xy.y AND my <= g.table.xy.y + g.table.h THEN
  51.                 g.human.pdl.xy.y = my - g.human.pdl.h / 2
  52.             END IF
  53.             IF RND < .3 THEN '                                                                 update computer paddle
  54.                 g.computer.pdl.xy.y = g.ball.xy.y - g.computer.pdl.h / 2
  55.             END IF
  56.             g.ball.xy.x = g.ball.xy.x + g.ball.dx: g.ball.xy.y = g.ball.xy.y + g.ball.dy '  update ball
  57.             'past the table edge? or paddle edge
  58.             IF g.ball.xy.x - g.ball.r <= g.table.xy.x THEN '                                ball paste left edge
  59.                 IF g.ball.xy.y + g.ball.r >= g.computer.pdl.xy.y AND g.ball.xy.y - g.ball.r <= g.computer.pdl.xy.y + g.computer.pdl.h THEN
  60.                     g.ball.dx = -g.ball.dx
  61.                 ELSE
  62.                     inbounds = 0: g.human.pts = g.human.pts + 1
  63.                 END IF
  64.             ELSEIF g.ball.xy.x + g.ball.r >= g.table.xy.x + g.table.w THEN '                ball paste right edge
  65.                 IF g.ball.xy.y + g.ball.r >= g.human.pdl.xy.y AND g.ball.xy.y - g.ball.r <= g.human.pdl.xy.y + g.human.pdl.h THEN
  66.                     g.ball.dx = -g.ball.dx
  67.                 ELSE
  68.                     inbounds = 0: g.computer.pts = g.computer.pts + 1
  69.                 END IF
  70.             ELSEIF g.ball.xy.y - g.ball.r <= g.table.xy.y THEN '                                          top edge
  71.                 g.ball.dy = -g.ball.dy
  72.             ELSEIF g.ball.xy.y + g.ball.r >= g.table.xy.y + g.table.h THEN '                            bottom edge
  73.                 g.ball.dy = -g.ball.dy
  74.             END IF
  75.             drawGame
  76.             _DISPLAY
  77.             _LIMIT 60
  78.         WEND
  79.         _DELAY .5
  80.     LOOP UNTIL g.human.pts = 21 OR g.computer.pts = 21
  81.  
  82. SUB getBallRolling
  83.     DIM d, s$, tstart, my
  84.     g.computer.pdl.xy.y = g.table.xy.y + (g.table.h - g.computer.pdl.h) / 2 '       center paddles y
  85.     g.human.pdl.xy.y = g.table.xy.y + (g.table.h - g.human.pdl.h) / 2
  86.     g.ball.dy = 4 + RND
  87.     g.ball.dx = (g.ball.dy + 1 + RND)
  88.     IF RND < .5 THEN d = -1 ELSE d = 1 '                              ball movement absolutely  more dx than dy
  89.     g.ball.dy = g.ball.dy * d
  90.     IF RND < .5 THEN d = -1 ELSE d = 1
  91.     g.ball.dx = g.ball.dx * d
  92.     IF d < 0 THEN '                                                      ball table center
  93.         g.ball.xy.x = g.table.xy.x + .9 * g.table.w
  94.     ELSE
  95.         g.ball.xy.x = g.table.xy.x + .1 * g.table.w
  96.     END IF
  97.     g.ball.xy.y = g.table.xy.y + g.table.h / 2
  98.     tstart = TIMER(.001)
  99.     WHILE TIMER(.001) - tstart < 1.500 ' <<<<<<<<<<<<<<<< This allows player to get es paddle alligned with mouse
  100.         WHILE _MOUSEINPUT: WEND
  101.         my = _MOUSEY
  102.         IF my > g.table.xy.y AND my <= g.table.xy.y + g.table.h THEN '    update human paddle
  103.             g.human.pdl.xy.y = my - g.human.pdl.h / 2
  104.         END IF
  105.         drawGame
  106.         s$ = "Get ready for random serve..."
  107.         COLOR , g.table.clr
  108.         _PRINTSTRING (g.table.xy.x + (g.table.w - 8 * LEN(s$)) / 2, g.table.xy.y + g.table.h / 2 - 8), s$
  109.         COLOR , &HFF000000
  110.         _DISPLAY
  111.         _LIMIT 60
  112.     WEND
  113.  
  114. SUB drawGame
  115.     DIM s$
  116.     CLS
  117.     _PRINTSTRING (g.table.xy.x + 120, g.table.xy.y / 2 - 4), g.computer.id + ":" + STR$(g.computer.pts) '              score
  118.     s$ = g.human.id + ":" + STR$(g.human.pts)
  119.     _PRINTSTRING (g.table.xy.x + g.table.w - 8 * LEN(s$) - 120, g.table.xy.y / 2 - 4), s$
  120.     LINE (g.table.xy.x, g.table.xy.y)-STEP(g.table.w, g.table.h), g.table.clr, BF '                                    table
  121.     LINE (g.computer.pdl.xy.x, g.computer.pdl.xy.y)-STEP(g.computer.pdl.w, g.computer.pdl.h), g.computer.pdl.clr, BF ' computer paddle
  122.     LINE (g.human.pdl.xy.x, g.human.pdl.xy.y)-STEP(g.human.pdl.w, g.human.pdl.h), g.human.pdl.clr, BF '                human paddle
  123.     fcirc g.ball.xy.x, g.ball.xy.y, g.ball.r, g.ball.clr
  124.  
  125. SUB fcirc (CX AS INTEGER, CY AS INTEGER, R AS INTEGER, C AS _UNSIGNED LONG)
  126.     DIM Radius AS INTEGER, RadiusError AS INTEGER
  127.     DIM X AS INTEGER, Y AS INTEGER
  128.     Radius = ABS(R): RadiusError = -Radius: X = Radius: Y = 0
  129.     IF Radius = 0 THEN PSET (CX, CY), C: EXIT SUB
  130.     LINE (CX - X, CY)-(CX + X, CY), C, BF
  131.     WHILE X > Y
  132.         RadiusError = RadiusError + Y * 2 + 1
  133.         IF RadiusError >= 0 THEN
  134.             IF X <> Y + 1 THEN
  135.                 LINE (CX - Y, CY - X)-(CX + Y, CY - X), C, BF
  136.                 LINE (CX - Y, CY + X)-(CX + Y, CY + X), C, BF
  137.             END IF
  138.             X = X - 1
  139.             RadiusError = RadiusError - X * 2
  140.         END IF
  141.         Y = Y + 1
  142.         LINE (CX - X, CY - Y)-(CX + X, CY - Y), C, BF
  143.         LINE (CX - X, CY + Y)-(CX + X, CY + Y), C, BF
  144.     WEND
  145.  
  146.  

Unfortunately when I hide the mouse, my x alignment drifts off and so movement gets stuck all too often.
Title: Re: Dice Roller, Ping Pong, Conversion Calculator, Timer, List Aphabetizer
Post by: SierraKen on June 20, 2019, 08:52:08 pm
Thanks Ron!
Title: Re: Dice Roller, Ping Pong, Conversion Calculator, Timer, List Aphabetizer
Post by: SierraKen on June 20, 2019, 11:42:55 pm
Interesting bplus, I might take a look at that. Using the mouse reminds me of a week or 2 ago when I made a Paint program. I used examples on this website and it lets you paint with the mouse and even choose from the Windows color selection window. It even prints the picture and saves as JPG. Plus I added circles, squares, and fill-in. I really liked it until I found out that it might not work on a lot of Windows computers. And I have no idea why. It's why I don't have it on my website. But if anyone is interested in seeing that code, just tell me. Would love to hear any opinions and what I might have done wrong.
Title: Re: Dice Roller, Ping Pong, Conversion Calculator, Timer, List Aphabetizer
Post by: bplus on June 21, 2019, 12:15:55 am
Hi Kenneth,

If you or anyone can figure a way to keep the mouse from getting stuck in my Ping Pong version I would be eternally grateful. With arrow keys you don't have to worry about paddle getting off track but with mouse I drift sometimes all the way off the left side of the screen! and yet showing the mouse gets distracting.

Should be able to do everything you described for Paint program with QB64 specially easy for Windows. Steve has nifty code for saving images to image file formats. We can draw and fill any shape including tilted ellipse though N-gons might be tricky.

You say you have code? I say I'd be interested :D I am very curious what might not work in Windows, ah the saving to file format might be different and I don't know about printing an image.

We have started image editor here some time ago for modifying images, I think that is similar to Paint program except the pixels are blown up to squares.
Title: Re: Dice Roller, Ping Pong, Conversion Calculator, Timer, List Aphabetizer
Post by: SierraKen on June 21, 2019, 12:28:13 am
All I can think of to possibly help you with your mouse problem is to require people to hold down the left mouse button at the same time as moving it. That will give people the chance to move the mouse anywhere they want without moving the paddle.

Well, here is the code to my Paint program. It also uses bloated boxes for the "pixels" but you can load any JPG with it first to edit. Another problem I have with it is that you have to draw pretty slowly to make your lines connect. But I still like it. It runs fine on my Windows 10 Home Edition computer. It might have just been that particular person's computer that had problems, I have no idea. You will probably laugh in how scattered the code is, I still program like I did in the 90's. LOL The biggest thing I like about this program is that it uses the ENTIRE screen to paint, no words, boxes, anything, just your canvas. :) But like I said, draw slow. And also make sure and read the 2 pages of instructions that start out.

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 G. 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. DIM ColorString AS STRING * 64
  43.  
  44. _LIMIT 500
  45. start:
  46. _TITLE "Paint Pixels"
  47. WIDTH 40, 43
  48. _SCREENMOVE 400, 200
  49. PRINT "         Paint Pixels"
  50. PRINT "         By Ken G."
  51. PRINT "This is a little program that you"
  52. PRINT "can draw using your mouse and"
  53. PRINT "save the picture and load it."
  54. PRINT "You also can make lines (Rays),"
  55. PRINT "circles (Orbits), and fill in the"
  56. PRINT "same color. You also can print to"
  57. PRINT "your USB printer as well as edit"
  58. PRINT "an old picture file."
  59. PRINT "It saves under .jpg files which can"
  60. PRINT "be used with most other programs."
  61. PRINT "Press the Space Bar to"
  62. PRINT "skip instructions."
  63. PRINT "Press Esc to end program."
  64. PRINT "Press any other key to continue."
  65. gggo:
  66. ecc$ = INKEY$
  67. IF ecc$ = " " THEN GOTO start2:
  68. IF ecc$ = CHR$(27) THEN END
  69. IF ecc$ = "" THEN GOTO gggo:
  70. PRINT "       Instructions"
  71. PRINT "(S)ave (L)oad (H)ome"
  72. PRINT "(R)ay coordinates for line."
  73. PRINT "Press R once to start line"
  74. PRINT "and again to finish it."
  75. PRINT "(O)rbit coordinates for circles."
  76. PRINT "Press O once to start circle."
  77. PRINT "and again to finish it."
  78. PRINT "The size of the circle depends"
  79. PRINT "on the length difference"
  80. PRINT "between where you pressed O"
  81. PRINT "both times. The center of the circle"
  82. PRINT "will be the first place you pressed O."
  83. PRINT "(P)rints the picture on"
  84. PRINT "your printer. It will not work"
  85. PRINT "if you choose a black background"
  86. PRINT "because of heavy ink or toner use."
  87. PRINT "To go around that, choose a white"
  88. PRINT "background and on the color picker"
  89. PRINT "window, choose black and press F"
  90. PRINT "to fill entire window."
  91. PRINT "The paper printed outcome will NOT"
  92. PRINT "be proportionate to the screen."
  93. PRINT "Esc to end program."
  94. PRINT "Space Bar clears the screen."
  95. PRINT "Left Mouse Button draws."
  96. PRINT "Right Mouse Button erases."
  97. PRINT "There is no Undo feature on"
  98. PRINT "this program."
  99. PRINT "Press Esc to end program or"
  100. PRINT "any other key to continue."
  101. ggggo:
  102. ecc2$ = INKEY$
  103. IF ecc2$ = CHR$(27) THEN END
  104. IF ecc2$ = "" THEN GOTO ggggo:
  105. PRINT "    Instructions Page 2"
  106. PRINT "(C)olor changes colors."
  107. PRINT "A window will popup to use"
  108. PRINT "your mouse to choose a color."
  109. PRINT "This will also happen when you"
  110. PRINT "first start your painting."
  111. PRINT "(F)ill fills in a color between"
  112. PRINT "the lines of the same color only."
  113. PRINT "Also close any gaps or it will"
  114. PRINT "fill the whole screen."
  115. PRINT "(B)oxes makes a box."
  116. PRINT "First press B once to start the"
  117. PRINT "box corner, then press B again"
  118. PRINT "to set the 2nd corner and size"
  119. PRINT "diagonally from the first one."
  120. PRINT "Paint slowly to leave out gaps."
  121. PRINT "When you press S to save,"
  122. PRINT "the program will create a temp.jpg"
  123. PRINT "of the screen and when asking you"
  124. PRINT "for a file name, it will rename temp.jpg"
  125. PRINT "to your chosen name."
  126. PRINT "Press Esc to end program or"
  127. PRINT "any other key to start."
  128. gggggo:
  129. s$ = INKEY$
  130. IF s$ = "" THEN GOTO gggggo:
  131. IF s$ = CHR$(27) THEN END
  132. start2:
  133. begin = 1
  134. PRINT "Background Color"
  135. PRINT "(B)lack (W)hite"
  136. PRINT "Or Esc to end program."
  137. start3:
  138. bcolor$ = INKEY$
  139. IF bcolor$ = CHR$(27) THEN END
  140. IF bcolor$ = "" THEN GOTO start3:
  141. IF bcolor$ = "w" OR bcolor$ = "W" THEN
  142.     s& = _NEWIMAGE(640, 480, 32)
  143.     SCREEN s&
  144.     LINE (0, 0)-(640, 480), _RGB(255, 255, 255), BF
  145.     GOTO more2:
  146. IF bcolor$ = "B" OR bcolor$ = "b" THEN
  147.     s& = _NEWIMAGE(640, 480, 32)
  148.     SCREEN s&
  149.     CLS
  150.     GOTO more2:
  151. GOTO start3:
  152. more2:
  153. begin = 1
  154. GOSUB chosencolor:
  155. '---------------------------------------------------
  156. 'Here is the main loop of the program when painting.
  157. '---------------------------------------------------
  158.     _LIMIT 500
  159.         mouseX = _MOUSEX
  160.         mouseY = _MOUSEY
  161.         mouseLeftButton = _MOUSEBUTTON(1)
  162.         mouseRightButton = _MOUSEBUTTON(2)
  163.         mouseMiddleButton = _MOUSEBUTTON(3)
  164.     LOOP
  165.     IF mouseLeftButton = -1 THEN
  166.         LINE (mouseX, mouseY)-(mouseX + 1, mouseY + 1), clr~&, BF
  167.     END IF
  168.     IF mouseRightButton = -1 THEN
  169.         LINE (mouseX, mouseY)-(mouseX + 1, mouseY + 1), 0, BF
  170.     END IF
  171.     a$ = INKEY$
  172.     'Here is when someone whipes the screen blank with the space bar.
  173.     IF a$ = " " THEN GOTO start2:
  174.     IF a$ = CHR$(27) THEN END
  175.     IF a$ = "s" OR a$ = "S" THEN GOTO saving:
  176.     IF a$ = "l" OR a$ = "L" THEN GOSUB loading:
  177.     IF a$ = "h" OR a$ = "H" THEN GOTO start:
  178.     'Here is code needed to call up the Windows Color Picker.
  179.     'It also uses the code on top of this program and the Function at the end
  180.     'of this program.
  181.     IF a$ = "c" OR a$ = "C" THEN
  182.         chosencolor:
  183.         'Color Dialog flag constants (use + or OR to use more than 1 flag)
  184.         ColorString = "FFFFFFFFFF" 'not sure how this works?
  185.         DECLARE DYNAMIC LIBRARY "comdlg32"
  186.             FUNCTION ChooseColorA& (DIALOGPARAMS AS COLORDIALOGTYPE) ' Yet the also famous color dialog box
  187.         END DECLARE
  188.         DECLARE LIBRARY
  189.             FUNCTION FindWindow& (BYVAL ClassName AS _OFFSET, WindowName$) ' To get hWnd handle
  190.         END DECLARE
  191.         ' SCREEN _NEWIMAGE(640, 480, 12) '32 or 16 or 256 color screen modes
  192.         _TITLE "Paint Pixels" 'set Title of program
  193.         hWnd& = FindWindow(0, "Paint Pixels" + CHR$(0)) 'get window handle using _TITLE string
  194.         clr~& = ChooseColor&(_RGB32(0, 0, 0), ColorString$, Cancel, CC_FULLOPEN, hWnd&)
  195.         IF begin = 1 THEN begin = 0: RETURN
  196.     END IF
  197.     'Here is the Ray Lines code.
  198.     IF a$ = "r" OR a$ = "R" THEN
  199.         ck = ck + 1
  200.         IF ck > 1 THEN GOTO ray:
  201.         xxx = mouseX: yyy = mouseY
  202.         LINE (mouseX, mouseY)-(mouseX + 1, mouseY + 1), clr~&, BF
  203.         GOTO firstray:
  204.         ray:
  205.         LINE (mouseX, mouseY)-(xxx, yyy), clr~&
  206.         xxx = 0: yyy = 0
  207.         ck = 0
  208.         firstray:
  209.     END IF
  210.     'Here is the Orbit Circles code.
  211.     IF a$ = "o" OR a$ = "O" THEN
  212.         ck2 = ck2 + 1
  213.         IF ck2 > 1 THEN GOTO orbit:
  214.         xxx2 = mouseX: yyy2 = mouseY
  215.         GOTO firstorbit:
  216.         orbit:
  217.         IF mouseX < xxx2 THEN size = xxx2 - mouseX
  218.         IF mouseX > xxx2 THEN size = mouseX - xxx2
  219.         IF mouseY < yyy2 THEN size2 = yyy2 - mouseY
  220.         IF mouseY > yyy2 THEN size2 = mouseY - yyy2
  221.         size3 = INT((size + size2) / 2)
  222.         CIRCLE (xxx2, yyy2), size3, clr~&
  223.         xxx2 = 0: yyy2 = 0
  224.         size = 0: size2 = 0: size3 = 0
  225.         ck2 = 0
  226.         firstorbit:
  227.     END IF
  228.     'Here is the Fill-in code.
  229.     IF a$ = "f" OR a$ = "F" THEN
  230.         PAINT (mouseX, mouseY), clr~&
  231.     END IF
  232.     'Here is the Boxes code.
  233.     IF a$ = "b" OR a$ = "B" THEN
  234.         ck3 = ck3 + 1
  235.         IF ck3 > 1 THEN GOTO box:
  236.         xxx3 = mouseX: yyy3 = mouseY
  237.         GOTO firstbox:
  238.         box:
  239.         LINE (mouseX, mouseY)-(xxx3 + 1, yyy3 + 1), clr~&, B
  240.         xxx3 = 0: yyy3 = 0
  241.         ck3 = 0
  242.         firstbox:
  243.     END IF
  244.     'Here is the Printing of the picture.
  245.     IF a$ = "p" OR a$ = "P" THEN
  246.         IF bcolor$ = "w" OR bcolor$ = "W" THEN
  247.             j& = _COPYIMAGE(0)
  248.             _DELAY .25
  249.             INPUT "Print on printer (Y/N)?", i$ 'print screen page on printer
  250.             CLS
  251.             SCREEN j&
  252.             _DELAY .25
  253.             IF UCASE$(i$) = "Y" THEN _PRINTIMAGE j&
  254.             _DELAY 2
  255.             j& = 0
  256.         END IF
  257.     END IF
  258.  
  259. 'Saving
  260. 'This section first saves your picture as temp.jpg and then
  261. 'asks you a name for your picture and then renames temp.jpg to your name.
  262. saving:
  263. 'Now we call up the SUB to save the image to JPG.
  264. SaveImage 0, "temp.jpg"
  265. _DELAY .25
  266. PRINT "            Saving"
  267. PRINT "Your jpg file will be saved in the"
  268. PRINT "same directory as this program is."
  269. PRINT "It can be used with almost any"
  270. PRINT "other graphics program or website."
  271. PRINT "It is saved using:"
  272. PRINT "width: 640  height: 480 pixels."
  273. PRINT "Type a name to save your picture"
  274. PRINT "and press the Enter key. Do not"
  275. PRINT "add .jpg at the end, the program"
  276. PRINT "will do it automatically."
  277. PRINT "Also do not use the name temp"
  278. PRINT "because the program uses that name"
  279. PRINT "and it would be erased the next time"
  280. PRINT "you save a picture."
  281. PRINT "Example: MyPic"
  282. PRINT "Quit and Enter key ends program."
  283. INPUT "->"; nm$
  284. IF nm$ = "Quit" OR nm$ = "quit" OR nm$ = "QUIT" THEN END
  285. nm$ = nm$ + ".jpg"
  286. 'Checking to see if the file already exists on your computer.
  287. theFileExists = _FILEEXISTS(nm$)
  288. IF theFileExists = -1 THEN
  289.     PRINT "File Already Exists"
  290.     PRINT "Saving will delete your old"
  291.     PRINT "jpg picture."
  292.     PRINT "Would you like to still do it?"
  293.     PRINT "(Y/N). Esc ends program."
  294.     llloop:
  295.     _LIMIT 10
  296.     ag2$ = INKEY$
  297.     IF ag2$ = "" THEN GOTO llloop:
  298.     IF ag2$ = "y" OR ag$ = "Y" THEN GOTO saving2:
  299.     IF ag2$ = CHR$(27) THEN END
  300.     GOTO saving:
  301. saving2:
  302. NAME "temp.jpg" AS nm$
  303.  
  304. nm$ = ""
  305. FOR snd = 100 TO 700 STEP 100
  306.     SOUND snd, 2
  307. NEXT snd
  308. GOTO start:
  309. loading: 'This section loads your picture from your computer.
  310. PRINT "           Loading"
  311. PRINT "Do not add .jpg at the end."
  312. PRINT "The jpg picture must be in the same"
  313. PRINT "directory as this program is."
  314. PRINT "Type the name of your picture file"
  315. PRINT "here and press the Enter key."
  316. PRINT "Example: MyPic"
  317. PRINT "Quit and Enter key ends program."
  318. INPUT "->"; nm$
  319. IF nm$ = "Quit" OR nm$ = "quit" OR nm$ = "QUIT" THEN END
  320. nm$ = nm$ + ".jpg"
  321. theFileExists = _FILEEXISTS(nm$)
  322. IF theFileExists = 0 THEN
  323.     PRINT "File Does Not Exist."
  324.     PRINT "Would you like to try again (Y/N)"
  325.     PRINT "Esc ends program."
  326.     _LIMIT 10
  327.     llloop2:
  328.     ag$ = INKEY$
  329.     IF ag$ = "" THEN GOTO llloop2:
  330.     IF ag$ = "y" OR ag$ = "Y" THEN GOTO loading:
  331.     IF ag$ = CHR$(27) THEN END
  332.     GOTO start:
  333. l = 0
  334. i& = _LOADIMAGE(nm$, 32)
  335. 'j& = _COPYIMAGE(0)
  336. FOR snd2 = 100 TO 700 STEP 100
  337.     SOUND snd2, 2
  338. NEXT snd2
  339. s& = i&
  340. i& = 0
  341.  
  342. 'Here is the function for the Windows Color Picker,
  343. FUNCTION ChooseColor& (InitialColor&, CustomColors$, Cancel, Flags&, hWnd&)
  344.     ' Parameters:
  345.     ' InitialColor& - The initial color used, will take effect if CC_RGBINIT flag is specified
  346.     ' CustomColors$ - A 64-byte string where the user's custom colors will be stored (4 bytes per color in RGB0 format).
  347.     ' Cancel - Variable where the cancel flag will be stored.
  348.     ' Flags& - Dialog flags
  349.     ' hWnd& - Your program's window handle that should be aquired by the FindWindow function.
  350.     DIM ColorCall AS COLORDIALOGTYPE
  351.     ColorCall.rgbResult = _RGB32(_BLUE32(InitialColor&), _GREEN32(InitialColor&), _RED32(InitialColor&))
  352.     ColorCall.lStructSize = LEN(ColorCall)
  353.     ColorCall.hwndOwner = hWnd&
  354.     ColorCall.flags = Flags&
  355.     ColorCall.lpCustColors = _OFFSET(CustomColors$)
  356.     ' Do dialog call
  357.     Result = ChooseColorA(ColorCall)
  358.     IF Result THEN
  359.         rgbResult& = ColorCall.rgbResult
  360.         ' Swap RED and BLUE color intensity values using _RGB
  361.         ChooseColor& = _RGB(_BLUE32(rgbResult&), _GREEN32(rgbResult&), _RED32(rgbResult&))
  362.     ELSE
  363.         Cancel = -1
  364.     END IF
  365.  
  366. 'Here is the SUB needed to save the image to JPG.
  367. 'It also can be used for BMP pictures on your own program.
  368. SUB SaveImage (image AS LONG, filename AS STRING)
  369.     bytesperpixel& = _PIXELSIZE(image&)
  370.     IF bytesperpixel& = 0 THEN PRINT "Text modes unsupported!": END
  371.     IF bytesperpixel& = 1 THEN bpp& = 8 ELSE bpp& = 24
  372.     x& = _WIDTH(image&)
  373.     y& = _HEIGHT(image&)
  374.     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)
  375.     IF bytesperpixel& = 1 THEN
  376.         FOR c& = 0 TO 255 ' read BGR color settings from JPG image + 1 byte spacer(CHR$(0))
  377.             cv& = _PALETTECOLOR(c&, image&) ' color attribute to read.
  378.             b$ = b$ + CHR$(_BLUE32(cv&)) + CHR$(_GREEN32(cv&)) + CHR$(_RED32(cv&)) + CHR$(0) 'spacer byte
  379.         NEXT
  380.     END IF
  381.     MID$(b$, 11, 4) = MKL$(LEN(b$)) ' image pixel data offset(BMP header)
  382.     lastsource& = _SOURCE
  383.     _SOURCE image&
  384.     IF ((x& * 3) MOD 4) THEN padder$ = STRING$(4 - ((x& * 3) MOD 4), 0)
  385.     FOR py& = y& - 1 TO 0 STEP -1 ' read JPG image pixel color data
  386.         r$ = ""
  387.         FOR px& = 0 TO x& - 1
  388.             c& = POINT(px&, py&) 'POINT 32 bit values are large LONG values
  389.             IF bytesperpixel& = 1 THEN r$ = r$ + CHR$(c&) ELSE r$ = r$ + LEFT$(MKL$(c&), 3)
  390.         NEXT px&
  391.         d$ = d$ + r$ + padder$
  392.     NEXT py&
  393.     _SOURCE lastsource&
  394.     MID$(b$, 35, 4) = MKL$(LEN(d$)) ' image size(BMP header)
  395.     b$ = b$ + d$ ' total file data bytes to create file
  396.     MID$(b$, 3, 4) = MKL$(LEN(b$)) ' size of data file(BMP header)
  397.     IF LCASE$(RIGHT$(filename$, 4)) <> ".jpg" THEN ext$ = ".jpg"
  398.     f& = FREEFILE
  399.     OPEN filename$ + ext$ FOR OUTPUT AS #f&: CLOSE #f& ' erases an existing file
  400.     OPEN filename$ + ext$ FOR BINARY AS #f&
  401.     PUT #f&, , b$
  402.     CLOSE #f&
  403.  
Title: Re: Dice Roller, Ping Pong, Conversion Calculator, Timer, List Aphabetizer
Post by: bplus on June 21, 2019, 12:44:27 am
Thanks Kenneth,

I see QB64 has compile error:
Quote
In file included from qbx.cpp:2171:
..\\temp\\main.txt: In function 'void QBMAIN(void*)':
..\\temp\\main.txt:1224:112: error: cast from 'HWND' {aka 'HWND__*'} to 'int' loses precision [-fpermissive]
 *__LONG_HWND=(  int32  )FindWindow(NULL,(char*)(qbs_add(qbs_new_txt_len("Paint Pixels",12),func_chr( 0 )))->chr);
                                                                                                                ^
compilation terminated due to -Wfatal-errors.

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. ;-))
Title: Re: Dice Roller, Ping Pong, Conversion Calculator, Timer, List Aphabetizer
Post by: SMcNeill on June 21, 2019, 03:39:49 am
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.
Title: Re: Dice Roller, Ping Pong, Conversion Calculator, Timer, List Aphabetizer
Post by: bplus on June 21, 2019, 10:45:23 am
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? ;-))
Title: Re: Dice Roller, Ping Pong, Conversion Calculator, Timer, List Aphabetizer
Post by: SierraKen on June 21, 2019, 12:07:34 pm
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.
Title: Re: Dice Roller, Ping Pong, Conversion Calculator, Timer, List Aphabetizer
Post by: SierraKen on June 21, 2019, 12:17:41 pm
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.
Title: Re: Dice Roller, Ping Pong, Conversion Calculator, Timer, List Aphabetizer
Post by: bplus on June 21, 2019, 02:19:44 pm
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.
Title: Re: Dice Roller, Ping Pong, Conversion Calculator, Timer, List Aphabetizer
Post by: SierraKen on June 21, 2019, 03:31:45 pm
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. :)
Title: Re: Dice Roller, Ping Pong, Conversion Calculator, Timer, List Aphabetizer
Post by: bplus on June 21, 2019, 06:05:15 pm
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.  

 
Title: Re: Dice Roller, Ping Pong, Conversion Calculator, Timer, List Aphabetizer
Post by: SierraKen on June 22, 2019, 06:28:38 pm
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.


Title: Re: Dice Roller, Ping Pong, Conversion Calculator, Timer, List Aphabetizer
Post by: SierraKen on June 22, 2019, 06:40:39 pm
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.  
Title: Re: Dice Roller, Ping Pong, Conversion Calculator, Timer, List Aphabetizer
Post by: bplus on June 22, 2019, 06:52:44 pm
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... :)
Title: Re: Dice Roller, Ping Pong, Conversion Calculator, Timer, List Aphabetizer
Post by: SierraKen on June 22, 2019, 07:35:24 pm
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/
Title: Re: Dice Roller, Ping Pong, Conversion Calculator, Timer, List Aphabetizer
Post by: SierraKen on June 22, 2019, 07:40:25 pm
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. :)