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,034
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

 
  Random Pouring Water
Posted by: SierraKen - 08-27-2022, 10:58 PM - Forum: Programs - Replies (2)

I was playing with water again today and came across this, so I thought I would put it here. It shows random streams of water pouring down. I first had PSET but changed to filled-in CIRCLE with an oblong shape for each drop. One important thing I finally learned is how to make a random number between a certain negative number and a positive number, just make both a positive and a negative and add them together. Took me long enough. LOL

Code: (Select All)
'Pouring Water by SierraKen - Aug. 27, 2022
Screen _NewImage(800, 600, 32)
Dim x(20000), y(20000), xx(20000)
For t = 1 To 20000
    x(t) = (Rnd * 100) + 350
    y(t) = (Rnd * 600)
Next t
Do
    _Limit 25
    a$ = InKey$
    If a$ = Chr$(27) Then End
    For t = 1 To 20000
        tt = tt + 1
        If tt > 100 And tt < 200 Then
            tt = 0
            ttt = ttt + 1
            If ttt > 20 Then ttt = 0
            xx(ttt) = xx(ttt) + (Rnd * 10) + (Rnd * -10)
        End If
        'Feel free to swap the PSET line and the circle loop, without the loop.
        'PSet (x(t) + xx(ttt), y(t)), _RGB32(127, 255, 255)
        For sz = .25 To Rnd * 4 Step .25
            Circle (x(t) + xx(ttt), y(t)), sz, _RGB32(127, 255, 255), , , 2.75
        Next sz
        y(t) = y(t) + .25
        If y(t) > 600 Then
            y(t) = 0
            x(t) = (Rnd * 100) + 350
            tt = 0
            ttt = 0
        End If
    Next t
    _Delay .01
    _Display
    Cls
Loop

Print this item

  Raylib Wrapper Help
Posted by: LeftyG - 08-27-2022, 07:44 PM - Forum: Works in Progress - Replies (21)

Hello all,

I am currently working on a Raylib wrapper. However I can't get it to show a image on the screen. Every time I do, it crashes the program.

Color issue is figured out. Need to figure out how to load and draw image functions aren't working properly.

Full wrapper code: https://github.com/gAndy50/Qb64Wrappers/...aylib42.bi

Wrapper code

Code: (Select All)
TYPE fImage
    xdata AS _OFFSET
    xwidth AS INTEGER
    height AS INTEGER
    mipmaps AS INTEGER
    format AS INTEGER
END TYPE

  FUNCTION LoadTexture& (fName AS STRING)

 SUB DrawTexture (BYVAL fTexture AS _OFFSET, BYVAL x AS INTEGER, BYVAL y AS INTEGER, BYVAL fColor AS _UNSIGNED LONG)
   

Program Code
Code: (Select All)
REM $include: 'raylib42.bi'

LET w = 800
LET h = 600

CALL InitWindow(w, h, "Hello")

DIM SHARED Col AS fColor

'R and G are backwards?
Col.r = 255 'this is blue?
Col.g = 0
Col.b = 0 'this is red? (if value is 255)
Col.a = 255

SetTargetFPS (60)

DIM SHARED tex AS fTexture
tex.id = 0
tex.xwidth = 50
tex.height = 50
tex.mipmaps = 0
tex.format = 0

tex& = LoadTexture("dw2.png")

DO

    BeginDrawing

    CALL ClearBackground(_RGBA32(Col.r, Col.g, Col.b, Col.a))

    CALL DrawFPS(1, 1)

    CALL DrawTexture(tex&, 10, 10, _RGBA32(255, 255, 255, 255))

    'CALL DrawLine(10, 20, 50, 50, _RGBA32(0, 0, 255, 255))

    EndDrawing

LOOP UNTIL WindowShouldClose

Print this item

  SUBS or GOSUB; for library projects, which do you guys prefer?
Posted by: Pete - 08-27-2022, 05:31 PM - Forum: General Discussion - Replies (9)

I just wrapped up a new faster edition of my string math routines. Jack provided another source of string math code from Treebeard. Treebeard's structure have many, may subs and functions. If you added it to your routines, you would add 50 subs/functions to work with addition, subtraction, multiplication, division, and square root calculations. Now you only need to call one sub for each of those, and then those 5 subs call the other subs and functions. In my original string math, which did not include square root, everything was contained in one sub. YOU called one sub, using an operator like "+", "-", etc. and the string math operation was returned. That's a lot less clutter when adding such a routine to function in another program.

So...

Which method do you guys prefer, and what pros and cons do you see in both if SEVERAL are needed to complete a library?

For me, it's the following.

SUBS and FUNCTIONS:

Pros:
Easier for the developer to work with when debugging.
Fewer problems or no need at all to clear variables.
Advantage to passing variables by reference. It's a neat trick to change the names without additional renaming statements.
Faster to code, provided you use TYPES for many passed variables to cut down on the variable lists passed.
Can be identified in the editor (IDE) easily enough if a prefix is used for each like SUB Smath_Mult, SUB SMath_DIV, etc.

Cons:
Harder for the user to find their own program subs and functions n the mix.
Cluttered SUB/FUNCTIONS lists to sort through in the IDE.
Requires multiple CALL arguments instead of just a single call the library sub like CALL StringMath().


------------------------------------------------------------------------------------------------------------------------

GOSUBs in a single SUB

Pros:
All code contained in one easy to port sub routine.
Less project time working out passing variables; (e.g., GOSUB StringMult instead of String_Mult var1, va2, var3, etc.
Keeps the subs and function list in the editor clean, making it easier to navigate the program to which it is ported.

Cons:
More work making sure variable names do not conflict with other GOSUB routines, meaning  more need for unique variable names.
More work zeroing variables.
Possible stack space issues if too nested and a RETURN is missed.
Harder for the developer to work on in the IDE, although Alt arrow left indexing helps some.

--------------------------------------------------------------------------------------------------------------------------

Anyway, what other pros and cons come to mind and again, which method would you rather use as a library addition in your own programming projects?

Pete

Print this item

  The Copyit Utility
Posted by: eoredson - 08-27-2022, 05:49 AM - Forum: Utilities - Replies (3)

Documentation public domain 08/15/2014:

Copyit v5.5a: File copy utility (PD 2014):

Copyit is a small yet powerful replacement to the DOS Copy and Xcopy commands.

"If it can't be copied with Copyit, it probably doesn't need to be copied."


Copyit55.zip for VBdos
Copyv9r5.zip for QB64



Attached Files
.zip   COPYIT55.ZIP (Size: 200.05 KB / Downloads: 34)
.zip   COPYV9R5.ZIP (Size: 586.99 KB / Downloads: 43)
Print this item

  Angle, Vector, Radian, and Distance Library
Posted by: TerryRitchie - 08-27-2022, 12:59 AM - Forum: Works in Progress - Replies (10)

While working on the tutorial site I decided the "Vectors, Angles & Rotation" lesson needed rewritten. Over the years I've had a few people point out that I was calculating these using methods much more difficult than needed. Also pointed out was some incorrect terminology I was using.

So, over the past week I went on a math quest to try and get these concepts correct. I decided to write a small library of routines to work with angles, vectors, and radians.

If you are mathematically inclined could you please take a moment to look over the code for any glaring errors I may have? Perhaps better ways of doing the math, my wording, etc.. I'm completely self-taught when it comes to higher math (Algebra II in high school) and don't always know the correct nomenclature to use. I believe I have it right this time from the week-long math brain-bender I went on.

These routines will be incorporated in the lesson and I plan to write a new lesson for creating and maintaining your own libraries using this one amongst others.

Code: (Select All)
'* Vector Demo - Tag, you're it!
'------------------------------------------------------------------------------------------------------------
' AVRDLibTop.BI
' Angle, Vector, Radian, and Distance Library
' By Terry Ritchie  quickbasic64@gmail.com
' 08/26/22
' Open source code - modify and distribute freely
' Original author's name must remain intact
'
' Declaration needed for the correct operation of the library.
'
TYPE XYPOINT '    2D point location definition
    x AS SINGLE ' x coordinate
    y AS SINGLE ' y coordinate
END TYPE
'------------------------------------------------------------------------------------------------------------

TYPE A_CIRCLE '                  circle definition
    location AS XYPOINT '        x,y coordinate
    vector AS XYPOINT '          x,y vector
    radius AS INTEGER '          radius
END TYPE

DIM RCircle AS A_CIRCLE '        a red circle
DIM GCircle AS A_CIRCLE '        a green circle
DIM Speed AS INTEGER '           speed of red circle
DIM Distance AS SINGLE '         distance between red and green circle
DIM Vector AS XYPOINT '          vector calculations
DIM Angle AS SINGLE '            angle calculations
DIM Radian AS SINGLE '           radian calculations

SCREEN _NEWIMAGE(640, 480, 32) ' graphics screen
_MOUSEHIDE '                     hide operating system mouse pointer
RCircle.location.x = 319 '       define circle properties
RCircle.location.y = 239
RCircle.radius = 30
GCircle.radius = 30
Speed = 3
DO '                                                               begin main program loop
    _LIMIT 60 '                                                    60 frames per second
    CLS
    P2PVector RCircle.location, GCircle.location, RCircle.vector ' vector from green to red circle
    Distance = P2PDistance(RCircle.location, GCircle.location) '   distance from center of circles
    Angle = P2PAngle(RCircle.location, GCircle.location) '         angle from center of circles
    Radian = Angle2Radian(Angle) '                                 radian calculated from angle
    Angle2Vector Angle, Vector
    PRINT "      Library Results     "
    PRINT " -------------------------"
    PRINT " P2PDistance   "; Distance
    PRINT " P2PAngle      "; Angle
    PRINT " Vector2Angle  "; Vector2Angle(Vector) '                angle calculated from vector
    PRINT " Radian2Angle  "; Radian2Angle(Radian) '                angle calculated from radian
    PRINT " Angle2Radian  "; Radian
    PRINT " Vector2Radian "; Vector2Radian(Vector) '               radian calculated from vector
    PRINT " Radian2Circle "; Radian2Circle(Radian) '               circle radian calculated from radian
    PRINT USING " P2PVector      Vx=##.##  Vy=##.##"; RCircle.vector.x; RCircle.vector.y
    PRINT USING " Angle2Vector   Vx=##.##  Vy=##.##"; Vector.x; Vector.y
    Radian2Vector Radian, Vector '                                 vector calculated from radian
    PRINT USING " Radian2Vector  Vx=##.##  Vy=##.##"; Vector.x, Vector.y
    LOCATE 2, 39: PRINT "TAG" '                                              print title of game
    IF Distance > GCircle.radius + RCircle.radius THEN '                     are circles colliding?
        RCircle.location.x = RCircle.location.x + RCircle.vector.x * Speed ' no, update enemy location
        RCircle.location.y = RCircle.location.y + RCircle.vector.y * Speed
    ELSE '                                                                   yes, circles colliding
        LOCATE 2, 35: PRINT "You're it!" '                                   print message to player
    END IF
    WHILE _MOUSEINPUT: WEND '                                                get latest mouse information
    GCircle.location.x = _MOUSEX '                                           update player location
    GCircle.location.y = _MOUSEY
    CIRCLE (GCircle.location.x, GCircle.location.y), GCircle.radius, _RGB32(0, 255, 0) '  draw player
    PAINT (GCircle.location.x, GCircle.location.y), _RGB32(0, 127, 0), _RGB32(0, 255, 0)
    CIRCLE (RCircle.location.x, RCircle.location.y), RCircle.radius, _RGB32(255, 0, 0) '  draw enemy
    PAINT (RCircle.location.x, RCircle.location.y), _RGB32(127, 0, 0), _RGB32(255, 0, 0)
    CIRCLE (RCircle.location.x, RCircle.location.y), 30, , -Radian2Circle(Radian), -Radian2Circle(Radian)
    _DISPLAY '                                                               update screen with changes
LOOP UNTIL _KEYDOWN(27) '                                                    leave when ESC pressed
SYSTEM '                                                                     return to operating system

'------------------------------------------------------------------------------------------------------------
' AVRDLib.BI
' Angle, Vector, Radian, and Distance Library
' By Terry Ritchie  quickbasic64@gmail.com
' 08/26/22
' Open source code - modify and distribute freely
' Original author's name must remain intact
'
' All subroutines and functions treat 0 degree and 0 radian as up and rotation is clock-wise.
' Some routines have dependencies on other routines.
'
' ** Subroutines **
'
' Angle2Vector  - converts the supplied degree angle (0 to 360) to a normalized vector
' P2PVector     - calculates the normalized vector between 2 points
' Radian2Vector - converts the supplied radian (0 to 2*PI) to a normalized vector

' ** Functions **
'
' Angle2Radian  - converts the supplied angle (0 to 360) to a radian (0 to 2*PI)
' FixRange      - ensures a value stays within a 0 to maximum range of values
' P2PDistance   - calculates the distance between 2 points
' P2PAngle      - calculates the angle (0 to 360) between 2 points
' Radian2Angle  - converts the supplied radian (0 to 2*PI) to a degree angle (0 to 360)
' Radian2Circle - converts the supplied radian (0 to 2*PI) to a radian (0 to 2*PI) to be used with the
'                 CIRCLE statement. The output radian adjusts the CIRCLE statement's radian so 0 is up
'                 and increasing radian values rotate in a clock-wise fashion.
' Vector2Angle  - converts the supplied normalized vector to a degree angle (0 to 360)
' Vector2Radian - converts the supplied normalized vector to a radian (0 to 2*PI)
'
' The following statements are needed at the top of the code for this library to function properly.
' (Use INCLUDE metastatement with AVRDLibTop.BI to include automatically.)
'
'  TYPE XYPOINT '    2D point location definition
'      x AS SINGLE ' x coordinate
'      y AS SINGLE ' y coordinate
'  END TYPE
'
'                                   0 Deg
'                                  0PI Rad                                   All functions and subroutines
'                                  *******                                   designed to treat 0 degrees,
'                             *****       *****                              0 radian, and vector 0,-1
'                         ****                 ****                          as up or north with values
'             315 Deg   **         Vec 0,-1        **   45 Deg               increasing clockwise.
'                     **              |              **
'                    *   Vec -1,-1    |     Vec 1,-1   *                     Radians supplied in the range
'                   *            \    |    /            *                    of 0 to 2 * PI
'                  *               \  |  /               *
'        1.5PI Rad *                 \|/                 * 1/2PI Rad         Degrees supplied in the range
'         270 Deg  * Vec -1,0 --------+--------- Vec 1,0 *  90 Deg           of 0 to 359.99..
'                  *                 /|\                 *
'                  *               /  |  \               *                   Vectors supplied in the range
'                   *            /    |    \            *                    of -1,-1 to 1,1 normalized
'                    *   Vec -1,1     |     Vec 1,1    *
'             225 Deg **              |              ** 135 Deg
'                       **         Vec 0,1         **
'                         ****                 ****
'                             *****       *****
'                                  *******
'                                  PI Rad
'                                  180 Deg
'
'------------------------------------------------------------------------------------------------------------

SUB P2PVector (P1 AS XYPOINT, P2 AS XYPOINT, V AS XYPOINT)

    '** NOTE: V passed by reference is altered

    '** Point to Point Vector Calculator
    '** Returns the x,y normalized vectors from P1 to P2

    ' P1.x, P1.y = FROM coordinate            (INPUT )
    ' P2.x, P2.y = TO coordinate              (INPUT )
    ' V.x, V.y   = normalized vectors to P2   (OUTPUT)

    DIM D AS SINGLE ' distance between points

    V.x = P2.x - P1.x '      horizontal distance (  side A  )
    V.y = P2.y - P1.y '      vertical distance   (  side B  )
    D = _HYPOT(V.x, V.y) '   direct distance (hypotenuse)
    IF D = 0 THEN EXIT SUB ' can't divide by 0
    V.x = V.x / D '          normalized x vector (  -1 to 1 )
    V.y = V.y / D '          normalized y vector (  -1 to 1 )

END SUB

'------------------------------------------------------------------------------------------------------------

FUNCTION P2PDistance (P1 AS XYPOINT, P2 AS XYPOINT)

    '** Point to Point Distance Calculator
    '** Returns the distance between P1 and P2

    ' P1.x, P1.y - FROM coordinate (INPUT)
    ' P2.x, P2.y - TO   coordinate (INPUT)
    ' returns SQR((P2.x - P1.x)^2 + (P2.y - P1.y)^2) using QB64 _HYPOT() function

    P2PDistance = _HYPOT(P2.x - P1.x, P2.y - P1.y) ' return direct distance (hypotenuse)

END FUNCTION

'------------------------------------------------------------------------------------------------------------

FUNCTION P2PAngle (P1 AS XYPOINT, P2 AS XYPOINT)

    '** Point to Point Angle Calculator
    '** Returns the degree angle from point 1 to point 2 with 0 degrees being up

    ' P1.x, P1.y - FROM coordinate (INPUT)
    ' P2.x, P2.y - TO   coordinate (INPUT)

    ' 57.29578 = 180 / PI

    DIM Theta AS SINGLE ' the returned degree angle

    IF P1.y = P2.y THEN '                                 do both points have same y value?
        IF P1.x = P2.x THEN '                             yes, do both points have same x value?
            EXIT FUNCTION '                               yes, identical points, no angle (0)
        END IF
        IF P2.x > P1.x THEN '                             is second point to the right of first point?
            P2PAngle = 90 '                               yes, the angle must be 90
        ELSE '                                            no, second point is to the left of first point
            P2PAngle = 270 '                              the amgle must be 270
        END IF
        EXIT FUNCTION '                                   leave function, angle calculated
    END IF
    IF P1.x = P2.x THEN '                                 do both points have the same x value?
        IF P2.y > P1.y THEN '                             yes, is second point below first point?
            P2PAngle = 180 '                              yes, the angle must be 180
        END IF
        EXIT FUNCTION '                                   leave function, angle calculated
    END IF
    Theta = _ATAN2(P2.y - P1.y, P2.x - P1.x) * 57.29578 ' calculate +/-180 degree angle
    IF Theta < 0 THEN Theta = 360 + Theta '               convert to 360 degree
    Theta = Theta + 90 '                                  set 0 degrees as up
    IF Theta > 360 THEN Theta = Theta - 360 '             adjust accordingly if needed
    P2PAngle = Theta '                                    return degree angle (0 to 359.99..)

END FUNCTION

'------------------------------------------------------------------------------------------------------------

FUNCTION Vector2Angle (V AS XYPOINT)

    '** Vector to Angle Calculator
    '** Converts the supplied normalized vector to a degree angle with 0 degrees facing up

    ' V.x, V.y - normalized vector (INPUT)

    ' 57.29578 = 180 / PI

    DIM Degrees AS SINGLE ' the returned degree angle

    Degrees = _ATAN2(V.y, V.x) * 57.29578 '         get angle from vector (-180 to 180)
    IF Degrees < 0 THEN Degrees = 360 + Degrees '   convert to 360
    Degrees = Degrees + 90 '                        set 0 degrees as up
    IF Degrees > 360 THEN Degrees = Degrees - 360 ' adjust if necessary
    Vector2Angle = Degrees '                        return degree angle (0 to 359.99..)

END FUNCTION

'------------------------------------------------------------------------------------------------------------

SUB Angle2Vector (A AS SINGLE, V AS XYPOINT)

    '** NOTE: V passed by reference is altered

    '** Angle to Vector Calculator
    '** Converts the supplied degree angle to a normalized vector

    ' A        - degree angle      (INPUT )
    ' V.x, V.y - normalized vector (OUTPUT)

    ' .017453292 = PI / 180

    DIM Angle AS SINGLE ' the angle value passed in

    Angle = A '                         don't alter passed in value
    IF Angle < 0 OR Angle >= 360 THEN ' angle outside limits?
        Angle = FixRange(Angle, 360) '  yes, correct angle
    END IF
    V.x = SIN(Angle * .017453292) '     return x vector
    V.y = -COS(Angle * .017453292) '    return y vector

END SUB

'------------------------------------------------------------------------------------------------------------

FUNCTION Vector2Radian (V AS XYPOINT)

    '** Vector to Radian Calculator
    '** Converts the supplied vector to a radian (0 to 2*PI)

    ' V.x, V.y - the supplied vector (INPUT)

    Vector2Radian = Angle2Radian(Vector2Angle(V)) ' return radian (0 to 2*PI)

END FUNCTION

'------------------------------------------------------------------------------------------------------------

SUB Radian2Vector (R AS SINGLE, V AS XYPOINT)

    '** NOTE: V passed by reference is altered

    '** Radian to Vector Calculator
    '** Converts the supplied radian to a normalized vector

    ' R        - supplied radian                (INPUT )
    ' V.x, V.y - the returned normalized vector (OUTPUT)

    ' 6.2831852 = 2 * PI

    DIM Radian AS SINGLE ' the radian value passed in

    Radian = R '                                don't alter passed in value
    IF Radian < 0 OR Radian >= 6.2831852 THEN ' radian outside limits?
        Radian = FixRange(Radian, 6.2831852) '  yes, correct radian
    END IF
    Angle2Vector Radian2Angle(Radian), V '      return normalized vector

END SUB

'------------------------------------------------------------------------------------------------------------

FUNCTION Radian2Angle (R AS SINGLE)

    '** Radian to Degree Angle Calculator
    '** Converts the supplied radian to an angle in degrees

    ' R - the supplied radian (INPUT)
    ' returns R * 180 / PI using the QB64 _R2D() function

    ' 6.2831852 = 2 * PI

    DIM Radian AS SINGLE ' the radian value passed in

    Radian = R '                                don't alter passed in value
    IF Radian < 0 OR Radian >= 6.2831852 THEN ' radian outside limits?
        Radian = FixRange(Radian, 6.2831852) '  yes, correct radian
    END IF
    Radian2Angle = _R2D(Radian) '               return angle (0 to 359.99..)

END FUNCTION

'------------------------------------------------------------------------------------------------------------

FUNCTION Angle2Radian (A AS SINGLE)

    '** Degree Angle to Radian Calculator
    '** Converts the supplied degree angle to radian

    ' A - the supplied degree angle (INPUT)
    ' returns A * PI / 180 using QB64 _D2R() function

    DIM Angle AS SINGLE ' the angle value passed in

    Angle = A '                         don't alter passed in value
    IF Angle < 0 OR Angle >= 360 THEN ' angle outside limits?
        Angle = FixRange(Angle, 360) '  yes, correct angle
    END IF
    Angle2Radian = _D2R(Angle) '        return radian (0 to 2*PI)

END FUNCTION

'------------------------------------------------------------------------------------------------------------

FUNCTION Radian2Circle (R AS SINGLE)

    '** Radian to CIRCLE Statement Radian Calculator
    '** Produces an output radian to be used with the CIRCLE statement that makes 0 up and
    '** the radian value increase clockwise instead of the CIRCLE statement's counter-clockwise default.

    ' R - the supplied radian (INPUT)

    ' 7.8539815 = 2.5 * PI
    ' 6.2831852 =   2 * PI

    DIM Radian AS SINGLE ' the radian value passed in

    Radian = R '                                             don't alter passed in value
    IF Radian < 0 OR Radian >= 6.2831852 THEN '              radian outside of limits?
        Radian = FixRange(Radian, 6.2831852) '               yes, correct radian
    END IF
    Radian = 7.8539815 - Radian '                            radian location on circle
    IF Radian > 6.2831852 THEN Radian = Radian - 6.2831852 ' adjust if necessary
    Radian2Circle = Radian '                                 return CIRCLE statement radian value

END FUNCTION

'------------------------------------------------------------------------------------------------------------

FUNCTION FixRange (N AS SINGLE, M AS SINGLE)

    '** Returns N within a fixed 0 to M range

    ' N - value to check
    ' M - maximim value N must be less than

    '** Code for this function provided by dcromley
    '** https://staging.qb64phoenix.com/showthread.php?tid=817
    '** 08/27/22

    FixRange = N - INT(N / M) * M ' rotate value as needed

END FUNCTION

Print this item

  QB64pe version 3.0 released!
Posted by: SMcNeill - 08-26-2022, 06:30 PM - Forum: Announcements - Replies (49)

Well guys, all of us here on the development team are now happy to announce that we've officially released version 3.0 of QB64-PE!

Now, I can hear some of you already asking (and a few complaining) about, "Gosh Timmy, isn't that a large jump in version numbers suddenly?"

No.  No it is not.  Big Grin

As we've explained in the past, the reason why we dropped back down to below 1.0 as our version number was simply because we weren't confident that what we were publishing was a stable release.  We branched off from the last development version that the old time had left behind, and were uncertain if everything they'd been working on was finished, or still a work-in-progress and unstable.  In our opinions, anything 1.0 and above should be considered a stable release and not one that's under constant development and bugfixes -- such as what we've had so far.  (Just look at our version history and you'll see what I'm talking about -- v 0.8 comes out, v0.8.1 is released 2 days later to patch something, v0.8.2 comes the next day as another bug fix...)

V3.0 should be a stable version, and shouldn't be subject to the same issue of constant repair.  We've finally incorporated all the old QB64 Team's work, verified it, and moved past it.  Everything from this point on is all us, and any new issues introduced into the source are entirely by us.  We've moved past the point of uncertainty over the past work that we've inherited, and we're ready to move forward and proudly say, "As far as we know, everything in here should be working as expected."  (Now, saying that, there's *still* some long established bugs and glitches that haven't all been ironed out yet, but those are "working as expected".  We haven't gotten around to fixing them yet, but as far as we know, we haven't added any new glitches into the matrix as of yet.)

So why'd we go from v0.8.2 all the way to v3.0?  

To indicate that we're an extension of the old QB64 and newer than their last release.  The last version from the QB64 Team was v2.0.2 -- we've built upon that, and finally gotten what we consider to be a stable version.  v3.0 seems like a fitting name for the new release, don't you guys think?



So what has changed between version 0.8.2 and v3.0?  Lots of stuff!

Quote: This is the first major release of QB64 Phoenix Edition. v3.0.0 was chosen to avoid overlapping with the existing QB64 v1 and v2 versions. QB64 Phoenix Edition v3.0.0 is compatible with QB64 v2.0.2.
Enhancements
  • #122#125#130#132 - Several improvements to the Help display in the IDE - @RhoSigma-QB64
  • #136 - Several naming and visual changes to reflect the "Phoenix Edition" branding - @RhoSigma-QB64
    • The executable is now named 
      qb64pe
       on Linux and Mac and 
      qb64pe.exe
       on Windows.
  • #139 - The files written to ./internal/temp are now buffered in memory and only written out when a build is requested - @RhoSigma-QB64
Bug fixes
  • #127 - Fixed linking of static libraries on Windows - @mkilgore
  • #126 - The math evaluator in the IDE will no longer crash when dividing by zero - @mkilgore
  • #131 - 
    setup_lnx.sh
     was fixed to properly call 
    make clean
     - @GeorgeMcGinn

Full Changelog: v0.8.2...v3.0.0




Download can be found at our github, at the latest release page here:  Releases · QB64-Phoenix-Edition/QB64pe (github.com)

Print this item

  Draw that Circle
Posted by: James D Jarvis - 08-26-2022, 04:00 PM - Forum: Programs - Replies (17)

I was playing with alternate means draw filled circles and had the most success with the following routine.

the basic algorithm is simple:  determine the center of the circle , plot the y axis out to the distance or R (negative to positive) and calculate X for each Y. Draw a line at X across the Y axis for each point of Y until there's a circle.

I was playing with a number of different methods to draw and do the calculations and the ones included here are good to share.

rcircle took  .8789062 to .9335938 seconds
dcircle took .6015625 to .6601562 seconds
dmcircle took .6015625 to .6601562 seconds

dcircle tended to get the best draw time on my computer, it had the same  range as dmcircle but it tended to be lower on average so certainly a win for the reference table but no clear advantage to using mem to access the look up table.

EDIT: typo corrected... better version of the rcircle sub is later in the thread

Code: (Select All)
'Draw_that_circle
'
'By James D. Jarvis
'
'an alternate subroutine to draw a filled circle.
'the basic sub is rcircle, rcircle find X while stepping through Y for -radius to the radius
'dcircle,  references the precalculated table in the array nsqr() to otherwise drae as rcircle
'dmcircle, references the precalculated table in the array nsqr() as dcircle but makes uses of _mem for access.

Screen _NewImage(800, 500, 256)
Randomize Timer
Dim Shared nsqr(-32000 To 32000) As Long 'table holds the square values
Dim Shared nsq As _MEM 'let's access the memblock of the table

For n = -32000 To 32000 'precaluclaitng the square values of -32000 to 32000
    nsqr(n) = Abs(n) ^ 2
Next
nsq = _Mem(nsqr())
Input "press enter to start"; any$

'draw without look up table
t1 = Timer
For n = 1 To 64000
    ' r = Int(1 + Rnd * 60) 'comment this out in each l0op to see the difference with a fixed radius
    r = 30 'chanign the size certainyl crerates a speed difference
    rcircle Int(Rnd * 800), Int(Rnd * 500), r, Int(Rnd * 256)
Next n
t2 = Timer
Print "that was"; t2 - t1; " seconds for 64,000 circles"

'draw with look up table
Input "Press enter to continue"; A$
t3 = Timer
For n = 1 To 64000
    'r = Int(1 + Rnd * 60)
    r = 30
    dcircle Int(Rnd * 800), Int(Rnd * 500), r, Int(Rnd * 256)
Next n
t4 = Timer
Print "that was"; t4 - t3; " seconds for 64,000 circles"
Input "press enter to continue"; ask$
'draw with look up table and using mem offset
t5 = Timer
For n = 1 To 64000
    'r = Int(1 + Rnd * 60)
    r = 30
    dmcircle Int(Rnd * 800), Int(Rnd * 500), r, Int(Rnd * 256)
Next n
t6 = Timer
Print "that was"; t6 - t5; " seconds for 64,000 circles"
Print
Print "Analysis"
Print "rcircle took  "; t2 - t1; " seconds"
Print "dcircle took  "; t4 - t3; " seconds"
Print "dmcircle took  "; t6 - t5; " seconds"

_MemFree nsq

Sub rcircle (cx, cy, r, klr)
'simple filled circle drawing with making use of paint command
    For y = -r To r
        x = Sqr(r ^ 2 - y ^ 2)
        Line (cx - x, cy + y)-(cx + x, cy + y), klr
        ' Print x
    Next y
End Sub

Sub dcircle (cx, cy, r, klr)
    'simple routine to draw a circle using a look up table to speed up calculations
    y = -r
    Do
        x = Sqr(nsqr(r) - nsqr(y))
        Line (cx - x, cy + y)-(cx + x, cy + y), klr
        y = y + 1
    Loop Until y > r
End Sub

Sub dmcircle (cx, cy, r, klr)
    'simple routine to draw a circle using a look up table to speed up calculations
    y = -r
    Do
        x = Sqr(_MemGet(nsq, nsq.OFFSET + (r + 32000) * 4, Long) - _MemGet(nsq, nsq.OFFSET + (y + 32000) * 4, Long))
        Line (cx - x, cy + y)-(cx + x, cy + y), klr
        y = y + 1
    Loop Until y > r
End Sub

Sub wcircle (cx, cy, r, klr)
    'was testing if there was a notable difference between using a do loop or a while loop, left it here if anyone else wanted to try it
    y = -r
    While y <= r
        x = Sqr(nsqr(r) - nsqr(y))
        Line (cx - x, cy + y)-(cx + x, cy + y), klr
        y = y + 1
    Wend
End Sub

Print this item

  Most popular programming languages
Posted by: bert22306 - 08-25-2022, 09:23 PM - Forum: General Discussion - Replies (21)

Hey guys, I just saw this from the IEEE:

https://spectrum.ieee.org/top-programmin...uages-2022

Looks like Python is #1 and C, plus two variants of C, are #2, #3, and #4. Okay, we sort of expected that much.

QuickBasic per se does not make the list, but Visual Basic strangely enough does. So that's something. The other interesting point, Visual Basic is more popular than some real stalwarts, like Fortran, Pascal, Lisp, Prolog, and Cobol.

That's something, at least. I find it hard to believe that today, VB is more popular than the various flavors of QuickBasic, but some of you probably know better than me about such things.

Print this item

  PEEK/POKE Video buffer
Posted by: BDS107 - 08-25-2022, 09:31 AM - Forum: Help Me! - Replies (7)

Hello everyone,
In the good old days we used PEEK and POKE to read and write on the screen address. See also the example below.

Code: (Select All)
SCREEN 0
WIDTH 80, 25
DEF SEG = &HB800
DO
  FOR a = 0 TO 4000 STEP 4
      x = INT(RND * 2) + 48
      y = ((INT(RND * 2)) * 8) + 2
      POKE a, x
      POKE a + 1, y
  NEXT
LOOP UNTIL INKEY$ <> ""
SYSTEM


If we use SCREEN _NEWIMAGE(80, 25, 0) it no longer works. See example below.
Any suggestions on how to use PEEK/POKE?

Code: (Select All)
SCREEN _NEWIMAGE(80, 25, 0)
DEF SEG = &HB800
DO
  FOR a = 0 TO 4000 STEP 4
      x = INT(RND * 2) + 48
      y = ((INT(RND * 2)) * 8) + 2
      POKE a, x
      POKE a + 1, y
  NEXT
LOOP UNTIL INKEY$ <> ""
SYSTEM

Print this item

  Defsng etc versus _Define
Posted by: PhilOfPerth - 08-25-2022, 01:21 AM - Forum: Help Me! - Replies (5)

I'm trying to come to grips with the _Define keyword in QB64, as against the "traditional" DefStr, DefInt etc. They appear to do the same thing, but I'm sure I'm missing something, otherwise it wouldn't be there. Can someone elucidate please?   Huh

Print this item