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

 
  sb Spiral of ChatGPT fixed by kay63 trans and mod b+
Posted by: bplus - 01-04-2023, 05:19 PM - Forum: Programs - No Replies

Interesting development at Syntax Bomb today starting with some code from ChatGPT that kay63 got working in sb and I translated and fixed ever better in QB64:

Code: (Select All)
_Title "sb spiral of chatGPT - fixed by kay63 trans and mod by me, b+ 2023-01-04"
Const xmax = 600, ymax = 600
Dim Shared pi
pi = _Pi
Dim clr As _Unsigned Long
Screen _NewImage(xmax, ymax, 32)

' Set the starting position and radius of the spiral
x = ymax / 2 - .5 * ymax / pi
y = ymax / 2 - .5 * ymax / pi
r = 1

' Set the angle increment for each loop iteration
angle_inc = 5

' Set the maximum radius of the spiral
max_r = ymax / 2

' Set the maximum number of loops
max_loops = ymax

' Set the spiral rotation direction
direction = 1

' Draw the spiral
For i = 1 To max_loops
    ' Set the color for this loop iteration
    'Color i Mod 14
    ' Draw the spiral segment
    Select Case i Mod 3
        Case 0: clr = _RGB32(0, 255 * (i / 600), 128 - (i * 127 / 600))
        Case 1: clr = _RGB32(0, 100 * i / 600 + 55, 100 * i / 600 + 55)
        Case 2: clr = _RGB32(0, 255 * (i / 600), 128 - (i * 127 / 600))
    End Select
    arc x, y, r, angle_inc * i / 180 * pi, angle_inc * (i + 30) / 180 * pi, clr
    ' Increase the radius for the next loop iteration
    r = r + direction
    cnt = cnt + 1
    ' Check if the radius has reached the maximum
    If r > max_r Then
        ' Reverse the growing of the spiral
        direction = -direction
        ' Reset the radius
        r = max_r
    End If
    ' move the spiral:
    x = x + 1 / pi
    y = y + 1 / pi
    _Limit 60
Next
Sleep


Sub arc (x, y, r, raStart, raStop, c As _Unsigned Long) ' this does not check raStart and raStop like arcC does
    Dim al, a
    'x, y origin, r = radius, c = color

    'raStart is first angle clockwise from due East = 0 degrees
    ' arc will start drawing there and clockwise until raStop angle reached

    If raStop < raStart Then
        arc x, y, r, raStart, _Pi(2), c
        arc x, y, r, 0, raStop, c
    Else
        ' modified to easier way suggested by Steve
        'Why was the line method not good? I forgot.
        al = _Pi * r * r * (raStop - raStart) / _Pi(2)
        For a = raStart To raStop Step 1 / al
            PSet (x + r * Cos(a), y + r * Sin(a)), c
        Next
    End If
End Sub
EDIT: fixed some errors in coloring which surprisingly didn't really change outcome? No it's better now without a bunch of black lines.



Attached Files Thumbnail(s)
       
Print this item

  Thanks for the help.
Posted by: PhilOfPerth - 01-04-2023, 01:04 AM - Forum: General Discussion - Replies (5)

In these early days of a new year, I’d like to say thanks to those who’ve helped me and many others with coding problems.
 
People like Steve, and Bplus, and others, with much greater knowledge and skills  than I have, give freely of their time to help other “QBphiles” overcome problems. Their help is given with great patience, and with respect for the sometimes “bumpy” code we write, recognizing that although we may peel an egg with a surgical laser, a sharp blow with the back of a spoon can sometimes be sufficient.

Other coders sometimes recognize a problem as being similar to one they have had and solved, and provide helpful advice based on this.
This spirit of co-operation and generosity makes me confident that QB64PE will survive and thrive for a long time to come.


Wishing you all a happy, prosperous and productive new year. 

Print this item

Question Where is Pete?
Posted by: Kernelpanic - 01-03-2023, 06:59 PM - Forum: General Discussion - Replies (15)

I hope he did not shoot himself with his revolvers. . .  Confused

Print this item

  Three-dimensional array
Posted by: Kernelpanic - 01-03-2023, 06:39 PM - Forum: Programs - Replies (20)

Structure and representation of a three-dimensional array. What could one do with it? For example: day, month, total sales . . . Nice!  Tongue
Oh yes, wrong inputs are not caught yet.

Ebene = level,  Zeile = row,  Spalte = column

Code: (Select All)
'Dreidimensionales Feld mit graphischer Darstellung - 3. Jan. 2023

$Console:Only
Option _Explicit

Option Base 1
Dim As Integer dreiDimFeld(3, 4, 4)

'"dm" legt die Dimension(Ebenen) fest. Hier dreimal Bloecke a 16
'dz ist Anzahl Zeilen, ds ist Anzahl Spalten
Dim As Integer dm, dz, ds, dFeld
Dim As Integer ebene, zeile, spalte

Locate 2, 2

'Der Ablauf ist: 1te Ebene -> Durchlauf Zeile * Spalte
'dann folgt die naechste Ebene usw. so viele Ebenen
'wie vorhanden sind
dFeld = 1
For dm = 1 To 3
  For dz = 1 To 4
    'Nach jedem sechszehner Block Absatz
    'fuer naechsten Block. Csrlin+1 statt 2 -> schraege Anzeige
    Locate CsrLin + 1, CsrLin + 1
    For ds = 1 To 4
      dreiDimFeld(dm, dz, ds) = dFeld
      Print Using "## "; dreiDimFeld(dm, dz, ds),
      dFeld = dFeld + 1
    Next
  Next
  Print: Locate , 2
Next

Locate CsrLin + 2, 2

Input "Zeige Wert in Ebene : ", ebene
Locate CsrLin + 0, 2
Input "Zeige Wert in Zeile : ", zeile
Locate CsrLin + 0, 2
Input "Und in Spalte       : ", spalte

Locate CsrLin + 1, 2
Print Using "Wert in Ebene: # Zeile: # Spalte: # ist: ##"; ebene, zeile, spalte, dreiDimFeld(ebene, zeile, spalte)

End

Straight and oblique version.
[Image: Dreidimensionales-Feld2023.jpg]

Print this item

  Keyword of the Day 45: _PIXELSIZE
Posted by: SMcNeill - 01-03-2023, 01:37 PM - Forum: Keyword of the Day! - Replies (1)

_PIXELSIZE...  A truly useful word for the people who might want to make various library routines, but not so much so, for everyone else.

What is it?: _Pixelsize is a simple little function which tells us how many bytes a pixel takes up in memory.

How do we use it?: We simply just call it like any other function.  Something as simple as PS = _PixelSize will work just fine.

An example for people:


Code: (Select All)
Screen 0
Print _PixelSize 'should print 0
Sleep

Screen 12
Print _PixelSize 'should print 1
Sleep

Screen _NewImage(640, 480, 32)
Print _PixelSize 'should print 4
Sleep
System


Run the code above and give it a try.  You'll see that we start out in a text only screen, so _PixelSize reports 0 back to us -- there's no pixels in a text only screen!  There's only columns and rows!

Hit any key and then we swap over to a SCREEN 12 screen.  At this point, _PixelSize will report a value of 1 back to us.  Each pixel on the screen takes up one byte of memory.

Hit another key and we swap over to a 32-bit screen.  Now _PixelSize reports a value of 4 back to us.  This is what everyone should expect as 32-bit screens are, by definition, 32-bits -- or 4-bytes -- in size.  Each pixel has a single byte dedicated for Alpha, Red, Green, Blue color values, in a 32-bit screen.

... Which is all well and good, but not really all that useful in a single program.  If you create your screens, you'll probably know what they are to begin with, and there's no need to use _PixelSize to get that value for you...

... Which is why I mentioned this is a gem of a command for anyone who works on making library style code.  You never know when, who, or where your library routine might end up being called, and as such, you'll want to write it to work across various screen modes.  (Or to at least trouble shoot and error check against certain screen modes.)

For example, let's say I write a PerfectBox routine which draws a lovely graphical box, puts a texture on the background for it, and a label, and it interacts with the mouse, and plays music when it's on the screen and highlighted, and does your taxes for you, and convinces your significant other to look the other way while you make out with the sexy neighbor down the hall or across the road...

If I wrote such an amazing piece of code, I'd probably want to write it up as a library function and save it for use in all my programs.  Right?  Heck, I'd probably even want to share it with all you guys so I could brag to the world (well, the world of QB64PE anyway) about what I'd accomplished, and let all of you bask in its glory as well!

And then old @Pete comes along and starts griping... "None of my programs work now, thanks to your stupid PerfectLibrary button!!"

So how do I fix that??

Code: (Select All)
Sub PerfectButton (Parameters As HiddenByTrademark)
  If _PixelSize = 0 Then
     Print "Pete, this doesn't work in Screen 0!  It's a graphical button!"
     DeletePetesHardDrive
     LaughAtPete
     System
   End If
.... 
    'Rest of my PerfectButton Sub goes below here.
End Sub

Now, as you can see, we've error trapped for anyone using Screen 0 with our perfect button.  Pete can now insert our PerfectButton routine into all his code, and not get generic error messages about invalid syntax and such when he attempts to run his code...

... Let's just hope nobody except Pete happens to try and use our PerfectButton routine on a text Screen...  Our error handler may be a little more intense than most people approve of, in the example above...

Print this item

  while: wend
Posted by: fistfullofnails - 01-03-2023, 06:09 AM - Forum: General Discussion - Replies (24)

On Terry Ritchie's function/subroutine part of the QB64 tutorial, line 15 of subs.base,  we have:

Code: (Select All)
WHILE _MOUSEINPUT: WEND

The only way I've seen "WHILE" and "WEND" used is at the start and end of a loop, with some instructions  in between, which then ends with 'WEND".
I'm confused on what is exactly going on here.  Can anyone explain like I'm a five year old?

Code: (Select All)
DO
    _LIMIT 60
    WHILE _MOUSEINPUT: WEND
    IF _MOUSEBUTTON(1) THEN DrawStar _MOUSEX, _MOUSEY
    IF _MOUSEBUTTON(2) THEN Directions
    _DISPLAY
LOOP UNTIL _KEYDOWN(27)

Print this item

  Red/Green/Blue/GrayScale images
Posted by: SMcNeill - 01-02-2023, 08:18 PM - Forum: SMcNeill - Replies (3)

[Image: Pandora.jpg]

Code: (Select All)
pic = _LoadImage("Pandora.jpg", 32)
Screen pic
Sleep
pic256 = Grayscale256(pic)
Screen pic256
Sleep
red256 = RedScale256(pic)
Screen red256
Sleep
green256 = GreenScale256(pic)
Screen green256
Sleep
blue256 = BlueScale256(pic)
Screen blue256
Sleep

Function Grayscale256 (image As Long)
    Dim As Long d, s, temp, r, g, b
    Dim As _MEM m(1): Dim As _Offset o(1), l
    d = _Dest: s = _Source
    m(0) = _MemImage(image): o(0) = m(0).OFFSET
    temp = _NewImage(_Width(image), _Height(image), 256)
    m(1) = _MemImage(temp): o(1) = m(1).OFFSET
    _Dest temp: For i = 0 To 255: _PaletteColor i, _RGB32(i): Next: _Dest d
    Do
        r = _MemGet(m(0), o(0) + 1, _Unsigned _Byte): g = _MemGet(m(0), o(0) + 2, _Unsigned _Byte): b = _MemGet(m(0), o(0) + 3, _Unsigned _Byte)
        _MemPut m(1), o(1), _RGB(r, g, b, temp) As _UNSIGNED _BYTE
        o(0) = o(0) + 4: o(1) = o(1) + 1
    Loop Until o(0) >= (m(0).OFFSET + m(0).SIZE)
    Grayscale256 = temp
    _MemFree m()
End Function

Function RedScale256 (image As Long)
    Dim As Long d, s, temp: d = _Dest: temp = Grayscale256(image)
    _Dest temp: For i = 0 To 255: _PaletteColor i, _RGB32(i, 0, 0): Next: _Dest d
    RedScale256 = temp
End Function

Function GreenScale256 (image As Long)
    Dim As Long d, s, temp: d = _Dest: temp = Grayscale256(image)
    _Dest temp: For i = 0 To 255: _PaletteColor i, _RGB32(0, i, 0): Next: _Dest d
    GreenScale256 = temp
End Function

Function BlueScale256 (image As Long)
    Dim As Long d, s, temp: d = _Dest: temp = Grayscale256(image)
    _Dest temp: For i = 0 To 255: _PaletteColor i, _RGB32(0, 0, i): Next: _Dest d
    BlueScale256 = temp
End Function

Print this item

  Bilateral Kaleidoscope
Posted by: bplus - 01-02-2023, 07:08 PM - Forum: Programs - Replies (4)

Looking at this: https://staging.qb64phoenix.com/showthread.php?tid=1306

I came up with this:

Code: (Select All)
_Title "Bilateral Kaleidoscope" ' 2023-01-02 NOT like May 2022 version by b+
Const sh = 600, sw = 800
Screen _NewImage(sw, sh, 32)
'_ScreenMove 200, 100
_FullScreen
Randomize Timer
Do
    If lc = 0 Then
        dx1 = 0: dx2 = 0: dy1 = 0: dy2 = 0: dr = 0: dg = 0: db = 0
        x1 = sw * Rnd: y1 = sh * Rnd: x2 = sw * Rnd: y2 = sh * Rnd: r = Rnd * 255: g = Rnd * 255: b = Rnd * 255
        While dx1 = 0: dx1 = Rnd * 6 - 3: Wend
        While dx2 = 0: dx2 = Rnd * 6 - 3: Wend
        While dy1 = 0: dy1 = Rnd * 6 - 3: Wend
        While dy2 = 0: dy2 = Rnd * 6 - 3: Wend
        While dr = 0: dr = Rnd * 4 - 2: Wend
        While dg = 0: dg = Rnd * 4 - 2: Wend
        While db = 0: db = Rnd * 4 - 2: Wend
    End If
    Line (x1, y1)-(x2, y2), _RGB32(r, g, b, 100)
    Line (sw - x1, y1)-(sw - x2, y2), _RGB32(r, g, b, 100)
    Line (x1, sh - y1)-(x2, sh - y2), _RGB32(r, g, b, 100)
    Line (sw - x1, sh - y1)-(sw - x2, sh - y2), _RGB32(r, g, b, 100)
    x1 = Remainder(x1 + dx1, sw)
    x2 = Remainder(x2 + dx2, sw)
    y1 = Remainder(y1 + dy1, sh)
    y2 = Remainder(y2 + dy2, sh)
    r = Remainder(r + dr, 255)
    g = Remainder(g + dr, 255)
    b = Remainder(b + db, 255)
    lc = lc + 1
    If ((Rnd > .999) And (lc > 300)) Or (lc > 4000) Then Sleep 1: Cls: lc = 0
    _Limit 60
Loop Until _KeyDown(27)

Function Remainder (n, d)
    If d = 0 Then Exit Function
    Remainder = n - (d) * Int(n / (d))
End Function

Print this item

  Like gliding over a sparkling ocean
Posted by: CharlieJV - 01-02-2023, 06:44 PM - Forum: QBJS, BAM, and Other BASICs - Replies (3)

https://basicanywheremachine.neocities.o...ling_ocean

Print this item

  DAY 044: RESET
Posted by: SMcNeill - 01-02-2023, 03:21 PM - Forum: Keyword of the Day! - Replies (3)

How many of you guys know this word even exists in our language?  The command is RESET, but how many remember exactly WHAT it resets?  Or what it's for?

This is one of those very important old keywords, that has basically became lost to time.

Keyword: RESET

Wiki page: https://qb64phoenix.com/qb64wiki/index.php/RESET

What's this do:  It basically works as a superpowered CLOSE statement.  Back in the day, when folks used floppy disks and such, it was necessary to use RESET to write your current directory info to the drive track.  Before you ever exited a program, and pulled your floppy out of the drive, you'd issue a RESET command to close all files and update all drive information to the floppy.

Nowadays?  Who owns a floppy drive?  Would a modern OS even require this type of command to update that information, IF you happened to have a floppy drive connected??  I dunno!!

All this command does for us now, is basically just work as a CLOSE statement to close all files.  It's unused.  Obsoleted.  Forgotten...

...Maybe I should've saved this keyword for Memorial Day.   

RIP poor RESET.

Print this item