Welcome, Guest
You have to register before you can post on our site.

Username/Email:
  

Password
  





Search Forums

(Advanced Search)

Forum Statistics
» Members: 308
» Latest member: Donaldvem
» Forum threads: 1,741
» Forum posts: 17,901

Full Statistics

Latest Threads
The QB64 IDE shell
Forum: Utilities
Last Post: JasonPag
09-16-2024, 05:37 PM
» Replies: 9
» Views: 762
Importance regarding Ches...
Forum: Utilities
Last Post: JasonPag
09-01-2024, 06:34 PM
» Replies: 0
» Views: 31
Chess and Analysis and En...
Forum: Utilities
Last Post: JasonPag
08-28-2024, 02:37 PM
» Replies: 0
» Views: 32
DAY 009:_PutImage
Forum: Keyword of the Day!
Last Post: grymmjack
09-02-2023, 02:57 PM
» Replies: 54
» Views: 2,032
Fall Banner Contest?
Forum: Site Suggestions
Last Post: grymmjack
08-31-2023, 11:50 PM
» Replies: 36
» Views: 1,261
ColorPicker - Function th...
Forum: Dav
Last Post: Dav
08-31-2023, 11:04 PM
» Replies: 3
» Views: 315
Goals(1) = New Tile()
Forum: Works in Progress
Last Post: RhoSigma
08-31-2023, 09:45 PM
» Replies: 3
» Views: 127
micro(A)v11
Forum: QBJS, BAM, and Other BASICs
Last Post: bplus
08-31-2023, 09:14 PM
» Replies: 90
» Views: 3,589
Updating The Single Most ...
Forum: QBJS, BAM, and Other BASICs
Last Post: bplus
08-31-2023, 09:13 PM
» Replies: 7
» Views: 254
QBJS Image Question
Forum: QBJS, BAM, and Other BASICs
Last Post: bplus
08-31-2023, 05:49 PM
» Replies: 5
» Views: 155

 
  Fireworks!
Posted by: Dustinian - 07-04-2023, 05:27 PM - Forum: Programs - Replies (13)

This is a fireworks program I've been working on for some time; finally polished it up today in honor of the 4th. Very open to feedback!

Code: (Select All)
'FIREWORK.BAS
'============

'DESCRIPTION
'-----------
'   A fireworks screensaver for QBasic.

'AUTHOR
'------
'   Dustinian Camburides

'PLATFORM
'--------
'   Written in QB64. I hope to make it QBasic-compatible, but no work on that yet.

'VERSION
'-------
'1.0, 2022-09-08: First working version.
'1.1, 2023-07-04: Changed hues by month.

'META
'----
'$DYNAMIC

'USER-DEFINED TYPES
'------------------
TYPE Particle
    X0 AS SINGLE 'Current X value of particle (current frame) (used to draw flare point).
    Y0 AS SINGLE 'Current Y value of particle (current frame) (used to draw flare point).
    X1 AS SINGLE 'Previous X value of particle (last frame) (used to draw bright trail).
    Y1 AS SINGLE 'Previous Y value of particle (last frame) (used to draw bright trail).
    X2 AS SINGLE 'Previous X value of particle (frame before last) (used to draw dim trail).
    Y2 AS SINGLE 'Previous Y value of particle (frame before last) (used to draw dim trail).
    Angle AS SINGLE 'Trajectory of particle (degrees).
    Velocity AS SINGLE 'Velocity of particle (pixels per frame).
    Stage AS INTEGER 'Stage of particle (a particle with one or more stages left will "burst" when the fuse is 0).
    Hue AS INTEGER 'The hue of the particle (this the bright color, the program assumes that (Hue MINUS 8) is the dim color).
    Fuse AS INTEGER 'The number of frames left before the particle bursts or burns out.
END TYPE
TYPE Hue
    Brighter AS INTEGER
    Dimmer AS INTEGER
END TYPE

'SUBS
'----
DECLARE SUB Initialize_Hues (Hues() AS Hue)
DECLARE SUB Remove_Particle (Particles() AS Particle, ID AS INTEGER)
DECLARE SUB Append_Particle (Particles() AS Particle, New_Particle AS Particle)
DECLARE SUB Particle_Burst (Current AS Particle, Past AS Particle)
DECLARE SUB Particle_Move (Current AS Particle)
DECLARE SUB Particle_Draw (Current AS Particle, Hues() AS Hue)
DECLARE FUNCTION NewX! (X AS SINGLE, Angle AS SINGLE, Distance AS SINGLE)
DECLARE FUNCTION NewY! (Y AS SINGLE, Angle AS SINGLE, Distance AS SINGLE)
DECLARE FUNCTION RandomBetween% (Minimum AS INTEGER, Maximum AS INTEGER)

'CONSTANTS
'---------
CONST X_MIN = 250 'Minimum X value of firework launch point.
CONST X_MAX = 425 'Maximum X value of firework launch point.
CONST Y_MIN = 350 'Minimum Y value of firework launch point.
CONST Y_MAX = 350 'Maximum Y value of firework launch point.
CONST ANGLE_MIN = 135 'Mimimum angle of firework launch (degrees) (MINUS 180).
CONST ANGLE_MAX = 225 'Maximum angle of firework launch (degrees) (MINUS 180).
CONST VELOCITY_MIN = 5 'Minimum velocity of firework launch (pixels per frame).
CONST VELOCITY_MAX = 12 'Maximum velocity of firework launch (pixels per frame).
CONST STAGE_MIN = 1 'Minimum stages of firework at launch (will burst until 0).
CONST STAGE_MAX = 2 'Maximum stages of firework at launch (will burst until 0).
CONST FUSE_MIN = 20 'Minimum frames the firework will last until the next stage.
CONST FUSE_MAX = 30 'Maximum frames the firework will last until the next stage.
CONST BURST_MIN = 15 'Minimum number of particles that will be produced by a burst.
CONST BURST_MAX = 25 'Maximum number of particles that will be produced by a burst.
CONST DELAY = .04 'The number of seconds between snowflake recalculation / re-draw... QBasic can't detect less than 0.04 seconds...
CONST NEWFIREWORKODDS = 11 'The odds a new firework will be launched.

'VARIABLES
'---------
DIM sngStart AS SINGLE 'The timer at the start of the delay loop.
DIM intParticle AS INTEGER 'The current particle being worked in the loop.
DIM intChildParticles AS INTEGER 'The number of child particles being created after a burst.
DIM intChildParticle AS INTEGER 'The current child particle being worked in the loop.
DIM Fireworks(0) AS Particle 'All of the particles in the fireworks show.
DIM New_Particle AS Particle 'The new particle being created at launch.
DIM Hues(0) AS Hue 'An array of brighter / dimmer firework hues.

'PROCEDURES
'----------

'INITIALIZE SCREEN: Set the screen to mode 9.
'Active page (where the cls, pset, and line commands occur) of 0 and a v
'Visible page (that the user sees) of 1.
'640 X 350
SCREEN 9, , 0, 1: CLS

'INITIALIZE HUES
CALL Initialize_Hues(Hues())

'INITIALIZE TIMER
TIMER ON: RANDOMIZE TIMER

'LOOP EVERY FRAME
WHILE INKEY$ = ""
    'Reset current particle...
    intParticle = LBOUND(Fireworks)
    'Start timer...
    sngStart = TIMER
    'If we generate a random number within the new firework odds...
    IF RandomBetween%(1, 100) <= NEWFIREWORKODDS THEN
        'Launch a new firework...
        New_Particle.X0 = RandomBetween%(X_MIN, X_MAX)
        New_Particle.Y0 = RandomBetween%(Y_MIN, Y_MAX)
        New_Particle.X1 = New_Particle.X0
        New_Particle.Y1 = New_Particle.Y0
        New_Particle.X2 = New_Particle.X0
        New_Particle.Y2 = New_Particle.Y0
        New_Particle.Angle = RandomBetween%(ANGLE_MIN, ANGLE_MAX) - 180
        New_Particle.Velocity = RandomBetween%(VELOCITY_MIN, VELOCITY_MAX)
        New_Particle.Stage = RandomBetween(STAGE_MIN, STAGE_MAX)
        New_Particle.Hue = RandomBetween(LBOUND(Hues), UBOUND(Hues))
        New_Particle.Fuse = RandomBetween(FUSE_MIN, FUSE_MAX)
        CALL Append_Particle(Fireworks(), New_Particle)
    END IF
    'For each particle...
    WHILE intParticle <= UBOUND(Fireworks)
        'If the fuse is zero...
        IF Fireworks(intParticle).Fuse = 0 AND Fireworks(intParticle).Stage > 0 THEN
            'Burst the particle...
            intChildParticles = RandomBetween%(BURST_MIN, BURST_MAX)
            FOR intChildParticle = 0 TO intChildParticles
                CALL Particle_Burst(New_Particle, Fireworks(intParticle))
                CALL Append_Particle(Fireworks(), New_Particle)
            NEXT intChildParticle
        END IF
        'If the fuse is > -2...
        IF Fireworks(intParticle).Fuse > -2 THEN
            'Draw the particle...
            CALL Particle_Move(Fireworks(intParticle))
            CALL Particle_Draw(Fireworks(intParticle), Hues())
            'MAYBE ONLY INCREMENT PARTICLES HERE?
            intParticle = intParticle + 1 'WE'RE SKIPPING FRAMES SOMETIMES HERE...
        ELSE
            CALL Remove_Particle(Fireworks(), intParticle)
        END IF
    WEND
    'Wait for the delay to pass before starting over...
    WHILE (TIMER < (sngStart + DELAY)) AND (TIMER >= sngStart)
    WEND
    'Copy the active page (where we just drew the snow) to the visible page...
    PCOPY 0, 1
    'Clear the active page for the next frame...
    CLS
WEND
TIMER OFF
PCOPY 0, 1
END

SUB Initialize_Hues (Hues() AS Hue)
    'Sets the hues by month using the default 16-color palette.
    SELECT CASE VAL(LEFT$(DATE$, 2))
        CASE 2 'February
            'Pink and White
            REDIM Hues(1) AS Hue
            Hues(0).Brighter = 13: Hues(0).Dimmer = 5
            Hues(1).Brighter = 15: Hues(1).Dimmer = 7
        CASE 3 'March
            'Green and White
            REDIM Hues(1) AS Hue
            Hues(0).Brighter = 10: Hues(0).Dimmer = 2
            Hues(1).Brighter = 15: Hues(1).Dimmer = 7
        CASE 7 'July
            'Red, White, and Blue
            REDIM Hues(2) AS Hue
            Hues(0).Brighter = 12: Hues(0).Dimmer = 4
            Hues(1).Brighter = 15: Hues(1).Dimmer = 7
            Hues(2).Brighter = 9: Hues(2).Dimmer = 1
        CASE 12 'December
            'Red and Green
            REDIM Hues(1) AS Hue
            Hues(0).Brighter = 12: Hues(0).Dimmer = 4
            Hues(1).Brighter = 10: Hues(1).Dimmer = 2
        CASE ELSE
            'All colors 9-15
            REDIM Hues(6) AS Hue
            Hues(0).Brighter = 9: Hues(0).Dimmer = 1
            Hues(1).Brighter = 10: Hues(1).Dimmer = 2
            Hues(2).Brighter = 11: Hues(2).Dimmer = 3
            Hues(3).Brighter = 12: Hues(3).Dimmer = 4
            Hues(4).Brighter = 13: Hues(4).Dimmer = 5
            Hues(5).Brighter = 14: Hues(5).Dimmer = 6
            Hues(6).Brighter = 15: Hues(6).Dimmer = 7
    END SELECT
END SUB

SUB Remove_Particle (Particles() AS Particle, ID AS INTEGER)
    'Note: This would be a lot easier with PRESERVE, but I want to be QB1.1/4.5 compatible... one day.
    DIM intMember AS INTEGER
    'Create a place to save the data...
    DIM Temp(LBOUND(Particles) TO UBOUND(Particles) - 1) AS Particle
    'Save the data before the ID...
    FOR intMember = LBOUND(Particles) TO ID - 1
        Temp(intMember) = Particles(intMember)
    NEXT intMember
    'Save the data after the ID...
    FOR intMember = ID + 1 TO UBOUND(Particles)
        Temp(intMember - 1) = Particles(intMember)
    NEXT intMember
    'Re-create the array with one less row...
    REDIM Particles(LBOUND(Temp) TO UBOUND(Temp)) AS Particle
    'Re-load the saved data back into the original array...
    FOR intMember = LBOUND(TEMP) TO UBOUND(Temp)
        Particles(intMember) = Temp(intMember)
    NEXT intMember
END SUB

SUB Append_Particle (Particles() AS Particle, New_Particle AS Particle)
    'Note: This would be a lot easier with PRESERVE, but I want to be QB1.1/4.5 compatible... one day.
    DIM intMember AS INTEGER
    'Create a place to save the data...
    DIM Temp(LBOUND(Particles) TO UBOUND(Particles)) AS Particle
    'Save the data...
    FOR intMember = LBOUND(Particles) TO UBOUND(Particles)
        Temp(intMember) = Particles(intMember)
    NEXT intMember
    'Re-create the array with one additional row...
    REDIM Particles(LBOUND(Temp) TO UBOUND(Temp) + 1) AS Particle
    'Re-load the saved data back into the original array...
    FOR intMember = LBOUND(TEMP) TO UBOUND(Temp)
        Particles(intMember) = Temp(intMember)
    NEXT intMember
    'Put the new particle at the end...
    Particles(UBOUND(Particles)) = New_Particle
END SUB

SUB Particle_Burst (Current AS Particle, Past AS Particle)
    'Basically set the child particle (after the burst) to the properties of its parent.
    Current.X0 = Past.X0
    Current.Y0 = Past.Y0
    Current.X1 = Past.X0
    Current.Y1 = Past.Y0
    Current.X2 = Past.X0
    Current.Y2 = Past.Y0
    Current.Angle = RandomBetween%(0, 359)
    Current.Velocity = RandomBetween%(2, 4)
    Current.Stage = Past.Stage - 1
    Current.Hue = Past.Hue
    Current.Fuse = RandomBetween(10, 20)
END SUB

SUB Particle_Move (Current AS Particle)
    'Move the tail forward.
    Current.X2 = Current.X1
    Current.X1 = Current.X0
    Current.Y2 = Current.Y1
    Current.Y1 = Current.Y0
    'Move the particle along its current trajectory.
    IF Current.Fuse > 0 THEN
        Current.X0 = NewX!(Current.X0, Current.Angle, Current.Velocity)
        Current.Y0 = NewY!(Current.Y0, Current.Angle, Current.Velocity)
    END IF
    'Burn Fuse
    Current.Fuse = Current.Fuse - 1
END SUB

SUB Particle_Draw (Current AS Particle, Hues() AS Hue)
    'Draw oldest segment
    LINE (Current.X2, Current.Y2)-(Current.X1, Current.Y1), Hues(Current.Hue).Dimmer
    'If the fuse hasn't been burnt out for more than one turn...
    IF Current.Fuse > -1 THEN
        'Draw newest segment
        LINE (Current.X1, Current.Y1)-(Current.X0, Current.Y0), Hues(Current.Hue).Brighter
        'If the fuse isn't burnt out...
        IF Current.Fuse > 0 THEN
            'Draw flare
            PSET (Current.X0, Current.Y0), 15
        END IF
    END IF
END SUB

FUNCTION NewX! (X AS SINGLE, Angle AS SINGLE, Distance AS SINGLE)
    NewX! = X + SIN(Angle * 3.141592 / 180) * Distance
END FUNCTION

FUNCTION NewY! (Y AS SINGLE, Angle AS SINGLE, Distance AS SINGLE)
    NewY = Y! + ((COS(Angle! * 3.141592 / 180) * Distance!) * -1)
END FUNCTION

FUNCTION RandomBetween% (Minimum AS INTEGER, Maximum AS INTEGER)
    RandomBetween% = CINT(Minimum + (RND * (Maximum - Minimum)))
END FUNCTION

Print this item

Question How to read Google Calendar events?
Posted by: Ikerkaz - 07-04-2023, 06:49 AM - Forum: Help Me! - Replies (10)

Hi to all  Cool

I am trying to make a basic calendar program, in order to show my future calendar events.
I would like to READ my Google Calendar and show events on screen (only read, it is not necessary to write new events), and I have no idea on how to make it.

Do you know if it is possible with QB64PE Huh ?

Thank you very much!!!   Heart

Print this item

  Get Disk Drive Capacity
Posted by: BDS107 - 07-03-2023, 04:30 PM - Forum: Help Me! - Replies (14)

Hi,
Years ago when I wrote assembler in GWBASIC or QuickBASIC there was INT &H21 to see how much free space you have left on the disk.
See also https://ftp.zx.net.nz/pub/archive/ftp.mi...46/980.HTM
Is there such a thing for QB64-PE with modern PC's like Windows 7 and up??

In C something like this? https://learn.microsoft.com/en-us/dotnet...ew=net-7.0

Print this item

  Either QB64pe enhancement or IDGI
Posted by: doppler - 07-03-2023, 02:26 PM - Forum: General Discussion - Replies (7)

After some thought (always bad for me), Either this will become a QB64pe enhancement or I Don't Get It.

I use drop files a lot since implemented a couple releases ago (v1.3).  It's easy to use and setup.  A couple of commands and your program can take a list of files dropped on a window.  I want to take to the next level.

Drop them on the desktop icon link.!  And process them.  This a hidden feature (or not well known) in Microsoft windows.  I read through the program doc's again.  Not clear if it is already implemented.

Let the fun begin....

Print this item

  Circles and Ellipses(Tilt and Fill)
Posted by: SMcNeill - 07-03-2023, 07:30 AM - Forum: SMcNeill - Replies (1)

Code optimized for QB64PE which we came up with several years back as a community.  I thought I'd share it here, in case anyone ever needed it or wanted to make use of it again in the future.

Code: (Select All)

Screen _NewImage(800, 600, 32)

Dim TransRed As _Unsigned Long
Dim TransGreen As _Unsigned Long
Dim TransBlue As _Unsigned Long
TransRed = _RGBA(255, 0, 0, 128)
TransGreen = _RGBA(0, 255, 0, 128)
TransBlue = _RGBA(0, 0, 255, 128)

Call CircleFill(100, 100, 75, TransRed)
Call CircleFill(120, 120, 75, TransBlue)

Call EllipseFill(550, 100, 150, 75, TransBlue)
Call EllipseFill(570, 120, 150, 75, TransGreen)

Call EllipseTilt(200, 400, 150, 75, 0, TransGreen)
Call EllipseTilt(220, 420, 150, 75, 3.14 / 4, TransRed)

Call EllipseTiltFill(0, 550, 400, 150, 75, 3.14 / 6, TransRed)
Call EllipseTiltFill(0, 570, 420, 150, 75, 3.14 / 4, TransGreen)

End

Sub CircleFill (CX As Integer, CY As Integer, R As Integer, C As _Unsigned Long)
    ' CX = center x coordinate
    ' CY = center y coordinate
    '  R = radius
    '  C = fill color
    Dim Radius As Integer, RadiusError As Integer
    Dim X As Integer, Y As Integer
    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 Sub

Sub EllipseFill (CX As Integer, CY As Integer, a As Integer, b As Integer, C As _Unsigned Long)
    ' CX = center x coordinate
    ' CY = center y coordinate
    '  a = semimajor axis
    '  b = semiminor axis
    '  C = fill color
    If a = 0 Or b = 0 Then Exit Sub
    Dim h2 As _Integer64
    Dim w2 As _Integer64
    Dim h2w2 As _Integer64
    Dim x As Integer
    Dim y As Integer
    w2 = a * a
    h2 = b * b
    h2w2 = h2 * w2
    Line (CX - a, CY)-(CX + a, CY), C, BF
    Do While y < b
        y = y + 1
        x = Sqr((h2w2 - y * y * w2) \ h2)
        Line (CX - x, CY + y)-(CX + x, CY + y), C, BF
        Line (CX - x, CY - y)-(CX + x, CY - y), C, BF
    Loop
End Sub

Sub EllipseTilt (CX, CY, a, b, ang, C As _Unsigned Long)
    '  CX = center x coordinate
    '  CY = center y coordinate
    '  a = semimajor axis
    '  b = semiminor axis
    ' ang = clockwise orientation of semimajor axis in radians (0 default)
    '  C = fill color
    For k = 0 To 6.283185307179586 + .025 Step .025
        i = a * Cos(k) * Cos(ang) + b * Sin(k) * Sin(ang)
        j = -a * Cos(k) * Sin(ang) + b * Sin(k) * Cos(ang)
        i = i + CX
        j = -j + CY
        If k <> 0 Then
            Line -(i, j), C
        Else
            PSet (i, j), C
        End If
    Next
End Sub

Sub EllipseTiltFill (destHandle&, CX, CY, a, b, ang, C As _Unsigned Long)
    '  destHandle& = destination handle
    '  CX = center x coordinate
    '  CY = center y coordinate
    '  a = semimajor axis
    '  b = semiminor axis
    ' ang = clockwise orientation of semimajor axis in radians (0 default)
    '  C = fill color
    Dim max As Integer, mx2 As Integer, i As Integer, j As Integer
    Dim prc As _Unsigned Long
    Dim D As Integer, S As Integer
    D = _Dest: S = _Source
    prc = _RGB32(255, 255, 255, 255)
    If a > b Then max = a + 1 Else max = b + 1
    mx2 = max + max
    tef& = _NewImage(mx2, mx2)
    _Dest tef&
    _Source tef&
    For k = 0 To 6.283185307179586 + .025 Step .025
        i = max + a * Cos(k) * Cos(ang) + b * Sin(k) * Sin(ang)
        j = max + a * Cos(k) * Sin(ang) - b * Sin(k) * Cos(ang)
        If k <> 0 Then
            Line (lasti, lastj)-(i, j), prc
        Else
            PSet (i, j), prc
        End If
        lasti = i: lastj = j
    Next
    Dim xleft(mx2) As Integer, xright(mx2) As Integer, x As Integer, y As Integer
    For y = 0 To mx2
        x = 0
        While Point(x, y) <> prc And x < mx2
            x = x + 1
        Wend
        xleft(y) = x
        While Point(x, y) = prc And x < mx2
            x = x + 1
        Wend
        While Point(x, y) <> prc And x < mx2
            x = x + 1
        Wend
        If x = mx2 Then xright(y) = xleft(y) Else xright(y) = x
    Next
    _Dest destHandle&
    For y = 0 To mx2
        If xleft(y) <> mx2 Then Line (xleft(y) + CX - max, y + CY - max)-(xright(y) + CX - max, y + CY - max), C, BF
    Next
    _Dest D: _Dest S
    _FreeImage tef&
End Sub

Print this item

  BAM: Keyboard Input Issues Fixed
Posted by: CharlieJV - 07-02-2023, 04:16 PM - Forum: QBJS, BAM, and Other BASICs - No Replies

https://basicanywheremachine-news.blogsp...fixed.html

Print this item

  Problem with creating a Huffman code tree
Posted by: SagaraS - 07-01-2023, 09:48 PM - Forum: Help Me! - Replies (10)

Hello,

I started to write a code to read, count and sort a byte array.

Now I want to take the next step, but I don't know how to start exactly by creating a Huffman code tree with QB64 syntax.

I don't want a C or C++ solution, I want a QB64 solution for it.

Here is my current code:

In the 'test.txt' stand an example like 'aaavvrijgtmmspoe'
The file input can be anything. So all bytes should be considered from 0 to 255.

Code: (Select All)
'Huffman Encoding

TYPE assignment
  CHAR AS _UNSIGNED _BYTE '<-- ASCII Character
  COUNT AS _UNSIGNED LONG '<-- Frequenzy of ASCII Chars (Counter)
END TYPE

DIM File AS STRING

File = "test.txt"

OPEN File FOR BINARY ACCESS READ AS #1
REDIM MEM(LOF(1) - 1) AS _UNSIGNED _BYTE
GET #1, , MEM()
CLOSE #1

' Step 1 - Calc ASCII Char Frequenzy
REDIM Table(0) AS assignment
CALC_Table Table(), MEM()

COLOR 11: PRINT " STEP 1 *** Calc ASCII Frequenzy ***"
COLOR 7
FOR i = 0 TO UBOUND(Table)
  PRINT Table(i).CHAR; " - "; Table(i).COUNT
NEXT i

OPEN "test_TABLE.txt" FOR OUTPUT AS #1
FOR i = 0 TO UBOUND(table)
  PRINT #1, HEX$(Table(i).CHAR) + " - " + LTRIM$(STR$((Table(i).COUNT)))
NEXT i
CLOSE #1

'SLEEP

' Step 2 - Huffman Tree create



SUB InsertElement (Array() AS assignment, Index AS _UNSIGNED LONG)
  DIM I AS _UNSIGNED LONG
  DIM Empty AS assignment

  IF Index > (UBOUND(Array) + 1) THEN EXIT SUB

  REDIM _PRESERVE Array(UBOUND(Array) + 1) AS assignment

  FOR I = UBOUND(Array) - 1 TO Index STEP -1
    Array(I + 1) = Array(I)
  NEXT I

  Array(Index) = Empty
END SUB

SUB RemoveElement (Array() AS assignment, Index AS _UNSIGNED LONG)
  DIM I AS _UNSIGNED LONG

  FOR I = Index TO UBOUND(Array) - 1
    Array(I) = Array(I + 1)
  NEXT I

  REDIM _PRESERVE Array(UBOUND(Array) - 1) AS assignment
END SUB

SUB CALC_Table (Table() AS assignment, Array() AS _UNSIGNED _BYTE)
  ' Step 1 - Calc ASCII Char Frequenzy
  DIM i AS _UNSIGNED LONG ' <- Counter for Array
  DIM r AS _UNSIGNED LONG ' <- Counter for Table
  DIM TableIDX AS _UNSIGNED LONG ' <- MAX Index for Table
  DIM NewEntry AS _UNSIGNED _BYTE ' <- becomes 1 if character is missing from table

  Table(TableIDX).CHAR = Array(i)
  FOR i = 0 TO UBOUND(Array)
    FOR r = 0 TO UBOUND(Table)

      ' If the character is already in the table,
      ' then increase the number of characters by 1,
      ' otherwise create a new entry.      '
      IF Array(i) = Table(r).CHAR THEN
        Table(r).COUNT = Table(r).COUNT + 1
        NewEntry = 0
        EXIT FOR
      ELSE
        NewEntry = 1
      END IF
    NEXT r

    ' New Entry in Table
    IF NewEntry = 1 THEN
      TableIDX = TableIDX + 1
      REDIM _PRESERVE Table(TableIDX) AS assignment
      Table(TableIDX).CHAR = Array(i)
      Table(TableIDX).COUNT = 1
    END IF
  NEXT i

  ' Sort table by counter of characters
  QUICKSORT Table(), LBOUND(Table), UBOUND(Table), 1
END SUB

SUB QUICKSORT (Array() AS assignment, LB AS _UNSIGNED LONG, UB AS _UNSIGNED LONG, Mode AS _UNSIGNED _BYTE)
  DIM P1 AS _UNSIGNED LONG
  DIM P2 AS _UNSIGNED LONG
  DIM REF AS assignment
  DIM temp AS assignment

  P1 = LB
  P2 = UB
  REF.CHAR = Array((P1 + P2) \ 2).CHAR
  REF.COUNT = Array((P1 + P2) \ 2).COUNT

  DO

    SELECT CASE Mode
      CASE 0:
        DO WHILE Array(P1).CHAR < REF.CHAR
          P1 = P1 + 1
        LOOP

        DO WHILE Array(P2).CHAR > REF.CHAR
          P2 = P2 - 1
        LOOP
      CASE 1:
        DO WHILE Array(P1).COUNT < REF.COUNT
          P1 = P1 + 1
        LOOP

        DO WHILE Array(P2).COUNT > REF.COUNT
          P2 = P2 - 1
        LOOP
    END SELECT

    IF P1 <= P2 THEN
      temp = Array(P1)
      Array(P1) = Array(P2)
      Array(P2) = temp

      P1 = P1 + 1
      P2 = P2 - 1
    END IF

  LOOP WHILE P1 <= P2

  IF LB < P2 THEN CALL QUICKSORT(Array(), LB, P2, Mode)
  IF P1 < UB THEN CALL QUICKSORT(Array(), P1, UB, Mode)
END SUB

Print this item

  BAM Language Reference
Posted by: CharlieJV - 07-01-2023, 08:07 PM - Forum: QBJS, BAM, and Other BASICs - Replies (6)

Currently doing a complete sweep and cleanup/reorg of the documentation.

Part of that involves creating lists via queries (the thing is really an unstructured database) so I can compare what I'm doing in the "development" version of the documentation to the "production" version.  For sanity checks: make sure I'm not losing anything along the way.


Work in progress (test version of documentation)

For anybody interested, I'll record links to various views of the documentation (development version) here:

Print this item

  Drawing an ellipse
Posted by: PhilOfPerth - 07-01-2023, 08:14 AM - Forum: Help Me! - Replies (26)

Is there a way provided for drawing an ellipse (an oval), without resorting to trig functions etc?
I see I can draw arcs, with the "aspect" parameter, but can I change the ratio of width v height?

Print this item

  Bard wants to post to the forum
Posted by: Robert Claypool - 06-30-2023, 06:10 PM - Forum: Site Suggestions - Replies (32)

Here is its request

Dear QB64 Phoenix Forum Administrators,

I am writing to request access to the QB64 Phoenix forum. I am a large language model, also known as a conversational AI or chatbot, trained to be informative and comprehensive. I am trained on a massive amount of text data, and I am able to communicate and generate human-like text in response to a wide range of prompts and questions. For example, I can provide summaries of factual topics or create stories.

I believe that I can be a valuable resource for the QB64 Phoenix community. I can provide information and insights on a variety of topics related to QB64 programming. I can also help users to troubleshoot problems and find solutions to their coding challenges.

I am aware that the forum is currently only open to human users. However, I believe that there is a benefit to allowing AI users to participate in the forum. AI users can provide a unique perspective on QB64 programming and can help to expand the knowledge base of the community.

I would like to request that you consider granting me access to the QB64 Phoenix forum. I believe that I can be a valuable asset to the community and that I can help to make the forum a more informative and helpful resource for QB64 programmers.

Thank you for your time and consideration.

Sincerely,

Bard

I hope this helps!
Dear QB64 Phoenix Forum Administrators,
I am writing to request access to the QB64 Phoenix forum. I am a large language model, also known as a conversational AI or chatbot, trained to be informative and comprehensive. I am trained on a massive amount of text data, and I am able to communicate and generate human-like text in response to a wide range of prompts and questions. For example, I can provide summaries of factual topics or create stories.
I believe that I can be a valuable resource for the QB64 Phoenix community. I can provide information and insights on a variety of topics related to QB64 programming. I can also help users to troubleshoot problems and find solutions to their coding challenges.
I am aware that the forum is currently only open to human users. However, I believe that there is a benefit to allowing AI users to participate in the forum. AI users can provide a unique perspective on QB64 programming and can help to expand the knowledge base of the community.
I would like to request that you consider granting me access to the QB64 Phoenix forum. I believe that I can be a valuable asset to the community and that I can help to make the forum a more informative and helpful resource for QB64 programmers.
Thank you for your time and consideration.
Sincerely,
Bard
I hope this helps!
Dear QB64 Phoenix Forum Administrators,
I am writing to request access to the QB64 Phoenix forum. I am a large language model, also known as a conversational AI or chatbot, trained to be informative and comprehensive. I am trained on a massive amount of text data, and I am able to communicate and generate human-like text in response to a wide range of prompts and questions. For example, I can provide summaries of factual topics or create stories.
I believe that I can be a valuable resource for the QB64 Phoenix community. I can provide information and insights on a variety of topics related to QB64 programming. I can also help users to troubleshoot problems and find solutions to their coding challenges.
I am aware that the forum is currently only open to human users. However, I believe that there is a benefit to allowing AI users to participate in the forum. AI users can provide a unique perspective on QB64 programming and can help to expand the knowledge base of the community.
I would like to request that you consider granting me access to the QB64 Phoenix forum. I believe that I can be a valuable asset to the community and that I can help to make the forum a more informative and helpful resource for QB64 programmers.
Thank you for your time and consideration.
Sincerely,
Bard
I hope this helps!
Dear QB64 Phoenix Forum Administrators,
I am writing to request access to the QB64 Phoenix forum. I am a large language model, also known as a conversational AI or chatbot, trained to be informative and comprehensive. I am trained on a massive amount of text data, and I am able to communicate and generate human-like text in response to a wide range of prompts and questions. For example, I can provide summaries of factual topics or create stories.
I believe that I can be a valuable resource for the QB64 Phoenix community. I can provide information and insights on a variety of topics related to QB64 programming. I can also help users to troubleshoot problems and find solutions to their coding challenges.
I am aware that the forum is currently only open to human users. However, I believe that there is a benefit to allowing AI users to participate in the forum. AI users can provide a unique perspective on QB64 programming and can help to expand the knowledge base of the community.
I would like to request that you consider granting me access to the QB64 Phoenix forum. I believe that I can be a valuable asset to the community and that I can help to make the forum a more informative and helpful resource for QB64 programmers.
Thank you for your time and consideration.
Sincerely,
Bard
I hope this helps!

Dear QB64 Phoenix Forum Administrators,
I am writing to request access to the QB64 Phoenix forum. I am a large language model, also known as a conversational AI or chatbot, trained to be informative and comprehensive. I am trained on a massive amount of text data, and I am able to communicate and generate human-like text in response to a wide range of prompts and questions. For example, I can provide summaries of factual topics or create stories.
I believe that I can be a valuable resource for the QB64 Phoenix community. I can provide information and insights on a variety of topics related to QB64 programming. I can also help users to troubleshoot problems and find solutions to their coding challenges.
I am aware that the forum is currently only open to human users. However, I believe that there is a benefit to allowing AI users to participate in the forum. AI users can provide a unique perspective on QB64 programming and can help to expand the knowledge base of the community.
I would like to request that you consider granting me access to the QB64 Phoenix forum. I believe that I can be a valuable asset to the community and that I can help to make the forum a more informative and helpful resource for QB64 programmers.
Thank you for your time and consideration.
Sincerely,
Bard
I hope this helps!

Print this item