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

Username/Email:
  

Password
  





Search Forums

(Advanced Search)

Forum Statistics
» Members: 482
» Latest member: zaalexijuniorz5256
» Forum threads: 2,796
» Forum posts: 26,366

Full Statistics

Latest Threads
Raspberry OS
Forum: Help Me!
Last Post: Pete
35 minutes ago
» Replies: 1
» Views: 16
fast file find with wildc...
Forum: Help Me!
Last Post: Pete
1 hour ago
» Replies: 1
» Views: 21
Tenary operator in QB64 w...
Forum: Utilities
Last Post: Pete
1 hour ago
» Replies: 6
» Views: 62
Video Renamer
Forum: Works in Progress
Last Post: Pete
1 hour ago
» Replies: 3
» Views: 49
List of file sound extens...
Forum: Help Me!
Last Post: madscijr
1 hour ago
» Replies: 9
» Views: 117
Need help capturng unicod...
Forum: General Discussion
Last Post: SMcNeill
1 hour ago
» Replies: 24
» Views: 313
QB64PE v4.0 is now live!!
Forum: Announcements
Last Post: RhoSigma
2 hours ago
» Replies: 35
» Views: 1,027
Remark Remover (WIP)
Forum: Works in Progress
Last Post: Pete
2 hours ago
» Replies: 0
» Views: 10
games or graphics for 3-D...
Forum: General Discussion
Last Post: madscijr
Yesterday, 01:09 PM
» Replies: 26
» Views: 782
Text-centring subs
Forum: Utilities
Last Post: SierraKen
Yesterday, 05:46 AM
» Replies: 2
» Views: 52

 
  blue circle isn't drawing and print isn't working?
Posted by: madscijr - 09-20-2024, 10:42 PM - Forum: Help Me! - Replies (12)

OK, I'm a little stumped, I'm trying to use Steve's circle drawing routine from a while back, to draw a red circle and a blue circle, and print on the screen the x,y, radius of the circle and the color. It's drawing the red circle, but not the blue one, and no text is appearing. If I could get a 2nd set of eyes to expose my foolishness, that would be most appreciated!

Code: (Select All)
' Circle code by SMcNeill from:
' Circles and Ellipses(Tilt and Fill)
' https://qb64phoenix.com/forum/showthread.php?tid=1806

' CONSTANTS
Const FALSE = 0
Const TRUE = Not FALSE

' COLORS
Dim Shared cRed~&
Dim Shared cOrangeRed~&
Dim Shared cDarkOrange~&
Dim Shared cOrange~&
Dim Shared cGold~&
Dim Shared cYellow~&
Dim Shared cOliveDrab1~&
Dim Shared cLime~&
Dim Shared cMediumSpringGreen~&
Dim Shared cSpringGreen~&
Dim Shared cCyan~&
Dim Shared cDeepSkyBlue~&
Dim Shared cDodgerBlue~&
Dim Shared cSeaBlue~&
Dim Shared cBlue~&
Dim Shared cBluePurple~&
Dim Shared cDeepPurple~&
Dim Shared cPurple~&
Dim Shared cPurpleRed~&
Dim Shared cDarkRed~&
Dim Shared cBrickRed~&
Dim Shared cDarkGreen~&
Dim Shared cGreen~&
Dim Shared cOliveDrab~&
Dim Shared cLightPink~&
Dim Shared cHotPink~&
Dim Shared cDeepPink~&
Dim Shared cMagenta~&
Dim Shared cBlack~&
Dim Shared cDimGray~&
Dim Shared cGray~&
Dim Shared cDarkGray~&
Dim Shared cSilver~&
Dim Shared cLightGray~&
Dim Shared cGainsboro~&
Dim Shared cWhiteSmoke~&
Dim Shared cWhite~&
Dim Shared cDarkBrown~&
Dim Shared cLightBrown~&
Dim Shared cKhaki~&
Dim Shared cEmpty~&

Dim Shared iScreenWidth%
Dim Shared iScreenHeight%

' SET SHARED VALUES
cRed = _RGB32(255, 0, 0)
cOrangeRed = _RGB32(255, 69, 0)
cDarkOrange = _RGB32(255, 140, 0)
cOrange = _RGB32(255, 165, 0)
cGold = _RGB32(255, 215, 0)
cYellow = _RGB32(255, 255, 0)
cOliveDrab1 = _RGB32(192, 255, 62)
cLime = _RGB32(0, 255, 0)
cMediumSpringGreen = _RGB32(0, 250, 154)
cSpringGreen = _RGB32(0, 255, 160)
cCyan = _RGB32(0, 255, 255)
cDeepSkyBlue = _RGB32(0, 191, 255)
cDodgerBlue = _RGB32(30, 144, 255)
cSeaBlue = _RGB32(0, 64, 255)
cBlue = _RGB32(0, 0, 255)
cBluePurple = _RGB32(64, 0, 255)
cDeepPurple = _RGB32(96, 0, 255)
cPurple = _RGB32(128, 0, 255)
cPurpleRed = _RGB32(128, 0, 192)
cDarkRed = _RGB32(160, 0, 64)
cBrickRed = _RGB32(192, 0, 32)
cDarkGreen = _RGB32(0, 100, 0)
cGreen = _RGB32(0, 128, 0)
cOliveDrab = _RGB32(107, 142, 35)
cLightPink = _RGB32(255, 182, 193)
cHotPink = _RGB32(255, 105, 180)
cDeepPink = _RGB32(255, 20, 147)
cMagenta = _RGB32(255, 0, 255)
cBlack = _RGB32(0, 0, 0)
cDimGray = _RGB32(105, 105, 105)
cGray = _RGB32(128, 128, 128)
cDarkGray = _RGB32(169, 169, 169)
cSilver = _RGB32(192, 192, 192)
cLightGray = _RGB32(211, 211, 211)
cGainsboro = _RGB32(220, 220, 220)
cWhiteSmoke = _RGB32(245, 245, 245)
cWhite = _RGB32(255, 255, 255)
cDarkBrown = _RGB32(128, 64, 0)
cLightBrown = _RGB32(196, 96, 0)
cKhaki = _RGB32(240, 230, 140)
cEmpty = _RGB32(0, 0, 0, 0) ' _RGBA(red, green, blue, alpha) where alpha& specifies the alpha component transparency value from 0 (fully transparent) to 255 (opaque).

iScreenWidth% = 1024 ' 800
iScreenHeight% = 768 ' 600

' LOCAL VARIABLES
Dim iX As Integer
Dim iY As Integer
Dim iR As Integer
Dim iC As _Unsigned Long
Dim sT As String

' CLEAR SCREEN & DRAW CIRCLES
Screen _NewImage(iScreenWidth%, iScreenHeight%, 32)
'Screen _NewImage(_DesktopWidth, _DesktopHeight, 32)
_ScreenMove 0, 0
_Dest 0: Cls , cBlack

'_Display ' update screen with changes & wait for next update
'_AutoDisplay ' RETURN TO AUTODISPLAY


Color , cBlack: Cls
Color cWhite, cEmpty
Print "X      Y      Radius   Color"

iX = 200 ' iScreenWidth% \ 2
iY = 200 ' iScreenHeight% \ 2
iR = 50
iC = cBlue
sT = "blue"
DrawNext iX, iY, iR, iC, sT

iX = 300 ' iScreenWidth% \ 4
iY = 300 ' iScreenHeight% \ 4
iR = 50
iC = cRed
sT = "red"
DrawNext iX, iY, iR, iC, sT

'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)

'sleep

End

' /////////////////////////////////////////////////////////////////////////////

Sub DrawNext (x%, y%, r%, c~&, text$)
    Color cCyan, cEmpty
    Print Left$(_Trim$(Str$(x%)) + "   ", 3) + "   " + Left$(_Trim$(Str$(y%)) + "   ", 3) + "   " + Left$(_Trim$(Str$(r%)) + "   ", 6) + "   " + text$
    Call CircleFill(x%, y%, r%, c~&)
End Sub ' DrawNext

' /////////////////////////////////////////////////////////////////////////////

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 ' CircleFill

' /////////////////////////////////////////////////////////////////////////////

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 ' EllipseFill

' /////////////////////////////////////////////////////////////////////////////

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 ' EllipseTilt

' /////////////////////////////////////////////////////////////////////////////

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 ' EllipseTiltFill

Print this item

  TCP/IP invalid handle error. What can I do?
Posted by: TempodiBasic - 09-20-2024, 10:16 PM - Forum: Help Me! - Replies (3)

Hi friends,
please help me to find where I have coded the bug...

Code: (Select All)

$Unstable:Http

Screen _NewImage(512, 512, 256)

Dim a(511, 511) As Integer 'an array we'll send

x = _OpenClient("TCP/IP:1234:localhost") 'try to connect to a host

If x = 0 Then 'couldn't be client, so become a host
    'put some data into array a
    For xx = 0 To 511
        For yy = 0 To 511
            a(xx, yy) = xx * yy
        Next
    Next
    Print "(Try passing data via TCP/IP!)"
    Print "Waiting... (Press any key to end)"
    x = _OpenHost("TCP/IP:1234")
    If x = 0 Then Print "failure to create host" Else Print "Host ON"
End If


x = _OpenClient("TCP/IP:1234") 'try to connect to a host
Print x
If x < 0 Then
    z = _OpenConnection(x)
    Print "z"; z
    'connect to host as a client



    If z < 0 Then
        Print "Connected to host. Reading data..."
        Do
            Put #z, , a() 'send array a to any client that connects
            Close z
            Print "Array data send to client!"


            Get #x, , a()
            _Limit 100
        Loop Until EOF(x) = 0 'wait until enough data to fill the array arrives
        For xx = 0 To 511
            For yy = 0 To 511
                PSet (xx, yy), a(xx, yy)
            Next
        Next
        Close x
        Print "That's how you share data folks!" 'G@lleon
        Do: Loop Until InKey$ = ""
    Else
        Print "Failure connection with z "; z
    End If
    _Limit 10

    Print "Finished!"
    End

Else
    Print "Failure to create host client connection "; x
End If

End

I get always the message of error "invalid Handle" on line ... (that of _OPENCONNECTION instruction) but I am not able to understand why.
Thanks for time spent for helping me

Print this item

  Testing Discord Hooks
Posted by: admin - 09-20-2024, 03:10 PM - Forum: General Discussion - No Replies

Nothing to see here either. Just testing some interactions with the forums and Discord. Just ignore any of these topics you see. I'll delete them and clean them all up later. This is just forum upkeep as normal.

Print this item

  Disable _GL Rendering
Posted by: SMcNeill - 09-20-2024, 02:58 PM - Forum: Learning Resources and Archives - Replies (2)

\

Code: (Select All)

Screen _NewImage(640, 480, 32)

GL_Render 0 'don't render to GL, as the next command will lock up and freeze the program if you do
_ScreenMove _Middle
GL_Render -1 'turn that GL rendering back on
Do
    _Limit 30 'A simple loop to see our GL display before ESC is hit
Loop Until _KeyDown(27)

Sub GL_Render (GL_go)
    Select Case GL_go
        Case 0 'disable GL rendering
            _DisplayOrder _Software
        Case -1 'enable GL rendering
            _DisplayOrder _Software , _Hardware , _GLRender
    End Select
    _Delay .2
End Sub



Sub _GL
    Static rtri, rquad
    _glViewport 0, 0, _Width, _Height
    _glMatrixMode _GL_PROJECTION '                          Set projection matrix
    _glLoadIdentity '                                      Matrix reset
    _gluPerspective 45.0F, _Width / _Height, 0.1F, 100.0F ' Perspective calculation
    _glMatrixMode _GL_MODELVIEW '                          set modelview matrix
    _glLoadIdentity
    _glShadeModel _GL_SMOOTH '                              allow smooth shading
    _glClearColor 0.0F, 0.0F, 0.0F, 0.5F
    _glClearDepth 1.0F '                                    set depth buffer
    _glEnable _GL_DEPTH_TEST '                              allow depth testing
    _glDepthFunc _GL_LEQUAL '                              set depth testing method
    _glHint _GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST '    set nicest projection matrix
    _glClear _GL_COLOR_BUFFER_BIT: _glClear _GL_DEPTH_BUFFER_BIT 'clear screen and depth buffer
    _glLoadIdentity '                                            matrix reset
    ' draw primitives here

    _glTranslatef -1.5F, 0.0F, -6.0F '      Shift to the left and to the depth - be careful, every other shift on the screen moves from the place where we moved before!


    _glRotatef rtri, 0.0F, 1.0F, 0.0F ' Rotate the triangle around the y-axis

    _glBegin _GL_TRIANGLES '            The beginning of drawing the PYRAMID

    _glColor3f 1.0F, 0.0F, 0.0F '      Red color (it is as _glColor3f Red, Green, Blue and values can be calculated as 1 / 255)
    _glVertex3f 0.0F, 1.0F, 0.0F '      Upper point
    _glColor3f 0.0F, 1.0F, 0.0F '      Green color
    _glVertex3f -1.0F, -1.0F, 1.0F '    left bottom point
    _glColor3f 0.0F, 0.0F, 1.0F '      blue color
    _glVertex3f 1.0F, -1.0F, 1.0F '    right bottom point

    _glColor3f 1.0F, 0.0F, 0.0F '  red color
    _glVertex3f 0.0F, 1.0F, 0.0F ' upper point (right wall)
    _glColor3f 0.0F, 0.0F, 1.0F '  blue color
    _glVertex3f 1.0F, -1.0F, 1.0F 'left point (right wall)
    _glColor3f 0.0F, 1.0F, 0.0F '  green
    _glVertex3f 1.0F, -1.0F, -1.0F ' right point (right wall)                '

    _glColor3f 1.0F, 0.0F, 0.0F '    red
    _glVertex3f 0.0F, 1.0F, 0.0F '  upper point (rear wall)
    _glColor3f 0.0F, 1.0F, 0.0F '    green
    _glVertex3f 1.0F, -1.0F, -1.0F ' left point (rear wall)
    _glColor3f 0.0F, 0.0F, 1.0F '    blue
    _glVertex3f -1.0F, -1.0F, -1.0F 'right point (rear wall)

    _glColor3f 1.0F, 0.0F, 0.0F '    red
    _glVertex3f 0.0F, 1.0F, 0.0F '  upper point (back wall)
    _glColor3f 0.0F, 0.0F, 1.0F '    blue
    _glVertex3f -1.0F, -1.0F, -1.0F 'left point (left wall)
    _glColor3f 0.0F, 1.0F, 0.0F '    green
    _glVertex3f -1.0F, -1.0F, 1.0F ' right point (left wall)

    _glEnd 'triangle draw end

    _glTranslatef 3.0F, 0.0F, 0.0F 'we will move in the x-axis by 1.5 to the center and 1.5 to the right, where we will paint a quad
    'FOR THE ENTIRE OBJECT IN ONE COLOR:

    _glLoadIdentity '                  we call it to align the X Y Z axes to the original direction, without it it would default to the previous rotated state
    _glTranslatef 1.5F, 0.0F, -7.0F '  The displacement of the origin is higher than in a quad

    _glRotatef rquad, 1.0F, 1.0F, 1.0F 'Rotate the quad around the x-axis

    _glBegin _GL_QUADS '              begin draw quad
    _glColor3f 0.0F, 1.0F, 0.0F '      green color
    _glVertex3f 1.0F, 1.0F, -1.0F '    left upper point
    _glVertex3f -1.0F, 1.0F, -1.0F '  right upper point
    _glVertex3f -1.0F, 1.0F, 1.0F '    right bottom point
    _glVertex3f 1.0F, 1.0F, 1.0F '    left bottom point

    _glColor3f 1.0F, 0.5F, 0.0F '      orange color
    _glVertex3f 1.0F, -1.0F, 1.0F '    right upper point (bottom wall)
    _glVertex3f -1.0F, -1.0F, 1.0F '  left upper point  (bottom wall)
    _glVertex3f -1.0F, -1.0F, -1.0F '  left bottom point (bottom wall)
    _glVertex3f 1.0F, -1.0F, -1.0F '  right bottm point (bottom wall)

    _glColor3f 1.0F, 0.0F, 0.0F '      red
    _glVertex3f 1.0F, 1.0F, 1.0F '    right upper point (front wall)
    _glVertex3f -1.0F, 1.0F, 1.0F '    Left upper point (front wall)
    _glVertex3f -1.0F, -1.0F, 1.0F '  left bottom point (front wall)
    _glVertex3f 1.0F, -1.0F, 1.0F '    right bottom point (front wall)

    _glColor3f 1.0F, 1.0F, 0.0F '      yellow
    _glVertex3f 1.0F, -1.0F, -1.0F '  right upper point (rear wall)
    _glVertex3f -1.0F, -1.0F, -1.0F '  left upper point (rear wall)
    _glVertex3f -1.0F, 1.0F, -1.0F '  left bottom point (rear wall)
    _glVertex3f 1.0F, 1.0F, -1.0F '    right bottom point (rear wall)

    _glColor3f 0.0F, 0.0F, 1.0F '      blue
    _glVertex3f -1.0F, 1.0F, 1.0F '  right upper point (left wall)
    _glVertex3f -1.0F, 1.0F, -1.0F '  left upper point (left wall)
    _glVertex3f -1.0F, -1.0F, -1.0F ' left bottom point (left wall)
    _glVertex3f -1.0F, -1.0F, 1.0F '  right bottom point (left wall)


    _glColor3f 1.0F, 0.0F, 1.0F ' purple
    _glVertex3f 1.0F, 1.0F, -1.0F ' right upper point (right wall)
    _glVertex3f 1.0F, 1.0F, 1.0F ' left upper point (right wall)
    _glVertex3f 1.0F, -1.0F, 1.0F 'Left bottom point (right wall)
    _glVertex3f 1.0F, -1.0F, -1.0F 'Right bottom point (right wall)

    _glEnd 'quad draw end
    rtri = rtri + 0.52F 'Incrementing the angle of rotation of the triangle
    rquad = rquad - 0.515F 'Incrementing the angle of rotation of the quad

    'it is important to RESET THE AXES so that they are rotated to the basic setting (otherwise the X axis can move to the Y axis) using _glLoadIdentity,
    'and it is EXTREMELY IMPORTANT to always move in the scene to the beginning of the scene using _glTranslateF
    'moving the object in openGL is not done by recalculating _glVertex, but by moving the start of rendering using _glTranslatef

End Sub


Now, the above is useful for folks who might want to use SUB _GL in a program and have encountered various issues.  The problem is, some of our graphic commands and SUB _GL don't necessary play nice together.  The simple solution around these issues is one like the above:

Turn off _GL drawing.
Do the problematic command (_SCREENMOVE _MIDDLE, _DESKTOPHEIGHT, _DESKTOPWIDTH, probably others)
Turn on _GL drawing.

It's simple and it seems to work for me without any real issues.  If you're having trouble with these type commands, this might just be what you've been looking for and you didn't even know it.  Wink




And for those wanting to see the glitch in action, simply set the value of GL_on to anything non-zero, before calling that _SCREENMOVE _MIDDLE statement.  The program will freeze up and do absolutely nothing for you.

Print this item

  How to find Default Web Browser in Linux ?
Posted by: ahenry3068 - 09-20-2024, 12:41 PM - Forum: Help Me! - Replies (3)

I want a program I'm working on to open a web page using the default browser.    Program is cross-platform and will be compiled for both WIN64 & LINUX.    Windows is easy here I just shell("start "+URL$).    I've figured out that in linux I can just shell "firefox  "+URL$ or shell "google-chrome " + URL$ and that works, but I don't know how to find the DEFAULT browser it's not in the ENVIRON$() and I'm not really sure how to go about it.

Print this item

  Another way to draw rounded rectangles
Posted by: James D Jarvis - 09-19-2024, 08:51 PM - Forum: Programs - Replies (4)

This uses SVG format to draw rounded rectangles. 

Code: (Select All)
'Draw rounded rectangles using SVG format
'by James D. Jarvis, use as you wish

Screen _NewImage(800, 500, 32)
_Title "Press any key to draw a new set of rectangles or Q to quit"
Randomize Timer
Dim si As _Unsigned Long
Do
    'refresh screen
    'define the svg description of 10 rounded rectangles
    Cls , _RGB32(100 + Int(Rnd * 150), 100 + Int(Rnd * 150), 100 + Int(Rnd * 150))
    ss$ = ""
    CX = 100: CY = 100: cRAD = 50
    For RR = 1 To 10
        xx = Int(Rnd * (_Width * .75)): yy = Int(Rnd * (_Height * .75))
        cRAD = Int(3 + Rnd * 12)
        WW = Int(30 + Rnd * 300): HH = Int(30 + Rnd * 300)
        ss$ = ss$ + doRrect$(xx, yy, cRAD, cRAD, WW, HH, _RGB32(Int(Rnd * 256), Int(Rnd * 256), Int(Rnd * 256)), _RGB32(Int(Rnd * 256), Int(Rnd * 256), Int(Rnd * 256)), Int(1 + Rnd * 25))
    Next RR
    simg$ = "<svg width='" + _Trim$(Str$(_Width)) + "' height='" + _Trim$(Str$(_Height)) + "'>" + ss$ + " </svg>"
    si = _LoadImage(simg$, 32, "memory") 'load the SVG image
    _PutImage (0, 0), si 'display the SVG image
    _FreeImage si
    Do
        kk$ = InKey$
    Loop Until kk$ <> ""
Loop Until UCase$(kk$) = "Q"
System
Function doRrect$ (x, y, rx, ry, w, h, sk As _Unsigned Long, fk As _Unsigned Long, swid)
    'returns the SVG description of a rounded rectangle
    'x,y are coordinates of rounded rectabgle on the screen
    'rx,ry are the radius of the rectangle corners
    'h,y are height and width of the rectangle
    'sk is the _rgb32 stroke color
    'fk is the _rgb32 fill color
    'swid is the stroke width of the rectangle
    doRrect$ = " <rect x='" + _Trim$(Str$(x)) + "' y='" + _Trim$(Str$(y)) + "' rx='" + _Trim$(Str$(rx)) + "' ry='" + _Trim$(Str$(ry)) + "' width='" + _Trim$(Str$(h)) + "' height='" + _Trim$(Str$(w)) + "' stroke='" + _Trim$(packcolorN$(sk)) + "' fill='" + _Trim$(packcolorN$(fk)) + "' stroke-width='" + _Trim$(Str$(swid)) + "'/>"
End Function

Function packcolorN$ (klr As _Unsigned Long)
    'convert an unsigned long color value into a hexidecimal string # that will be used in an SVG
    Dim As _Unsigned Long rk, gk, bk
    'get the color channels of the unsinged long color
    rk = _Red32(klr)
    gk = _Green32(klr)
    bk = _Blue32(klr)
    'convert those channel values into hexidecimal
    If rk < 16 Then
        r$ = "0" + Hex$(rk) 'put in a padded hexidcimal value
    Else
        r$ = Hex$(rk) 'put in a 2 digit hexidecimal value
    End If
    If gk < 16 Then
        g$ = "0" + Hex$(gk) 'put in a padded hexidcimal value
    Else
        g$ = Hex$(gk) 'put in a 2 digit hexidecimal value
    End If
    If bk < 16 Then
        b$ = "0" + Hex$(bk) 'put in a padded hexidcimal value
    Else
        b$ = Hex$(bk) 'put in a 2 digit hexidecimal value
    End If
    packcolorN$ = "#" + r$ + g$ + b$
End Function

Print this item

  Ball Screensaver
Posted by: SMcNeill - 09-19-2024, 03:03 PM - Forum: Programs - Replies (5)

The little demo should speak for itself.   It's simple, but I was just having fun playing around with my balls for a bit this morning, since it seems everyone else has been doing the same thing around here lately.  Big Grin

Code: (Select All)
Screen _NewImage(1024, 720, 32)
Randomize Timer
$Color:32

Type Ball_Type
x As Integer 'position
y As Integer
xchange As Integer 'speed
ychange As Integer
size As Integer 'size
c As _Unsigned Long 'color
End Type

Dim Balls(5000) As Ball_Type
'Init balls
For i = 0 To UBound(Balls)
Balls(i).size = Int(Rnd * 10) + 1
Select Case Int(Rnd * 2)
Case 0: Balls(i).c = Red
Case Else: Balls(i).c = Blue
End Select
Balls(i).x = Int(Rnd * _Width)
Balls(i).y = Int(Rnd * _Height)
Balls(i).xchange = Int(Rnd * 20) - 10
Balls(i).ychange = Int(Rnd * 20) - 10
Next

t# = Timer(.01)
Do
While _MouseInput: Wend
Cls
max = (Timer - t#) * 10
If max >= 1000 Then max = 1000
For i = 1 To max
CircleFill Balls(i).x, Balls(i).y, Balls(i).size, Balls(i).c
Balls(i).x = Balls(i).x + Balls(i).xchange
Balls(i).y = Balls(i).y + Balls(i).ychange
If _Hypot(Balls(i).x - _MouseX, Balls(i).y - _MouseY) < Balls(i).size Then
Balls(i).xchange = -Balls(i).xchange
Balls(i).ychange = -Balls(i).ychange
Balls(i).c = Green
End If
If Balls(i).x < 0 Then
Balls(i).x = 0
Balls(i).xchange = -Balls(i).xchange
End If
If Balls(i).y < 0 Then
Balls(i).y = 0
Balls(i).ychange = -Balls(i).ychange
End If
If Balls(i).x >= _Width Then
Balls(i).x = _Width
Balls(i).xchange = -Balls(i).xchange
End If
If Balls(i).y >= _Height Then
Balls(i).y = _Height
Balls(i).ychange = -Balls(i).ychange
End If
Next
_Limit 60
_Display
Loop

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


Have fun and see how long it takes you to turn all the balls green. Big Grin

Print this item

  simplistic misunderstanding about ; + "" in a print
Posted by: doppler - 09-19-2024, 01:37 AM - Forum: General Discussion - Replies (12)

I may have a simplistic misunderstand about the use of semicolon, strings, plus sign and quotes in print statements.

1 q$=chr$(34)
2 print q$; "test"; q$
3 print q$ + "test" + q$

Output is "test" and "test" on separate lines.  I assumed ? q$; "test"; q$ would be an improper use of concatenation in a print statement.  I thought line 3 was the right way. But it works.
If I try to type q$"" the line changes to q$; "".  Auto corrects and makes me wonder.  I checked this output in the mother tongue "qb45".  Works like qb64.

If the +'s are not needed, do they take cycles and code unnecessary ?  Again wondering.
I know PRINT is most code producing and time wasting part of the source in qb64.

Thanks

Print this item

  Need an Audio Expert.
Posted by: ahenry3068 - 09-18-2024, 11:28 PM - Forum: Help Me! - No Replies

I've got the following code.   The purpose is to create a Medium byterate Wave file WITHOUT METADATA.     I'm writing an Audio Book app for the Commander X16 and I don't have the processor power to parse and ignore Meta Data in the Wave.     Ignoring it creates clicks when the METADATA is treated as Audio.      I can create the proper files in Audacity but ffmpeg refuses to leave out the encoder MetaData even with the -metadata -1 directive. 

My solution for semi-automating the conversion is the following program which uses ffmpeg first to convert to raw_audio (no metadata) then use my code to tack on the WAV Header.   My program kind of works,  the files even play properly on the X16 where I'm ignoring a bunch of the WAV Header.    But I'm missing something important as none of the big boy programs on Linux or Windows recognize my output as a Valid WAV.    There are a couple fields in the RIFF/WAV Header I'm not filling in which I'm sure are the problem but I don't know what to put there. 

My code is attached and any help is appreciated.    Code is meant for Linux and hasn't been ported for Windows yet,   ffmpeg must be installed.

Identified one problem.   Header.FmtSpecific  has to be set equal to 16. But that still doesn't solve all the problems.

PROBLEM FIXED.     UPDATED CODE ATTACHED.   THIS WORKS TO STRIP METADATA FROM ANY AUDIO FILE AND OUTPUT IT AS A MONO WAV (Easily modified to do Stereo if you desire)



Attached Files
.bas   MakeBookWav.bas (Size: 5.1 KB / Downloads: 18)
Print this item

  Searching sateliet calculating position program.
Posted by: Rudi59 - 09-18-2024, 06:43 PM - Forum: General Discussion - Replies (4)

Hello every one.

I am a new member and searching a QB64 program that calculates the position of a group of satelites.
Because i am a hamradio amateur and interested in making contact with special designed hamradio satelites.
The programs i already have are too old and not working after year 2000 and because of that i do this request.
In that program i can put (so called) nasa/kepler parameters and some information of me. Then the program can predict the position of the/a satelite.
And yes, there are already beautifull programs, but i need a QB64 version. I can extend that QB64 program with routines for calculating
my antenne positions and control the antenne rotors.

Thanks in advance,

Rudi59

Print this item