|
Post by qbasicdude on Dec 17, 2022 4:18:50 GMT
Has anyone tried ChatGPT for generating qbasic code? It does a pretty great job! Here's a program I asked it to write, I wanted to compare it to a version I wrote myself. It's first try was nearly identical to what I wrote! I asked it a couple times to try again or make changes, and it kept updating the code as I asked. No idea if this code actually works, I haven't tested it. 100% AI-generated.
Instructions: write a qbasic program that plots a sine wave and exports g-code based on height, distance between waves, and total number of wave variables. It should also draw the shape in screen 12 to a scale automatically determined by available screen space.
Response:
' Program to plot a sine wave and export G-Code
' Declare variables DIM height AS SINGLE ' Height of sine wave DIM distance AS SINGLE ' Distance between waves DIM numWaves AS INTEGER ' Number of waves DIM maxX AS INTEGER ' Maximum x value (used for scaling) DIM maxY AS INTEGER ' Maximum y value (used for scaling) DIM scale AS SINGLE ' Scale factor for x and y axes
' Prompt user for input PRINT "Enter the height of the sine wave: "; INPUT height PRINT "Enter the distance between waves: "; INPUT distance PRINT "Enter the total number of waves: "; INPUT numWaves
' Calculate maximum x and y values maxX = numWaves * distance maxY = height
' Set screen mode to SCREEN 12 (graphics mode) SCREEN 12
' Set scale factor based on screen size scale = SCREENWIDTH / maxX
' Open output file for writing OPEN "output.gcode" FOR OUTPUT AS #1
' Loop through each wave and plot the sine function FOR wave = 1 TO numWaves FOR angle = 0 TO 360 STEP 1 x = wave * distance + distance * SIN(angle) y = height * SIN(angle) ' Plot line on screen LINE (x * scale, y * scale)-(x * scale, y * scale), 15 ' Write G-Code command to output file PRINT #1, "G1 X" & x & " Y" & y NEXT angle PRINT #1, "G1 Y0" ' Move back to starting position NEXT wave
' Close output file CLOSE #1
PRINT "G-Code generated successfully and saved to 'output.gcode'!"
' Wait for user to press a key before exiting SLEEP END
|
|
|
Post by qbasicdude on Dec 17, 2022 4:20:27 GMT
Not going to make up for a lack of programming knowledge, but I can see this generating some very useful chunks of code!
|
|
dualbrain
Junior Member
The only bug free code is code that is no longer used.
Posts: 51
|
Post by dualbrain on Dec 23, 2022 19:26:58 GMT
I've been playing with ChatGPT and I'll share that it does seem to do a good job of "faking it until you make it"; but with that said the results are pretty lacking in my experience thus far. Don't get me wrong, it certainly provides some possible hints and the fact that you can converse with it where it takes the whole of the conversation into consideration... the generated code leaves a lot to be desired. It's possible that my questions are more of the *advanced* in nature... but I have yet to get it give me any code that can simply be used as is (or, for that matter, compile). Will this improve? Maybe. Is it useful... absolutely! If nothing else, it's been valuable in my early experimentation in providing some **hints** of where to go investigate further.
For some real fun... ask it to convert a chunk of ASM code to QB64. ;-)
|
|
sera
New Member
Posts: 1
|
Post by sera on May 29, 2023 14:36:03 GMT
Mobile app development solutions are designed to help organizations create mobile apps that are tailored to their specific needs. Solutions typically include software development kits (SDKs) that enable organizations to quickly build and deploy mobile apps for multiple platforms. They also include cloud-based tools that allow teams to collaborate on app development projects. Additionally, mobile app development solutions may include analytics tools to help organizations gain insights into user behavior and improve their mobile apps.
|
|
|
Post by bplus on May 29, 2023 21:27:27 GMT
Here's my fix:
_Title "b+ once again tries to fix a ChatGPT" ' Dear ChatGPT it's just a sin wave scaleed to screen in the display ' God only knows what a G-Code file is but I can guess from what was ' being output?
' qbasicdude it doesn't work and takes a fair amount of fixing
' Program to plot a sine wave and export G-Code
' Declare variables Dim height As Single ' Height of sine wave Dim distance As Single ' Distance between waves Dim numWaves As Integer ' Number of waves Dim maxX As Integer ' Maximum x value (used for scaling) Dim maxY As Integer ' Maximum y value (used for scaling) Dim xscale As Single ' Scale factor for x and y axes Dim yscale As Single ' need 2 scales to fit inside screen and fill most of the screen
' Prompt user for input Print "Enter the height of the sine wave: "; Input height 'height = 100 'while fixing lets not answer over and over Print "Enter the distance between waves: "; Input distance 'distance = 200 'while fixing lets not answer over and over Print "Enter the total number of waves: "; Input numWaves 'numWaves = 3 'while fixing lets not answer over and over
' Calculate maximum x and y values b+ over sizes the screen to put graph inside it maxX = numWaves * distance + 4 ' plus some to draw inside screen maxY = 2 * height + 4
' Set screen mode to SCREEN 12 (graphics mode) Screen 12
' Set scale factor based on screen size xscale = _Width / maxX yscale = _Height / maxY
' Open output file for writing Open "output.gcode" For Output As #1
' screen orientation Line (x * xscale + 1, 0)-(x * xscale + 1, _Height), 15 ' mark start wave Line (0, height * yscale + 3)-(_Width, height * yscale + 3), 15 ' mark x axis
' Loop through each wave and plot the sine function For wave = 1 To numWaves Print #1, "" Print #1, "G1 Wave:"; wave ' label wave number and repeat wave times Print #1, "G1 Y0"; height ' Move back to starting position For angle = 0 To 360 Step 1
' calc: consider each angle a step of 1 across x axis 360 steps per wave with distance = distance x = (wave - 1) * distance + angle / 360 * distance ' so x = completed waves * distance + angle * scaling of distance or (angle/360) * distance
y = height + height * Sin(_D2R(angle)) ' sin function needs radian units ChatGPT always misses this! ' so y = midscreen +/- some fraction of height according to sin of angle
' Plot line on screen need the scale factors here Circle (x * xscale + 1, y * yscale + 3), 1, 15 ' +1 +3 again to keep entire graph on screen
' Write G-Code command to output file Print #1, "G1 X"; x; " Y"; y Next angle Line (x * xscale, 0)-(x * xscale + 1, _Height), 15, BF ' mark the end of another period or wave Next wave
' Close output file Close #1 Locate 14, 10: Print "G-Code generated successfully and saved to 'output.gcode'! zzz..." ' < zzz... sleeping
' Wait for user to press a key before exiting Sleep End
|
|
|
Post by bplus on May 30, 2023 0:24:25 GMT
Oh G Code is for running machines, like telling them where to go, OK then probably didn't need my wave number label. Do they take commented lines?
|
|
|
Post by marjagonzalves on Sept 5, 2023 23:32:00 GMT
s://linux.org/threads/qb64-programming.44900/ (I am new, I don't know if I'm allowed to post straight Internet link.)
Ask chat to produce code to load font or image or music file. Maybe have to say "on Linux" so it doesn't give Windows path.
I wanted that topic to go on much longer.
|
|