Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Topics - TerryRitchie

Pages: [1] 2 3 4
1
A while back I mentioned I have a laptop, an HP Compaq nx7400, that will not allow QB64 to display the QB64 editor. I found the issue and am posting this in case others have the same problem.

Laptop Specs:

Intel GMA 950 Graphics
Windows 7 64bit Pro

I normally set Windows 7 to "Windows Classic" view. This appears to be the issue. Two items required for the editor to appear are disabled when setting to classic. Go to Control Panel->System->Advanced system settings->Performance Settings and make sure that "[ ] Use visual styles on windows and buttons" and "[ ] Enable desktop composition" are both selected.

I'm assuming this has something to do with the Intel GMA 950 video chipset. "Enable desktop composition" is not even listed in any of my other Windows 7 machines.

2
Programs / Raycasting
« on: July 13, 2020, 01:56:42 pm »
Sorry I've been scarce this past month. The wife was getting upset that the honey do list was not getting done. Had to limit my time on computer.

Any way, I've been trying to learn ray casting for another topic in my tutorial. I found a pretty good video on YouTube explaining the process. The narrator uses OpenGL and C. I converted it to QB64 as I watched the video. If you watch the video and look at the code below you'll be amazed at just how easy it is to do ray casting.

The code is sloppy. I threw it together as the narrator wrote his code. But it works. :-)



Code: QB64: [Select]
  1. '  [youtube]https://www.youtube.com/watch?v=gYRrGTC7GtA[/youtube]
  2.  
  3.  
  4.  
  5. CONST DARKGRAY = _RGB32(76, 76, 76)
  6. CONST WHITE = _RGB32(255, 255, 255)
  7. CONST BLACK = _RGB32(0, 0, 0)
  8. CONST YELLOW = _RGB32(255, 255, 0)
  9. CONST GREEN = _RGB32(0, 255, 0)
  10. CONST RED = _RGB32(255, 0, 0)
  11. CONST DARKRED = _RGB32(128, 0, 0)
  12. CONST PI = 3.1415926
  13. CONST P2 = PI / 2
  14. CONST P3 = 3 * PI / 2
  15. CONST DR = .0174533
  16.  
  17. DIM SHARED px AS SINGLE '  player position
  18. DIM SHARED pdx AS SINGLE ' delta X of player
  19. DIM SHARED pdy AS SINGLE ' delta Y of player
  20. DIM SHARED pa AS SINGLE '  angle of player
  21.  
  22. mapX = 8
  23. mapY = 8
  24. mapS = 64
  25. FOR i = 0 TO 63: READ map(i): NEXT i
  26.  
  27.  
  28. Init
  29.     _LIMIT 60
  30.     CLS , DARKGRAY
  31.     drawMap2D
  32.     drawRays2D
  33.     DrawPlayer
  34.     Buttons
  35.  
  36.  
  37.     _DISPLAY
  38.  
  39. DATA 1,1,1,1,1,1,1,1
  40. DATA 1,0,1,0,0,0,0,1
  41. DATA 1,0,1,0,0,0,0,1
  42. DATA 1,0,1,0,0,0,0,1
  43. DATA 1,0,0,0,0,0,0,1
  44. DATA 1,0,0,0,0,1,0,1
  45. DATA 1,0,0,0,0,0,0,1
  46. DATA 1,1,1,1,1,1,1,1
  47.  
  48.  
  49. FUNCTION dist (ax AS SINGLE, ay AS SINGLE, bx AS SINGLE, by AS SINGLE, ang AS SINGLE)
  50.  
  51.     dist = SQR((bx - ax) * (bx - ax) + (by - ay) * (by - ay))
  52.  
  53.  
  54.  
  55. SUB drawRays2D ()
  56.  
  57.     DIM r AS INTEGER
  58.     DIM mx AS INTEGER
  59.     DIM my AS INTEGER
  60.     DIM mp AS INTEGER
  61.     DIM dof AS INTEGER
  62.     DIM rx AS SINGLE
  63.     DIM ry AS SINGLE
  64.     DIM ra AS SINGLE
  65.     DIM xo AS SINGLE
  66.     DIM yo AS SINGLE
  67.     DIM aTan AS SINGLE
  68.     DIM nTan AS SINGLE
  69.     DIM disH AS SINGLE
  70.     DIM hx AS SINGLE
  71.     DIM hy AS SINGLE
  72.     DIM disV AS SINGLE
  73.     DIM vx AS SINGLE
  74.     DIM vy AS SINGLE
  75.     DIM disTT AS SINGLE
  76.     DIM lineH AS SINGLE
  77.     DIM lineO AS SINGLE
  78.     DIM ca AS SINGLE
  79.     DIM clr AS _UNSIGNED LONG
  80.  
  81.     ra = pa - DR * 30
  82.     IF ra < 0 THEN ra = ra + 2 * PI
  83.     IF ra > 2 * PI THEN ra = ra - 2 * PI
  84.  
  85.     FOR r = 0 TO 59
  86.         '--- Check Horizontal Lines ---
  87.         dof = 0
  88.         disH = 1000000
  89.         hx = px
  90.         hy = py
  91.         aTan = -1 / TAN(ra)
  92.         IF ra > PI THEN
  93.             'ry = ((INT(py) / 64) * 64) - .0001
  94.  
  95.             ry = INT(py / 64) * 64 - .0001
  96.  
  97.  
  98.             rx = (py - ry) * aTan + px
  99.             yo = -64
  100.             xo = -yo * aTan
  101.         END IF
  102.         IF ra < PI THEN
  103.             'ry = ((INT(py) / 64) * 64) + 64
  104.  
  105.             ry = INT(py / 64) * 64 + 64
  106.  
  107.  
  108.             rx = (py - ry) * aTan + px
  109.             yo = 64
  110.             xo = -yo * aTan
  111.         END IF
  112.         IF (ra = 0) OR (ra = PI) THEN
  113.             rx = px
  114.             ry = py
  115.             dof = 8
  116.         END IF
  117.         WHILE dof < 8
  118.             'mx = INT(rx) / 64
  119.             'my = INT(ry) / 64
  120.  
  121.             mx = INT(rx / 64)
  122.             my = INT(ry / 64)
  123.  
  124.             mp = my * mapX + mx
  125.  
  126.             'LOCATE 1, 1: PRINT mp; pa;
  127.             '_DISPLAY
  128.  
  129.             IF mp < 0 THEN mp = 0
  130.             IF mp > 63 THEN mp = 63
  131.  
  132.             'IF (mp < mapX * mapY) AND map(mp) = 1 THEN ' -- hit wall
  133.             IF map(mp) = 1 THEN
  134.                 hx = rx
  135.                 hy = ry
  136.                 disH = dist(px, py, hx, hy, ra)
  137.                 dof = 8
  138.             ELSE '                                       -- next line
  139.                 rx = rx + xo
  140.                 ry = ry + yo
  141.                 dof = dof + 1
  142.             END IF
  143.         WEND
  144.  
  145.  
  146.         '--- Check Vertical Lines ---
  147.         dof = 0
  148.         disV = 1000000
  149.         vx = px
  150.         vy = py
  151.  
  152.         nTan = -TAN(ra)
  153.         IF ra > P2 AND ra < P3 THEN
  154.             'ry = ((INT(py) / 64) * 64) - .0001
  155.  
  156.             rx = INT(px / 64) * 64 - .0001
  157.  
  158.  
  159.             ry = (px - rx) * nTan + py
  160.             xo = -64
  161.             yo = -xo * nTan
  162.         END IF
  163.         IF ra < P2 OR ra > P3 THEN
  164.             'ry = ((INT(py) / 64) * 64) + 64
  165.  
  166.             rx = INT(px / 64) * 64 + 64
  167.  
  168.  
  169.             ry = (px - rx) * nTan + py
  170.             xo = 64
  171.             yo = -xo * nTan
  172.         END IF
  173.         IF (ra = 0) OR (ra = PI) THEN
  174.             rx = px
  175.             ry = py
  176.             dof = 8
  177.         END IF
  178.         WHILE dof < 8
  179.             'mx = INT(rx) / 64
  180.             'my = INT(ry) / 64
  181.  
  182.             mx = INT(rx / 64)
  183.             my = INT(ry / 64)
  184.  
  185.             mp = my * mapX + mx
  186.  
  187.             'LOCATE 1, 1: PRINT mp; pa;
  188.             '_DISPLAY
  189.  
  190.             IF mp < 0 THEN mp = 0
  191.             IF mp > 63 THEN mp = 63
  192.  
  193.             'IF (mp < mapX * mapY) AND map(mp) = 1 THEN ' -- hit wall
  194.             IF map(mp) = 1 THEN
  195.                 vx = rx
  196.                 vy = ry
  197.                 disV = dist(px, py, vx, vy, ra)
  198.                 dof = 8
  199.             ELSE '                                       -- next line
  200.                 rx = rx + xo
  201.                 ry = ry + yo
  202.                 dof = dof + 1
  203.             END IF
  204.         WEND
  205.  
  206.         IF disV < disH THEN ' -- Vertical wall hit
  207.             rx = vx
  208.             ry = vy
  209.             disTT = disV
  210.             clr = RED
  211.         END IF
  212.         IF disH < disV THEN ' -- Horizontal wall hit
  213.             rx = hx
  214.             ry = hy
  215.             disTT = disH
  216.             clr = DARKRED
  217.         END IF
  218.  
  219.         LINE (px, py)-(rx, ry), RED
  220.  
  221.         '--- Draw 3D Walls ---
  222.  
  223.         ca = pa - ra
  224.         IF ca < 0 THEN ca = ca + 2 * PI
  225.         IF ca > 2 * PI THEN ca = ca - 2 * PI
  226.         disTT = disTT * COS(ca) '          -- fix fish eye
  227.  
  228.         lineH = mapS * 320 / disTT
  229.         IF lineH > 320 THEN lineH = 320 ' -- Line height
  230.         lineO = 160 - lineH / 2 '         -- Line offset
  231.         LINE (r * 8 + 530 - 4, lineO)-(r * 8 + 530 + 4, lineH + lineO), clr, BF
  232.  
  233.  
  234.  
  235.         ra = ra + DR
  236.         IF ra < 0 THEN ra = ra + 2 * PI
  237.         IF ra > 2 * PI THEN ra = ra - 2 * PI
  238.  
  239.  
  240.  
  241.     NEXT r
  242.  
  243.  
  244.  
  245.  
  246.  
  247. SUB drawMap2D ()
  248.  
  249.     DIM x AS INTEGER
  250.     DIM y AS INTEGER
  251.     DIM xo AS INTEGER
  252.     DIM yo AS INTEGER
  253.     DIM clr AS _UNSIGNED LONG
  254.  
  255.     FOR y = 0 TO mapY - 1
  256.         FOR x = 0 TO mapX - 1
  257.             IF map(y * mapX + x) = 1 THEN clr = WHITE ELSE clr = BLACK
  258.             xo = x * mapS
  259.             yo = y * mapS
  260.             LINE (xo + 1, yo + 1)-(xo + mapS - 1, yo + mapS - 1), clr, BF
  261.         NEXT x
  262.     NEXT y
  263.  
  264.  
  265.  
  266. SUB Buttons ()
  267.  
  268.     IF _KEYDOWN(97) THEN
  269.         pa = pa - .1
  270.         IF pa < 0 THEN pa = pa + 2 * PI
  271.     END IF
  272.     IF _KEYDOWN(100) THEN
  273.         pa = pa + .1
  274.         IF pa > 2 * PI THEN pa = pa - 2 * PI
  275.     END IF
  276.     pdx = COS(pa) * 5
  277.     pdy = SIN(pa) * 5
  278.     IF _KEYDOWN(119) THEN px = px + pdx: py = py + pdy
  279.     IF _KEYDOWN(115) THEN px = px - pdx: py = py - pdy
  280.  
  281.  
  282.  
  283. SUB DrawPlayer ()
  284.  
  285.     LINE (px - 4, py - 4)-(px + 4, py + 4), YELLOW, BF
  286.  
  287.     LINE (px, py)-(px + pdx * 5, py + pdy * 5), YELLOW
  288.  
  289.  
  290.  
  291.  
  292. SUB Init ()
  293.  
  294.  
  295.     SCREEN _NEWIMAGE(1024, 512, 32)
  296.     CLS , DARKGRAY
  297.     px = 300
  298.     py = 300
  299.     pdx = COS(pa) * 5
  300.     pdy = SIN(pa) * 5
  301.  
  302.  
  303.  

3
QB64 Discussion / Math help with puck/paddle bounce
« on: June 04, 2020, 02:12:54 pm »
Calling all math wizards. I have no idea why this problem is eluding me but I just cant seem to create the math needed for this problem I have.

A rectangular paddle of known size (rw x rh) moves only in a vertical direction.

When a ball hits the surface it needs to deflect at the tangent point of an arc instead of a flat surface.

I drew the diagram below when I set out to create the math to help as a visual aid.

Would anyone care to help with the math needed to accomplish this? I would very much appreciate it.

4
QB64 Discussion / Summer is almost here
« on: May 18, 2020, 12:32:50 pm »
I know, not the right place to put this, but I have a pic I need to share.

I live right down the road from Cedar Point and can't wait until it opens again. I was going through my images looking for some good sprites for the tutorial when I stumbled across the picture below. It's the first time my son and I were on a roller coaster together and makes me crack up every time I see it. I thought maybe someone else could use a good laugh. It's snoopy express, a very mild coaster but the look of terror on the kid's eyes is just priceless.

5
QB64 Discussion / _CLEARCOLOR Verification
« on: May 09, 2020, 03:17:46 pm »
The code below uses _CLEARCOLOR to set the transparent color of an image brought in. The image contains bright magenta (255, 0, 255) that I'm setting as the transparent color. This works fine as seen in the _PUTIMAGE line where only the red oval appears.

However...

When I try to use _CLEARCOLOR as a function later on to retrieve the transparent color I always get the value of zero. The Wiki entry on this command is very vague but the line that caught my attention is this:

"In 32-bit color modes, zero is returned."

Is zero the only value ever returned with 32bit color images? How in the world am I supposed to load an image in 32bit mode and determine the transparent color? How can I set the transparent color of a 32bit color image and then later on retrieve it? Am I missing something here?

Code: QB64: [Select]
  1. image& = _LOADIMAGE("redoval.png", 32)
  2. _CLEARCOLOR _RGB32(255, 0, 255), image&
  3. SCREEN _NEWIMAGE(640, 480, 32)
  4. CLS , _RGB32(127, 127, 127)
  5. _PUTIMAGE (10, 10), image&
  6. LOCATE 10,1
  7. PRINT _CLEARCOLOR(image&) ' always returns zero ??

6
Programs / Hocus Pocus
« on: May 07, 2020, 10:41:42 am »
While updating the tutorials I ran across this little gem called Hocus Pocus that I created to highlight color use in QB64.

You can change the CONST values at the beginning of the program to change the behavior of the color blooms. You'll also need the sound file attached.

Move the mouse around to make the magic happen.

Code: QB64: [Select]
  1. '*
  2. '* Hocus Pocus V2.2 by Terry Ritchie 01/24/14
  3. '*
  4. '* Use the mouse to create magic. Press ESC to leave this magical place.
  5. '*
  6.  
  7. '--------------------------------
  8. '- Variable Declaration Section -
  9. '--------------------------------
  10.  
  11. CONST FALSE = 0, TRUE = NOT FALSE
  12.  
  13. CONST SWIDTH = 640 '       screen width
  14. CONST SHEIGHT = 480 '      screen height
  15. CONST BLOOMAMOUNT = 5 '    number of blooms per mouse movement (don't go too high!)
  16. CONST MAXSIZE = 64 '       maximum size of blooms (don't go too high!)
  17. CONST MAXLIFE = 32 '       maximum life time on screen
  18. CONST MAXXSPEED = 6 '      maximum horizontal speed at bloom creation
  19. CONST MAXYSPEED = 10 '     maximum vertical speed at bloom creation
  20. CONST BOUNCE = FALSE '     set to TRUE to have blooms bounce off bottom of screen
  21.  
  22. TYPE CADABRA '             image properties
  23.     lifespan AS INTEGER '  life span of bloom on screen
  24.     x AS SINGLE '          x location of bloom
  25.     y AS SINGLE '          y location of bloom
  26.     size AS INTEGER '      size of bloom
  27.     xdir AS SINGLE '       horizontal direction of bloom
  28.     ydir AS SINGLE '       vertical direction of bloom
  29.     xspeed AS SINGLE '     horizontal speed of bloom
  30.     yspeed AS SINGLE '     vertical speed of bloom
  31.     image AS LONG '        bloom image handle
  32.     freed AS INTEGER '     boolean indicating if image handle has been freed
  33.  
  34. REDIM Abra(1) AS CADABRA ' dynamic array to hold properties
  35. DIM x% '                   current x position of mouse
  36. DIM y% '                   current y position of mouse
  37. DIM Oldx% '                previous x position of mouse
  38. DIM Oldy% '                previous y position of mouse
  39. DIM Blooms% '              bloom counter
  40. DIM sa& '                  Sorcerer's Apprentice sound file
  41.  
  42. '----------------------------
  43. '- Main Program Begins Here -
  44. '----------------------------
  45.  
  46. SCREEN _NEWIMAGE(SWIDTH, SHEIGHT, 32) '      create 32 bit graphics screen
  47. _SCREENMOVE _MIDDLE '                        move window to center of desktop
  48. sa& = _SNDOPEN("apprentice.ogg") '           load sound file into RAM
  49. _SNDLOOP sa& '                               play music in continuous loop
  50. _MOUSEHIDE '                                 hide the mouse pointer
  51. _MOUSEMOVE SWIDTH \ 2, SHEIGHT \ 2 '         move mouse pointer to middle of screen
  52. WHILE _MOUSEINPUT: WEND '                    get latest mouse information
  53. x% = _MOUSEX '                               get current mouse x position
  54. y% = _MOUSEY '                               get current mouse y position
  55. Oldx% = x% '                                 remember mouse x position
  56. Oldy% = y% '                                 remember mouse y position
  57. Abra(1).freed = TRUE '                       first index is free to use
  58. RANDOMIZE TIMER '                            seed random number generator
  59. DO '                                         begin main loop
  60.     _LIMIT 30 '                              30 frames per second
  61.     WHILE _MOUSEINPUT: WEND '                get latest mouse information
  62.     x% = _MOUSEX '                           get current mouse x position
  63.     y% = _MOUSEY '                           get current mouse y position
  64.     IF (Oldx% <> x%) OR (Oldy% <> y%) THEN ' has mouse moved since last loop?
  65.         FOR Blooms% = 1 TO BLOOMAMOUNT '     yes, create set number of blooms
  66.             HOCUS x%, y% '                   create bloom at current mouse location
  67.         NEXT Blooms%
  68.         Oldx% = x% '                         remember mouse x position
  69.         Oldy% = y% '                         remember mouse y position
  70.     END IF
  71.     CLS '                                    clear screen
  72.     POCUS '                                  draw active blooms
  73.     _DISPLAY '                               update screen with changes
  74. LOOP UNTIL _KEYDOWN(27) '                    leave when ESC pressed
  75. SYSTEM '                                     return to Windows
  76.  
  77. '-----------------------------------
  78. '- Function and Subroutine section -
  79. '-----------------------------------
  80.  
  81. '----------------------------------------------------------------------------------------------------------------------
  82.  
  83. SUB HOCUS (hx%, hy%)
  84.  
  85.     '*
  86.     '* Maintains the bloom array by creating bloom properties for a new bloom.
  87.     '* If no array indexes are free a new one is added to the end of the array to
  88.     '* hold the new bloom. If an unused index is available the new bloom will occupy
  89.     '* that free index position. If no blooms are currently active the array is
  90.     '* erased and reset to an index of 1 to be built again.
  91.     '*
  92.     '* hx% - x location of new bloom
  93.     '* hy% - y location of new bloom
  94.     '*
  95.  
  96.     SHARED Abra() AS CADABRA ' need access to bloom array
  97.  
  98.     DIM CleanUp% '             if true array will be reset
  99.     DIM Count% '               generic counter
  100.     DIM Index% '               array index to create new bloom in
  101.     DIM OriginalDest& '        destination screen/image of calling routine
  102.     DIM Red% '                 red color component of bloom
  103.     DIM Green% '               green color component of bloom
  104.     DIM Blue% '                blue color component of bloom
  105.     DIM RedStep% '             red fade amount
  106.     DIM GreenStep% '           green fade amount
  107.     DIM BlueStep% '            blue fade amount
  108.     DIM Alpha% '               alpha channel fade amount
  109.  
  110.     CleanUp% = TRUE '                                           assume array will need reset
  111.     Index% = 0 '                                                reset available index marker
  112.     Count% = 1 '                                                start array index counter at 1
  113.     DO WHILE Count% <= UBOUND(Abra) '                           cycle through entire array
  114.         IF Abra(Count%).lifespan = 0 THEN '                     has this image run its course?
  115.             IF NOT Abra(Count%).freed THEN '                    yes, has the image been freed from RAM?
  116.                 _FREEIMAGE Abra(Count%).image '                 no, remove the image from RAM
  117.                 Abra(Count%).freed = TRUE '                     remember that it has been removed
  118.             END IF
  119.             IF Index% = 0 THEN '                                has an available array index been chosen?
  120.                 Index% = Count% '                               no, mark this array index as available
  121.             END IF
  122.         ELSE '                                                  no, this image is still active
  123.             CleanUp% = FALSE '                                  do not clear the array
  124.         END IF
  125.         Count% = Count% + 1 '                                   increment array index counter
  126.     LOOP
  127.     IF CleanUp% THEN '                                          have all images run their course?
  128.         REDIM Abra(1) AS CADABRA '                              yes, reset the array
  129.         Abra(1).freed = TRUE '                                  there is no image here yet
  130.         Index% = 1 '                                            mark first index as available
  131.     ELSE '                                                      no, there are still active images
  132.         IF Index% = 0 THEN '                                    were all the images in the array active?
  133.             REDIM _PRESERVE Abra(UBOUND(abra) + 1) AS CADABRA ' yes, increase the array size by 1
  134.             Index% = UBOUND(abra) '                             mark top index as available
  135.         END IF
  136.     END IF
  137.     Abra(Index%).lifespan = INT(RND(1) * MAXLIFE) + 16 '        random length of time to live (frames)
  138.     Abra(Index%).x = hx% '                                      bloom x location
  139.     Abra(Index%).y = hy% '                                      bloom y location
  140.     Abra(Index%).size = INT(RND(1) * (MAXSIZE * .75) + (MAXSIZE * .25)) ' random size of bloom
  141.     Abra(Index%).xdir = (RND(1) - RND(1)) * 3 '                 random horizontal direction of bloom
  142.     Abra(Index%).ydir = -1 '                                    vertical direction of bloom (up)
  143.     Abra(Index%).xspeed = INT(RND(1) * MAXXSPEED) '             random horizontal speed of bloom
  144.     Abra(Index%).yspeed = INT(RND(1) * MAXYSPEED) '             random vertical speed of bloom
  145.     Abra(Index%).image = _NEWIMAGE(Abra(Index%).size * 2, Abra(Index%).size * 2, 32) ' create image holder
  146.     Red% = INT(RND(1) * 255) + 1 '                              random red component value
  147.     Green% = INT(RND(1) * 255) + 1 '                            random green compoenent value
  148.     Blue% = INT(RND(1) * 255) + 1 '                             random blue component value
  149.     RedStep% = (255 - Red%) \ Abra(Index%).size '               random fade of red component
  150.     GreenStep% = (255 - Green%) \ Abra(Index%).size '           random fade of green component
  151.     BlueStep% = (255 - Blue%) \ Abra(Index%).size '             random fade of blue component
  152.     AlphaStep! = 255 \ Abra(Index%).size '                      compute fade of alpha channel
  153.     Alpha% = 0 '                                                start alpha channel completely transparent
  154.     OriginalDest& = _DEST '                                     save calling routine's destination screen/image
  155.     _DEST Abra(Index%).image '                                  set destination to bloom image
  156.     Count% = Abra(Index%).size '                                start from outside of bloom working in
  157.     DO WHILE Count% > 0 '                                       start bloom drawing loop
  158.         '*
  159.         '* Draw circle with current red, green, blue components
  160.         '*
  161.         CIRCLE (_WIDTH(Abra(Index%).image) / 2, _HEIGHT(Abra(Index%).image) / 2), Count%, _RGB32(Red%, Green%, Blue%)
  162.         '*
  163.         '* Paint circle with current red, green, blue components
  164.         '*
  165.         PAINT (_WIDTH(Abra(Index%).image) / 2, _HEIGHT(Abra(Index%).image) / 2), _RGB32(Red%, Green%, Blue%), _RGB32(Red%, Green%, Blue%)
  166.         _SETALPHA Alpha%, _RGB32(Red%, Green%, Blue%) '         set transparency level of current color
  167.         Red% = Red% + RedStep% '                                increase red component
  168.         Green% = Green% + GreenStep% '                          increase green component
  169.         Blue% = Blue% + BlueStep% '                             increase blue component
  170.         Alpha% = Alpha% + AlphaStep! '                          increase opacity level of alpha channel
  171.         Count% = Count% - 1 '                                   decrease size of circle
  172.     LOOP '                                                      leave loop when smallest circle drawn
  173.     _DEST OriginalDest& '                                       return original destination to calling routine
  174.  
  175.  
  176. '----------------------------------------------------------------------------------------------------------------------
  177.  
  178. SUB POCUS ()
  179.  
  180.     '*
  181.     '* places active blooms onto the screen or current image and updates their
  182.     '* position, size and speed
  183.     '*
  184.  
  185.     SHARED Abra() AS CADABRA ' need access to bloom array
  186.  
  187.     DIM c% '                   array index counter
  188.     DIM o% '                   bloom image size x,y offset
  189.  
  190.     c% = UBOUND(Abra) '                                                 start at top of array
  191.     DO WHILE c% > 0 '                                                   loop until beginning of array
  192.         IF Abra(c%).lifespan > 0 THEN '                                 is this bloom active?
  193.             o% = INT(Abra(c%).size) '                                   yes, get current size of bloom image
  194.             _PUTIMAGE (Abra(c%).x - o%, Abra(c%).y - o%)-(Abra(c%).x + o%, Abra(c%).y + o%), Abra(c%).image
  195.             Abra(c%).lifespan = Abra(c%).lifespan - 1 '                 decrement lifespan of bloom
  196.             Abra(c%).size = Abra(c%).size * .95 '                       decrease size of bloom slightly
  197.             Abra(c%).x = Abra(c%).x + Abra(c%).xdir * Abra(c%).xspeed ' update x position of bloom
  198.             Abra(c%).y = Abra(c%).y + Abra(c%).ydir * Abra(c%).yspeed ' update y position of bloom
  199.             IF Abra(c%).y > SHEIGHT - 1 THEN '                          has bloom left bottom of screen?
  200.                 IF BOUNCE THEN '                                        should bloom bounce?
  201.                     Abra(c%).yspeed = -Abra(c%).yspeed '                yes, reverse y velocity
  202.                 ELSE '                                                  no
  203.                     Abra(c%).lifespan = 0 '                             kill it, no longer needed
  204.                 END IF
  205.             END IF
  206.             Abra(c%).xspeed = Abra(c%).xspeed * .9 '                    decrease x velocity slightly
  207.             Abra(c%).yspeed = Abra(c%).yspeed - .5 '                    decrease y velocity (simulating gravity)
  208.         END IF
  209.         c% = c% - 1 '                                                   decrement to next index in array
  210.     LOOP
  211.  
  212.  
  213. '----------------------------------------------------------------------------------------------------------------------
  214.  

7
QB64 Discussion / _SCREENIMAGE Fuzzy [solved]
« on: May 02, 2020, 10:14:42 pm »
I found some funky behavior with _SCREENIMAGE. If the width of a screen shot exceeds 1024 (0 - 1023) the image always comes out fuzzy as though it is being resized.

Desktop& = _SCREENIMAGE(0, 0, 1023, 600) ' not fuzzy

Desktop& = _SCREENIMAGE(0, 0, 1024, 600) ' fuzzy (anything over 1023)

Desktop& = _SCREENIMAGE ' fuzzy if over 1024 wide

Bug perhaps?

8
QB64 Discussion / _LOADIMAGE supported image types
« on: April 28, 2020, 04:39:39 pm »
What's the official image types supported by _LOADIMAGE? In the Wiki this is stated:

"Various common image file formats supported, like BMP, JPG, PNG, etc. A path can also be given."

It's the "etc." that is throwing me. Are there more than just BMP, JPG, and PNG? I know in the SDL version the following were supported:

BMP, JPG, PNG, GIF, PNM, XPM, XCF, PCX, TIF, LBM, and TGA.

Does that still hold true for later versions?

9
QB64 Discussion / _SNDLIMIT Behavior (not a bug)
« on: April 27, 2020, 05:55:18 pm »
_SNDLIMIT behaves differently from what it used to. This code:

Code: QB64: [Select]
  1. DIM WilliamTell&
  2. DIM Count%
  3.  
  4. WilliamTell& = _SNDOPEN("WilliamTell.ogg")
  5. PRINT " The first five seconds of the William Tell Overture"
  6. _SNDLIMIT WilliamTell&, 5
  7. _SNDPLAY WilliamTell&
  8. FOR Count% = 1 TO 5
  9.     _DELAY 1
  10.     PRINT Count%; "..";
  11. NEXT Count%
  12. _SNDCLOSE WilliamTell&

Behaves very strangely. Not only does _LIMIT not work, the _SNDCLOSE statement does not stop the sound from playing. However simply placing the _SNDLIMIT line after the _SNDPLAY line clears everything up and the code works as expected.


oops...hold on...

After switching these two lines around a few times _SNDLIMIT isn't working in either case now?? Maybe a bug?


10
QB64 Discussion / BEEP
« on: April 27, 2020, 01:33:58 pm »
Just curious, when did QB64 lose the ability to produce a beep tone by using this?

PRINT CHR$(7) ' ASCII BEL character

While redoing my tutorials I came across this. I'm working on the sound tutorial now and loading some of the old programs didn't beep when they were supposed to.

ASCII values of 7 were used when terminals needed to send an audible alert to users.


11
QB64 Discussion / QB64SOURCECODE.COM
« on: April 19, 2020, 01:20:56 pm »
I've been working on updating the QB64 tutorials at https://www.qb64sourcecode.com for the past 3 weeks.

I should be finished by no later than the end of May. I have 10 lessons done so far. I modernized the pages a bit by using Windows 10 screen shots and the look of today's QB64 IDE.

If you get a chance look over what I have and let me know if you see any glaring issues that need corrected.

Thanks, Terry.

12
QB64 Discussion / REDIM _PRESERVE bug
« on: March 28, 2020, 05:00:32 pm »
Is there any time line on when this bug may get corrected? I really need to be able to preserve values across multi-dimensional arrays.

Code: QB64: [Select]
  1. 'REDIM _PRESERVE bug in multiple dimensioned arrays.
  2.  
  3.  
  4. REDIM Test(0, 0)
  5.  
  6.  
  7. FOR i = 0 TO 9
  8.     Test(0, i) = i
  9.     PRINT Test(0, i)
  10.     REDIM _PRESERVE Test(0, UBOUND(test, 2) + 1)
  11.  
  12. FOR i = 0 TO 9
  13.     PRINT Test(0, i)
  14. PRINT "That works. But when you REDIM the other index this happens."
  15. REDIM _PRESERVE Test(1, UBOUND(Test, 2))
  16. FOR i = 0 TO 9
  17.     PRINT Test(0, i), Test(1, i)
  18. PRINT "The values get spread across both indexes."

13
Programs / Simple Piano
« on: March 25, 2020, 02:25:21 pm »
I was going through my QB64 tutorials and forget about this little program I wrote back in 2014. It's a one-octave piano simulator that allows you to switch between octaves. The asset files (images and sounds) are contained in the attached PIANO.zip file. Be sure to place the \PIANO folder in your QB64 folder (the programs looks for the .\PIANO\ folder when loading assets.

Directions for use are at the top of the source code listing.

Note: I wrote this using version 0.954 and because of that the sounds are loaded using options not available in the latest versions of QB64. If you compile this using an SDL version of QB64 the piano keys will stop the sound as soon as you release them. In non SDL versions of QB64 the key sustains even after released.

Code: QB64: [Select]
  1. '*
  2. '* QB64 Simple Piano
  3. '*
  4. '* by Terry Ritchie
  5. '*
  6. '* Demonstrates the use of external sound files to create a realistic piano.
  7. '*
  8. '* ESC         - exit program
  9. '* RIGHT ARROW - increase octave
  10. '* LEFT ARROW  - decrease octave
  11. '* Piano Keys  -  R T  U I O   (black keys)
  12. '*             - D F GH J K L  (white keys)
  13. '*
  14.  
  15. '--------------------------------
  16. '- Variable Declaration Section -
  17. '--------------------------------
  18.  
  19. TYPE IVORY '          key information
  20.     u AS INTEGER '    upper case value
  21.     l AS INTEGER '    lower case value
  22.     Down AS INTEGER ' key position
  23.     x AS INTEGER '    key indicator x coordinate
  24.     y AS INTEGER '    key indicator y coordinate
  25.  
  26. DIM K(12) AS IVORY '  key information array
  27. DIM Tone&(88) '       piano key sounds array
  28. DIM imgPiano& '       piano keyboard image
  29. DIM imgAoctave& '     active octave image
  30. DIM imgIoctave& '     inactive octave image
  31. DIM Octave% '         current octave
  32. DIM Khit& '           keyboard status
  33. DIM Keys% '           key cycle counter
  34.  
  35. '----------------------------
  36. '- Main Program Begins Here -
  37. '----------------------------
  38.  
  39. LOADPIANO '                                                          load piano assets
  40. SCREEN _NEWIMAGE(512, 263, 32) '                                     create default screen
  41. _TITLE "PIANO" '                                                     set window title
  42. _SCREENMOVE _MIDDLE '                                                center window on desktop
  43. _DELAY .25
  44. _PUTIMAGE (0, 0), imgPiano& '                                        show piano image
  45. SHOWOCTAVE '                                                         update octave indicator
  46. DO '                                                                 MAIN LOOP begins
  47.     Khit& = _KEYHIT '                                                get keyboard status
  48.     IF Khit& THEN '                                                  was a key hit?
  49.         IF Khit& = 19200 OR Khit& = 19712 THEN '                     yes, left or right key?
  50.             IF Khit& = 19200 THEN '                                  yes, left key?
  51.                 Octave% = Octave% - 1 '                              yes, decrease octave
  52.                 IF Octave% = -1 THEN Octave% = 0 '                   keep octave in limits
  53.             ELSE '                                                   no, must be right key
  54.                 Octave% = Octave% + 1 '                              increase octave
  55.                 IF Octave% = 5 THEN Octave% = 4 '                    keep octave in limits
  56.             END IF
  57.             SHOWOCTAVE '                                             update octave indicator
  58.         ELSEIF Khit& = 27 THEN '                                     no, escape key?
  59.             QUIT '                                                   yes, quit program
  60.         END IF
  61.     END IF
  62.     FOR Keys% = 1 TO 12 '                                            cycle through keys
  63.         IF _KEYDOWN(K(Keys%).u) OR _KEYDOWN(K(Keys%).l) THEN '       key pressed?
  64.             PRESS Keys% '                                            yes, play note
  65.         ELSE '                                                       no
  66.             RELEASE Keys% '                                          remove key indicator
  67.         END IF
  68.     NEXT Keys%
  69.     _DISPLAY '                                                       update screen changes
  70. LOOP '                                                               MAIN LOOP back
  71.  
  72. '-----------------------------------
  73. '- Function and Subroutine section -
  74. '-----------------------------------
  75.  
  76. '--------------------------------------------------------------------------------------------
  77.  
  78. SUB QUIT ()
  79.  
  80.     '*
  81.     '* Cleans RAM by removing all image and sound assets and then exits to Windows.
  82.     '*
  83.  
  84.     SHARED Tone&() '     need access to piano key sounds array
  85.     SHARED imgPiano& '   need access to piano keyboard image
  86.     SHARED imgAoctave& ' need access to active octave image
  87.     SHARED imgIoctave& ' need access to inactive octave image
  88.  
  89.     DIM Count% '         generic counter
  90.  
  91.     FOR Count% = 1 TO 88 '        cycle through all 88 sound files
  92.         _SNDCLOSE Tone&(Count%) ' remove sound file from RAM
  93.     NEXT Count%
  94.     _FREEIMAGE imgPiano& '        remove piano image from RAM
  95.     _FREEIMAGE imgAoctave& '      remove active octave image from RAM
  96.     _FREEIMAGE imgIoctave& '      remove inactive octave image from RAM
  97.     SYSTEM '                      return to Windows
  98.  
  99.  
  100. '--------------------------------------------------------------------------------------------
  101.  
  102. SUB RELEASE (k%)
  103.  
  104.     '*
  105.     '* Removes key press display and sets key as being released
  106.     '*
  107.  
  108.     SHARED K() AS IVORY ' need access to key information array
  109.  
  110.     IF K(k%).Down THEN '                                                  is key pressed?
  111.         K(k%).Down = 0 '                                                  yes, set it as released
  112.         SELECT CASE k% '                                                  which key is it?
  113.             CASE 1, 3, 5, 6, 8, 10, 12 '                                  white key
  114.                 LINE (K(k%).x, K(k%).y)-(K(k%).x + 27, K(k%).y + 27), _RGB32(255, 255, 255), BF
  115.             CASE ELSE '                                                   black key
  116.                 LINE (K(k%).x, K(k%).y)-(K(k%).x + 27, K(k%).y + 27), _RGB32(32, 32, 32), BF
  117.         END SELECT
  118.     END IF
  119.  
  120.  
  121. '--------------------------------------------------------------------------------------------
  122.  
  123. SUB PRESS (k%)
  124.  
  125.     '*
  126.     '* Applies key press display and sets key as being pressed
  127.     '*
  128.  
  129.     SHARED K() AS IVORY ' need access to key information array
  130.     SHARED Tone&() '      need access to piano key sounds array
  131.     SHARED Octave% '      need access to current octave
  132.  
  133.     IF NOT K(k%).Down THEN '                                               is key released?
  134.         K(k%).Down = -1 '                                                  yes, set it as pressed
  135.         _SNDPLAY Tone&(Octave% * 12 + k%) '                                play tone for key
  136.         SELECT CASE k% '                                                   which key is it?
  137.             CASE 1, 3, 5, 6, 8, 10, 12 '                                   white key
  138.                 LINE (K(k%).x, K(k%).y)-(K(k%).x + 27, K(k%).y + 27), _RGB32(0, 0, 0), BF
  139.             CASE ELSE '                                                    black key
  140.                 LINE (K(k%).x, K(k%).y)-(K(k%).x + 27, K(k%).y + 27), _RGB32(255, 255, 255), BF
  141.         END SELECT
  142.     END IF
  143.  
  144.  
  145. '--------------------------------------------------------------------------------------------
  146.  
  147. SUB SHOWOCTAVE
  148.  
  149.     '*
  150.     '* Updates the small top piano keyboard to show current active octave
  151.     '*
  152.  
  153.     SHARED Octave% '     need access to current octave
  154.     SHARED imgAoctave& ' need access to active octave image
  155.     SHARED imgIoctave& ' need access to inactive octave image
  156.  
  157.     DIM Count% '         generic counter
  158.  
  159.     FOR Count% = 0 TO 4 '                                    cycle through octaves
  160.         IF Count% = Octave% THEN '                           current octave?
  161.             _PUTIMAGE (96 + (Count% * 64), 0), imgAoctave& ' yes, place active octave image
  162.         ELSE '                                               no
  163.             _PUTIMAGE (96 + (Count% * 64), 0), imgIoctave& ' place inactive octave image
  164.         END IF
  165.     NEXT Count%
  166.  
  167.  
  168. '--------------------------------------------------------------------------------------------
  169.  
  170. SUB LOADPIANO ()
  171.  
  172.     '*
  173.     '* Loads the piano sounds and images and initializes variables
  174.     '*
  175.  
  176.     SHARED K() AS IVORY ' need access to key information array
  177.     SHARED Tone&() '      need access to piano key sounds array
  178.     SHARED imgPiano& '    need access to piano keyboard image
  179.     SHARED imgAoctave& '  need access to active octave image
  180.     SHARED imgIoctave& '  need access to inactive octave image
  181.     SHARED Octave% '      need access to current octave
  182.  
  183.     DIM Note% '           counter used to open sounds
  184.     DIM Count% '          counter used to close sounds if error
  185.     DIM Path$ '           path to sound and graphics files
  186.     DIM File$ '           sound file names
  187.  
  188.     Path$ = ".\PIANO\"
  189.     IF _DIREXISTS(Path$) THEN '                                        path exist?
  190.         FOR Note% = 1 TO 88 '                                          cycle through notes
  191.             File$ = Path$ + LTRIM$(STR$(Note%)) + ".ogg" '             construct file name
  192.             IF _FILEEXISTS(File$) THEN '                               sound file exist?
  193.                 Tone&(Note%) = _SNDOPEN(File$, "VOL,SYNC,LEN,PAUSE") ' yes, load sound file
  194.             ELSE '                                                     no, sound file missing
  195.                 PRINT '                                                report error to user
  196.                 PRINT " ERROR: Sound file "; File$; " is missing."
  197.                 IF Note% > 1 THEN '                                    did any sounds load?
  198.                     FOR Count% = Note% TO 1 STEP -1 '                  yes, cycle notes backwards
  199.                         _SNDCLOSE Tone&(Count%) '                      remove sound from RAM
  200.                     NEXT Count%
  201.                     END '                                              end program
  202.                 END IF
  203.             END IF
  204.         NEXT Note%
  205.     ELSE '                                                             no, path missing
  206.         PRINT '                                                        report error to user
  207.         PRINT " ERROR: The \PIANO\ folder could not be found."
  208.         END '                                                          end program
  209.     END IF
  210.     IF _FILEEXISTS(Path$ + "piano.png") THEN '                     image file exist?
  211.         imgPiano& = _LOADIMAGE(Path$ + "piano.png", 32) '          yes, load image file
  212.     ELSE '                                                         no, image file missing
  213.         PRINT '                                                    report error to user
  214.         PRINT " ERROR: piano.png missing."
  215.         END '                                                      end program
  216.     END IF
  217.     IF _FILEEXISTS(Path$ + "active.png") THEN '                    image file exist?
  218.         imgAoctave& = _LOADIMAGE(Path$ + "active.png", 32) '       yes, load image file
  219.     ELSE '                                                         no, image file missing
  220.         PRINT '                                                    report error to user
  221.         PRINT " ERROR: active.png missing."
  222.         _FREEIMAGE imgPiano& '                                     remove image from RAM
  223.         END '                                                      end program
  224.     END IF
  225.     IF _FILEEXISTS(Path$ + "inactive.png") THEN '                  image file exist?
  226.         imgIoctave& = _LOADIMAGE(Path$ + "inactive.png", 32) '     yes, load image file
  227.     ELSE '                                                         no, image file missing
  228.         PRINT '                                                    report error to user
  229.         PRINT " ERROR: inactive.png missing."
  230.         _FREEIMAGE imgPiano& '                                     remove image from RAM
  231.         _FREEIMAGE imgAoctave& '                                   remove image from RAM
  232.         END '                                                      end program
  233.     END IF
  234.  
  235.     K(1).x = 22: K(1).y = 212: K(2).x = 60: K(2).y = 132 '             set indicator coordinates
  236.     K(3).x = 95: K(3).y = 212: K(4).x = 134: K(4).y = 132
  237.     K(5).x = 168: K(5).y = 212: K(6).x = 241: K(6).y = 212
  238.     K(7).x = 278: K(7).y = 132: K(8).x = 314: K(8).y = 212
  239.     K(9).x = 353: K(9).y = 132: K(10).x = 387: K(10).y = 212
  240.     K(11).x = 428: K(11).y = 132: K(12).x = 460: K(12).y = 212
  241.     K(1).l = 100: K(1).u = 68: K(2).l = 114: K(2).u = 82 '             set key case values
  242.     K(3).l = 102: K(3).u = 70: K(4).l = 116: K(4).u = 84
  243.     K(5).l = 103: K(5).u = 71: K(6).l = 104: K(6).u = 72
  244.     K(7).l = 117: K(7).u = 85: K(8).l = 106: K(8).u = 74
  245.     K(9).l = 105: K(9).u = 73: K(10).l = 107: K(10).u = 75
  246.     K(11).l = 111: K(11).u = 79: K(12).l = 108: K(12).u = 76
  247.     Octave% = 2 '                                                      set initial octave
  248.  
  249.  
  250. '--------------------------------------------------------------------------------------------
  251.  

14
QB64 Discussion / Strange things are afoot at the Circle K
« on: March 21, 2020, 12:43:04 pm »
Lately I've been getting a few anomalous bugs in my code that are very hard to track down and I believe I know the reason.

I've never taken the time zeroize or clear string contents in newly created arrays or variables in BASIC because that seems to have always been done automagically since the days of BASIC 80. However QB64 seems to not be exhibiting the behavior any longer. This seems especially true for variables defined as _BYTE inside and outside of TYPE statements. (I use _BYTE for boolean TRUE(-1) and FALSE(0) flags).

Many times my "bugs" disappear when I take the time to zeroize the arrays and variables I create ... in other words I can't assume any longer that variables and strings will be set to 0 or null when newly created.

Has anyone else run across this behavior? When I have time I'll try to create some code that shows this happening.

15
InForm Discussion / UI Theme Editor
« on: March 12, 2020, 04:11:49 pm »
Fellippe, is there an InForm theme editor available? I would like to create a Windows 2000 theme (aka "Classic Windows") for InForm if possible. If no editor then perhaps information posted somewhere with details on how to create another UI theme? I get the basic idea that the images have been converted using DAV's BIN/BAS and they are recreated as needed later on, just not sure where to begin.

By the way, I studied the InForm source code in some detail last night. What an amazing piece of work.

Pages: [1] 2 3 4