Author Topic: QBJS - QBasic for the Web  (Read 40963 times)

0 Members and 1 Guest are viewing this topic.

Offline dbox

  • Newbie
  • Posts: 80
    • View Profile
Re: QBJS - QBasic for the Web
« Reply #30 on: February 18, 2022, 11:40:46 pm »
@dbox
 I almost have this guy roughed out but _delay is not working

Sleep is messing with Keypresses need a _KeyClear

I tried my own version of sleep and that worked perfect in QB64 keeping inkey$ clear for next letter but QBJS ignored code. So I am just trying _delay to give user time to read what happened before next round starts.


Hey @bplus, looking good so far.  _KeyClear should be easy to add.  I'll put that on the top of the list.  Thanks for the good feedback! I'll also look into what's happening with _Delay in your example.

Offline DANILIN

  • Forum Regular
  • Posts: 128
    • View Profile
    • Danilin youtube
Re: QBJS - QBasic for the Web
« Reply #31 on: February 19, 2022, 01:42:03 am »
https://boxgm.itch.io/qbjs

does work... goto & labels ?
does work... circle ? 

Circle (100,150),25,5
QB.sub_Circle(false, 100, 150, 25, 5);

so far: has been calculated in this shell only ... factorial
« Last Edit: February 19, 2022, 04:09:32 am by DANILIN »
Russia looks world from future. big data is peace data.
https://youtube.com/playlist?list=PLBBTP9oVY7IagpH0g9FNUQ8JqmHwxDDDB
i never recommend anything to anyone and always write only about myself

Offline dbox

  • Newbie
  • Posts: 80
    • View Profile
Re: QBJS - QBasic for the Web
« Reply #32 on: February 19, 2022, 07:21:17 am »
@DANILIN

Goto and labels are not currently supported.

Circle is supported but I have not mapped the color table for the legacy screen modes.  I do plan to, but at the moment colors need to be defined with the _RGB or _RGB32 function:

Code: QB64: [Select]
  1. Circle (100,150), 25, _RGB(100,255,50)
  2.  

Offline DANILIN

  • Forum Regular
  • Posts: 128
    • View Profile
    • Danilin youtube
Re: QBJS - QBasic for the Web
« Reply #33 on: February 19, 2022, 08:37:06 am »
theoretically it works and there will still be uncovered functions

Code: [Select]
https://v6p9d9t4.ssl.hwcdn.net/html/5279712/index.html?qbcode=BOAQAHvAN8AKgkRJTdAZAAoXAKeoqmhqSKipyQDEAGU8JGT1J4BrvX7QVRPmANV/mKmJ6GgqiLuQBZhedrgNLi5u74BUByQkEkpypd+EpJyI3AKngBzqAYOgCt17aAOnpc0Mr2uQC1+rKy2AJCIaemJ6ldgL5ASkjoWv85k1Dw9iQxYBOIoKSSnKiqwahpyKsKhmRj386O3dc5evgfr8ARWQlNVTat3cAdo7R4sO6CrTu2sA3zLCr3M8MABel2HGdsigqCT3N2gCUCkoyfp9fIB9d+o/eeqAaokIqct+vmkcP8XlAhAF16wFBAdEABqbZcVdbdgamqIqg7PyAaSAf02mT63kAD6u2cYSanojLrLaBnlFQ0lSQ0xFevQDPXcbjl77g6eKWR+y6nvunuY7+59bZr2j71+/1r2s8+o51fcs7iIepdVa/OF86kziuad/vll7bv9/cAAxgkVORGFwADqfyx7vySbA5ev3nc6Rgz7Ss1qgbQXP1u95alLv23f866+47/n2+h/HjfEZt+4rdxsziXF++5akvvuWtR77557OuvYfez3YAHdXfsA72wCjqiIiKmIKy1d1xIBtsMXYUcSrvT4=
 
dia.PNG


This is Danilin Russian Circle Diagram
https://qb64forum.alephc.xyz/index.php?topic=4367.msg138214#msg138214
« Last Edit: February 20, 2022, 07:44:22 am by DANILIN »
Russia looks world from future. big data is peace data.
https://youtube.com/playlist?list=PLBBTP9oVY7IagpH0g9FNUQ8JqmHwxDDDB
i never recommend anything to anyone and always write only about myself

Offline dbox

  • Newbie
  • Posts: 80
    • View Profile
Re: QBJS - QBasic for the Web
« Reply #34 on: February 19, 2022, 08:46:00 am »
Nice @DANILIN, cool example!

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: QBJS - QBasic for the Web
« Reply #35 on: February 19, 2022, 11:56:17 am »
+1 I am still trying to get a graphics working, so far getting 0 drawn from small apps.

Offline dbox

  • Newbie
  • Posts: 80
    • View Profile
Re: QBJS - QBasic for the Web
« Reply #36 on: February 19, 2022, 12:44:06 pm »
@bplus can you share the code that is not working?

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: QBJS - QBasic for the Web
« Reply #37 on: February 19, 2022, 12:55:49 pm »
Sure here is last simple one that I've cut and cut, turns out I use one liner IF's allot and also :'s that are so common I don't see them.  Connett Circles:
Code: QB64: [Select]
  1. Const xmax = 600
  2. Const ymax = 600
  3.  
  4. Dim As Integer i, j, s, sq
  5. Dim As Double x, y, c, d
  6.  
  7. Screen _NewImage(xmax, ymax, 32)
  8.  
  9. s = 1
  10. sq = 5
  11.     For j = 0 To ymax / sq
  12.         For i = 0 To xmax / sq
  13.             x = i * s / 600
  14.             y = j * s / 600
  15.             c = x * x + y * y
  16.             d = c / 2
  17.             d = d - Int(d)
  18.             d = Int(d * 1000)
  19.             If d < 250 Then
  20.                 cc = _RGB32(d, 0, 0)
  21.             ElseIf d < 500 Then
  22.                 cc = _RGB32(0, d - 250, 0)
  23.             ElseIf d < 750 Then
  24.                 cc = _RGB32(0, 0, d - 500)
  25.             Else
  26.                 cc = _RGB32(255, 255, 255)
  27.             End If
  28.             Line (i * sq, j * sq)-Step(sq, sq), cc, BF
  29.         Next
  30.     Next
  31.     _Delay 2
  32.     'Color _RGB32(255, 255, 255)
  33.     'Locate 1, 1
  34.     'Print s
  35.     s = s + 15
  36.     If s > 1000 Then  ' it was this on one line!
  37.         s = 1
  38.     End If
  39.  
  40.  
  41.  

Finally! Share:
https://v6p9d9t4.ssl.hwcdn.net/html/5279712/index.html?qbcode=RDb25zdAEAbw2sLxwD1gG0AYd0An6E3N7ogzu3uTW0tzP4BDyUAFDgN5bWF42wKqdBIjS26AoLn3GSW50ZWdlcsgGmoBZgA1T9wHO3EFzcYu7ugqI3urE2MusB4XcA8tpAYzqAZJjwxgL6B1Vuc2lnbmVk7Q0xvbmfMCxsdVOKpsbkysrdnkHTmV3SW1hZ2W4AoIrWrCAZzAGT4BTumWtwAYo+bZAGqeBRG9X54SM3uXE4cNwFUb+vaAL99f//6rjC7zWPKz0ACEw7vIBUjc0d8aABjMPbaqVCfkYAB8NNyykbQCtsRocAHXrpidO1//IXX0iAWxgSS3OhGOML/+xdFopuVGGMYJX/8WCks0MEAeRow+BDVGhlbk//8xsincJSR0IaWsQhuLcvT/99FRWxzZUlmlv+AcN9p//79ZVtt8evBNLfMNQJotz//bWW2W0A3XjaT//89XatB0kITRPLZb8Sfl/+IhorY5spf/+xrvQzBQJQFBFxNtFxt0A//1YJFbmSyz//Kw0xpbmWg8XNGmEubQp5a4am6Mrgg6ZGOZbsjwKEjF/uENOZXh0LxxL3o4IiMrYwvNsvJgkIht7Y3uUUkvbVebdZCADIRHPPxkYFTG9jYXRlqLKifr69EUHJpbnSZTzcVdGkCc/Fre+gD6ic51jP/fy2B+P6uj4DTG9vcERg==

BTW _delay might be working for this.

 
Connett Circles.PNG




« Last Edit: February 19, 2022, 02:55:23 pm by bplus »

Offline dbox

  • Newbie
  • Posts: 80
    • View Profile
Re: QBJS - QBasic for the Web
« Reply #38 on: February 19, 2022, 01:00:33 pm »
Nice @bplus!  Looks great.  I’ll add this and @DANILIN’s to the sample apps later!

Offline dbox

  • Newbie
  • Posts: 80
    • View Profile
Re: QBJS - QBasic for the Web
« Reply #39 on: February 19, 2022, 01:04:57 pm »
Also, I’ll add single line if/then/else support to the todo list.

And yes it looks like the issue is when _Delay is called from a Sub instead of from the main program.  I’ll fix that too.

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: QBJS - QBasic for the Web
« Reply #40 on: February 19, 2022, 01:28:37 pm »
Here finally got this working, without _Display in QB64 this blinks to great annoyance! but in QB64 it's just a little slow but not as slow as other Basic's I've run it in so JS is fast Interpreter.

share:
https://v6p9d9t4.ssl.hwcdn.net/html/5279712/index.html?qbcode=VPcHRpb24BAAvx0V4cGxpY2l0ABTiKjS6NjKIBFx1BhcnRpY2xlMOjN7q3OjC0t25RENvbnN0EC3KB4B7cAZ6AYYujgao8uDKwO4MLk6NLG2MpXxAeMAUFz7iqbS3M7Yyn/sA8rVcCoLI8KJ+EgWR5Q74cgOSHfDgBjahmOqtzm0s7cysjYNMb25nlYSK3MjhNAkRpbWQqm0MLkysj+A4YAFGq8ApU2S0VTY3JlZW5/9HTmV3SW1hZ2W3QAbc5EAWIfeyrBKAZU+xvMb6A0/20FscO2BIze5Nl0ocwVRvRaHAJuZXdy3GGnMrw6bmBRG+BbCQ2xzgZAUlmc7GAeL3+GqNDK3QAxOKxeAK1UAx/+BtL+BwqlT7PXQA4NNda0AXZipRi6loMtapVD4B1nhNyvnCPWGkWekst4bYzXAGn9/s55s8/v93ksr22K+ZdAKCdsVlyRLD8BT3JS2az6JMA+Rcgiu0sjo0PfgAH4bwA9V7ADgpXNZ3HHRcYqQytLO0Oj/hILcyJW3WXVqKuLAAJ39aX5olgC2cKAbygBq+YBUlf2KxUABPPsX1rkU9TlNaAIT5QBNCobS5MbYytW57WvkFfnt657gs99zU5xs99zc6sKRYQSgiY0trS6MKEL/waY3t7hd4cJTdWJWt+3YX57evS1DP0AAXp6qPsEpNzIlL+xTDYpYZ77mtzBVEq7+L8pWwx33M/1W/DRfrVZyKDG/b12XvqxOgxz29RLNdPt/aDG/b1EOln8CUkdCtrrlyUkl3L7L3xr7XOayjtCKxhxvStXhRYnP/qfZzszX

Particle Fountain:
Code: QB64: [Select]
  1. _Title "Particle Fountain"
  2. Const nP = 30000
  3. Type particle
  4.     x As Single
  5.     y As Single
  6.     dx As Single
  7.     dy As Single
  8.     r As Single
  9.     c As _Unsigned Long
  10. Dim Shared p(nP) As particle
  11. Screen _NewImage(600, 600, 32)
  12. Dim As Long i, lp
  13. For i = 0 To nP
  14.     new i
  15.     Cls
  16.     If lp < nP Then
  17.         lp = lp + 100
  18.     End If
  19.     For i = 0 To lp
  20.         p(i).dy = p(i).dy + .1
  21.         p(i).x = p(i).x + p(i).dx
  22.         p(i).y = p(i).y + p(i).dy
  23.         If p(i).x < 0 Or p(i).x > _Width Then
  24.             new i
  25.         End If
  26.         If p(i).y > _Height And p(i).dy > 0 Then
  27.             p(i).dy = -.75 * p(i).dy
  28.             p(i).y = _Height - 5
  29.         End If
  30.         Circle (p(i).x, p(i).y), p(i).r, p(i).c
  31.     Next
  32.     _Limit 30
  33.  
  34. Sub new (i)
  35.     p(i).x = _Width / 2 + Rnd * 20 - 10
  36.     p(i).y = _Height + Rnd * 5
  37.     p(i).dx = Rnd * 1 - .5
  38.     p(i).dy = -10
  39.     p(i).r = Rnd * 3
  40.     p(i).c = _RGB32(100 * Rnd + 155, 100 * Rnd + 155, 200 + Rnd * 55)
  41.  
  42.  
  43.  

Oh hey! It worked with Option _Explicit, I forgot I had that at top, great!

A screen shot that took awhile to setup, so I had lunch while it ran:
 
Particle Fountain.PNG
« Last Edit: February 19, 2022, 02:01:07 pm by bplus »

Offline dbox

  • Newbie
  • Posts: 80
    • View Profile
Re: QBJS - QBasic for the Web
« Reply #41 on: February 19, 2022, 01:51:51 pm »
That’s a lot of circles!  Very cool.

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: QBJS - QBasic for the Web
« Reply #42 on: February 19, 2022, 02:53:04 pm »
@dbox _Keydown and _Keyhit have notesthat say see GXKeyDown but links to HomePage with no further info.
I assume these are constants, are they similar to QB64's?

Offline dbox

  • Newbie
  • Posts: 80
    • View Profile
Re: QBJS - QBasic for the Web
« Reply #43 on: February 19, 2022, 03:34:09 pm »
Hey @bplus, looks like when I moved that page from the GX project I broke the link to that page.   I ported most of the GX game engine code to JS first, so the input handling is a bit more fleshed out there.  I plan to fully implement _KeyDown and _KeyHit but I thought I would reference the GX-specific methods since they were already available.

I fixed the links in the supported keywords page.  Here is what it is pointing to now:
https://github.com/boxgaming/gx/wiki/GXKeyDown

Also, links to your examples are up on the qbjs main page.

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: QBJS - QBasic for the Web
« Reply #44 on: February 19, 2022, 04:49:25 pm »
Hi @dbox

Here's one I can't figure out what's not working with keys. I found I had to get rid of $ for string variables and DIM as String just to get board to show.
Code: QB64: [Select]
  1. _Title "15 Squares Puzzle" 'b+ mod for QBJS 2022-02-19
  2. Dim Shared As Integer board(4, 4)
  3. Dim Shared As Integer r0, c0, d
  4. Dim As Integer r, c, i, solved
  5. For r = 1 To 4
  6.     For c = 1 To 4
  7.         board(c, r) = c + (r - 1) * 4
  8.     Next
  9. board(4, 4) = 0
  10. c0 = 4
  11. r0 = 4
  12. For i = 0 To 50 * 4 * 4
  13.     d = Val(Mid$("0358", Int(Rnd * 4) + 1, 1))
  14.     handle
  15.     Locate 1, 1
  16.     b = ""
  17.     solved = 1
  18.     For r = 1 To 4
  19.         For c = 1 To 4
  20.             If board(c, r) Then
  21.                 If board(c, r) <> c + (r - 1) * 4 Then
  22.                     solved = 0
  23.                 End If
  24.                 b = b + Right$("   " + Str$(board(c, r)), 3) + " "
  25.             Else
  26.                 b = b + "    "
  27.             End If
  28.         Next
  29.         Print b
  30.         b = ""
  31.     Next
  32.     Print
  33.     If solved Then
  34.         Locate 4 + 2, 2
  35.         Print "Solved!"
  36.         _Delay 5
  37.         'End
  38.     End If
  39.     k = InKey$
  40.     If Len(k) = 2 Then
  41.         d = (Asc(Right$(k, 1)) - 72)
  42.         handle
  43.     End If
  44.     _Limit 30
  45.  
  46. Sub handle
  47.     Select Case d
  48.         Case 3
  49.             If c0 < 4 Then
  50.                 board(c0, r0) = board(c0 + 1, r0)
  51.                 board(c0 + 1, r0) = 0
  52.                 c0 = c0 + 1
  53.             End If
  54.         Case 5
  55.             If c0 > 1 Then
  56.                 board(c0, r0) = board(c0 - 1, r0)
  57.                 board(c0 - 1, r0) = 0
  58.                 c0 = c0 - 1
  59.             End If
  60.         Case 0
  61.             If r0 < 4 Then
  62.                 board(c0, r0) = board(c0, r0 + 1)
  63.                 board(c0, r0 + 1) = 0
  64.                 r0 = r0 + 1
  65.             End If
  66.         Case 8
  67.             If r0 > 1 Then
  68.                 board(c0, r0) = board(c0, r0 - 1)
  69.                 board(c0, r0 - 1) = 0
  70.                 r0 = r0 - 1
  71.             End If
  72.     End Select
  73.  
  74.