QB64 Phoenix Edition
Proggies - Printable Version

+- QB64 Phoenix Edition (https://qb64phoenix.com/forum)
+-- Forum: QB64 Rising (https://qb64phoenix.com/forum/forumdisplay.php?fid=1)
+--- Forum: Prolific Programmers (https://qb64phoenix.com/forum/forumdisplay.php?fid=26)
+---- Forum: bplus (https://qb64phoenix.com/forum/forumdisplay.php?fid=36)
+---- Thread: Proggies (/showthread.php?tid=162)

Pages: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25


RE: Proggies - bplus - 08-17-2025

OK that fixed Smile  now for detecting the y keypress to play again?


RE: Proggies - hsiangch_ong - 08-17-2025

https://qb64phoenix.com/forum/showthread.php?tid=162&pid=30990#pid30990

(post #223 if you're logged in.  post #205 if not logged in.  the summer is hot for me.)

maybe somebody proposed changes like this.  but it might not work on qbjs.

when pressing "any" key.  even a shift key alone.  it was like pressing minus or plus.  also i desired escape to get out of the program.  didn't care to have to press enter only.  so here is how i fixed it.

Code: (Select All)
'Option _Explicit
_Title "Spinner 2 press enter to save imagee, try + and - " 'b+ 2021-06-18

' 2023-09-25 convert to QBJS
' 2023-09-27 use FArc for Fat Arcs!
' 2025-01-01
$If WEB Then
        import G2D From "lib/graphics/2d.bas"
$End If

Dim As Long b, r, kh, stepper
Dim a
Dim K As _Unsigned Long
Screen _NewImage(700, 700, 32): _ScreenMove 250, 0
stepper = 5
DO
    Cls , &HFFDDDDFF
    b = b + 1
    For r = 10 To 330 Step stepper ' tsh73 suggested fix for inner most
        a = _D2R(b * r / (2 * stepper))
        If Int(r / stepper) Mod 2 Then K = &HFF00AA66 Else K = &HFF000066
        FArc 350, 350, r, .4 * stepper, a, a + _Pi, K
    Next
    _Display
    DO
        kh = 0
        While kh = 0: kh = _KeyHit: Wend
        If kh = 13 Then _SaveImage "spinner2.png": End
        If kh = 43 Then stepper = stepper + 1
        If kh = 45 Then stepper = stepper - 1
    LOOP UNTIL kh = 13 OR kh = 27 OR kh = 43 OR kh = 45
LOOP UNTIL kh = 27
SYSTEM

'2023-02-04 Fill Arc draw an arc with thickness, tested in Profile Pong 3-0
' this sub needs sub FCirc(CX As Long, CY As Long, R As Long, C As _Unsigned Long) for dots
Sub FArc (x, y, r, thickness, RadianStart, RadianStop, c As _Unsigned Long)
    Dim al, a
    'x, y origin of arc, r = radius, thickness is radius of dots, c = color
    'RadianStart is first angle clockwise from due East = 0 in Radians
    ' arc will start drawing there and clockwise until RadianStop angle reached

    If RadianStop < RadianStart Then
        FArc x, y, r, thickness, RadianStart, _Pi(2), c
        FArc x, y, r, 0, thickness, RadianStop, c
    Else
        al = _Pi * r * r * (RadianStop - RadianStart) / _Pi(2)
        For a = RadianStart To RadianStop Step 1 / r
            FCirc x + r * Cos(a), y + r * Sin(a), thickness, c
        Next
    End If
End Sub

' modified for QBJS AND QB64
Sub FCirc (CX As Long, CY As Long, R As Long, C As _Unsigned Long)

    ' put this at top of QB64 to QBJS code
    '$If WEB Then
    '        import G2D From "lib/graphics/2d.bas"
    '$End If


    $If WEB Then
            G2D.FillCircle CX, CY, R, C
    $Else
        Dim Radius As Long, RadiusError As Long
        Dim X As Long, Y As Long
        Radius = Abs(R): RadiusError = -Radius: X = Radius: Y = 0
        If Radius = 0 Then PSet (CX, CY), C: Exit Sub
        Line (CX - X, CY)-(CX + X, CY), C, BF
        While X > Y
            RadiusError = RadiusError + Y * 2 + 1
            If RadiusError >= 0 Then
                If X <> Y + 1 Then
                    Line (CX - Y, CY - X)-(CX + Y, CY - X), C, BF
                    Line (CX - Y, CY + X)-(CX + Y, CY + X), C, BF
                End If
                X = X - 1
                RadiusError = RadiusError - X * 2
            End If
            Y = Y + 1
            Line (CX - X, CY - Y)-(CX + X, CY - Y), C, BF
            Line (CX - X, CY + Y)-(CX + X, CY + Y), C, BF
        Wend
    $End If
End Sub



RE: Proggies - bplus - 08-17-2025

@hsiangch_ong

Your "fix" breaks the ability for it to spin! Pressing any key (spacebar was the intended key) was needed to spin the thing.
After I got code working I wanted to take snapshots to show off different aspects so I used a spacebar key press to spin the thing to a point where I wanted to take a snapshot. The +/- keys were for just adding or subtracting arcs to spinner while it was spinning.

Just add line to main loop like this:
Code: (Select All)
While 1
    Cls , &HFFDDDDFF
    b = b + 1
    For r = 10 To 330 Step stepper ' tsh73 suggested fix for inner most
        a = _D2R(b * r / (2 * stepper))
        If Int(r / stepper) Mod 2 Then K = &HFF00AA66 Else K = &HFF000066
        FArc 350, 350, r, .4 * stepper, a, a + _Pi, K
    Next
    _Display
    kh = 0
    While kh = 0: kh = _KeyHit: Wend
    If kh = 13 Then _SaveImage "spinner2.png": End
    If kh = 43 Then stepper = stepper + 1
    If kh = 45 Then stepper = stepper - 1
    If kh = 27 Then System ' <<<<<<<<<<<<<<<<<<<<<<<< add line for escape
Wend



RE: Proggies - dbox - 08-17-2025

(08-17-2025, 12:08 AM)bplus Wrote: OK that fixed Smile  now for detecting the y keypress to play again?
Interesting, it works for me.  It's possible that because it's in such a tight loop at the end that it was not processing the keypresses.  You could try adding the following call to _Limit to the loop starting on line 248 to see if it works any better for you.  It's working for me either way.

Code: (Select All)
    again$ = INKEY$
    WHILE LEN(again$) = 0
        again$ = INKEY$
        _LIMIT 60
    WEND



RE: Proggies - SMcNeill - 08-17-2025

You might also want a _KEYCLEAR before that loop, just in case there was something in the INKEY$ buffer making it exit automatically before entering the pause loop.


RE: Proggies - bplus - 08-17-2025

Ok I tried _Limit 60 first and then _KeyClear and neither worked ?

One of Life's Mysteries I guess. I did find the strike zone though Smile

   


RE: Proggies - bplus - 08-18-2025

I am up at 4:04 am thinking I have solution to Mystery, Nope!

And even Input "";again$ doesn't work though the ? for Input does appear at the top of screen.

Nope QBJS is doing the logic of all those loops inside loops different than regular QB64pe does.

Oh and talk about differences between QBJS and QB64pe, in QB64 you can see the intended 2 skinny circles in the top view of the pins:
   

Anybody else find the sure strike zone yet?


RE: Proggies - bplus - 08-18-2025

(08-17-2025, 08:39 PM)dbox Wrote:
(08-17-2025, 12:08 AM)bplus Wrote: OK that fixed Smile  now for detecting the y keypress to play again?
Interesting, it works for me.  It's possible that because it's in such a tight loop at the end that it was not processing the keypresses.  You could try adding the following call to _Limit to the loop starting on line 248 to see if it works any better for you.  It's working for me either way.

Code: (Select All)
    again$ = INKEY$
    WHILE LEN(again$) = 0
        again$ = INKEY$
        _LIMIT 60
    WEND

Just to be clear the Bowling code in your QBJS samples is working for you because you played through a whole game and are able to reply to prompt with a y for yes and it works by starting another game of that Bowling code in a Browser? You played a whole game with the code as is in a browser, you didn't just test a little snippet?


RE: Proggies - dbox - 08-18-2025

(08-18-2025, 12:24 PM)bplus Wrote: Just to be clear the Bowling code in your QBJS samples is working for you because you played through a whole game and are able to reply to prompt with a y for yes and it works by starting another game of that Bowling code in a Browser? You played a whole game with the code as is in a browser, you didn't just test a little snippet?

Yep, I played through the whole thing.  It prompted me to play again.  I hit ‘y’ and it started a new game.

(Also, you are correct that the circles may look a little different in QBJS as they are slightly thicker and antialiased.)


RE: Proggies - bplus - 08-18-2025

OK thanks different systems = different results.