1. ChatGPT & Euphoria
- Posted by Icy_Viking 2 weeks ago
- 419 views
Hi all, So I got bored and decided how ChatGPT would react to the question "Shoot a bullet in Euphoria programming language". Here is what it gave me.
-- Bullet class structure (using a sequence) sequence bullet = {0, 0, 5, 0} -- {x, y, speed, direction} -- Update function to move the bullet procedure update_bullet(sequence b) b[1] = b[1] + b[3] * cos(b[4]) -- x = x + speed * cos(direction) b[2] = b[2] + b[3] * sin(b[4]) -- y = y + speed * sin(direction) end procedure procedure shoot_bullet(sequence bullet) bullet[1] = 0 -- Start x position bullet[2] = 0 -- Start y position bullet[3] = 10 -- Bullet speed bullet[4] = 0 -- Direction in radians (0 = moving to the right) end procedure -- This procedure could be called in a loop to continuously update the bullet position update_bullet(bullet) -- A simple game loop while 1 do -- Check for user input (e.g., space bar to shoot) if keypressed() = ' ' then shoot_bullet(bullet) end if -- Update bullet's position update_bullet(bullet) -- If the bullet has gone off-screen, reset it if bullet[1] > screen_width then bullet = {0, 0, 5, 0} -- Reset bullet end if -- Draw the bullet (or just print for now) puts(1, "Bullet position: " & bullet[1] & ", " & bullet[2] & "\n") -- You would use your graphics library here for rendering the bullet on screen. -- Pause briefly to control game speed sleep(0.016) -- 60 frames per second end while
Also, it included a way to do it with Euphoria-GL, lol
include graphics.e -- Initialize window window_width = 800 window_height = 600 open_window(window_width, window_height, "Bullet Simulation") -- Main game loop while 1 do -- Clear screen and redraw the background clear_screen() -- Update bullet's position update_bullet(bullet) -- Draw the bullet (use a circle or small rectangle) draw_circle(bullet[1], bullet[2], 5) -- Show the updated screen update_screen() -- Check for key press if keypressed() = ' ' then shoot_bullet(bullet) end if -- Sleep briefly to control game speed sleep(0.016) end while
Collision test
-- Example target (a rectangle) sequence target = {400, 300, 50, 50} -- {x, y, width, height} -- Collision detection (bullet with target) if bullet[1] >= target[1] and bullet[1] <= target[1] + target[3] and bullet[2] >= target[2] and bullet[2] <= target[2] + target[4] then -- Bullet hit the target puts(1, "Bullet hit the target!\n") bullet = {0, 0, 5, 0} -- Reset bullet end if
I'm surprised how thorough the example was. With Euphoria being such a fringe language these days, I'm surprised.
2. Re: ChatGPT & Euphoria
- Posted by ChrisB (moderator) 2 weeks ago
- 410 views
Me too, when I tried it a while ago.
Have you rune these - did you have to tweak?
Cheer
Chris
3. Re: ChatGPT & Euphoria
- Posted by Icy_Viking 2 weeks ago
- 389 views
Me too, when I tried it a while ago.
Have you rune these - did you have to tweak?
Cheer
Chris
I haven't used it yet, I was curious if ChatGPT had knowledge of Euphoria as a programming language. I did ask it for some C code that I had to play around with to make it work. ChatGPT can point you in the right direction and give you a good idea of where to start, but you'll still have to fine tune or change some things to get it to work.
4. Re: ChatGPT & Euphoria
- Posted by xecronix 2 weeks ago
- 382 views
I've been working with ChatGPT using Euphoria every day for a few weeks. Seems to be getting better and better at it. ChatGPT knows Phix too.
5. Re: ChatGPT & Euphoria
- Posted by petelomax 2 weeks ago
- 380 views
I've used AI chat to generate Phix code too. When (as usual) it don't quite work, I fix it and always make sure to tell it back: I fixed that for you: <paste>. It's the only way it'll learn.
6. Re: ChatGPT & Euphoria
- Posted by irv 6 days ago
- 272 views
- Last edited 5 days ago
write a function to break a string up into words, each word in quotes, separated by commas, and add comments
-- This function takes a string, splits it into words, -- surrounds each word with double quotes, and joins them with commas. function quote_and_comma_words(sequence input) sequence result = "" -- Final result string sequence word = "" -- Temporary storage for building each word integer first = 1 -- Flag to handle whether to prepend a comma -- Loop through each character in the input for i = 1 to length(input) do integer ch = input[i] if ch = ' ' then -- We've hit a space; if we have a word built, add it to result if length(word) > 0 then if not first then result &= "," -- Add comma before next word (not the first) else first = 0 -- Mark that the first word is done end if result &= "\"" & word & "\"" -- Add quoted word word = "" -- Reset word builder end if else -- Add character to current word word &= ch end if end for -- Handle the last word (if there is one) if length(word) > 0 then if not first then result &= "," end if result &= "\"" & word & "\"" end if return result end function puts(1,quote_and_comma_words("Now is the time for all good men")) puts(1,'\n')
irv@irv-desktop:~$ eui quotem.ex "Now","is","the","time","for","all","good","men"
This isn't bad for writing small functions. Also works for reformatting code to look neater, and adds reasonable comments.
7. Re: ChatGPT & Euphoria
- Posted by irv 4 days ago
- 197 views
ChatGPT is helping me write a new GTK4 "wrapper". Most of the widgets are working. Here's an example, formatted and commented by ChatGPT:
/* 💡 What This Program Does: Loads a GTK CSS stylesheet for styling widgets. Creates a window with: ⏺ A bold-label "Hello World!" ⏺ An image (apple-red.png) ⏺ Two buttons: Exit (left) and OK (right) Uses ActionBar, Box, Label, Button, Picture, and GTK CSS theming. */ -- Include necessary modules include gtk4.e include action_bar.e -- Path to the CSS file used for styling constant css_file = locate_file("gtk.css") -- Create a new GTK application instance object app = Application:new("org.gtk.example") ------------------------------------------------------------- function interface(object app, object data) -- Callback function called when the GTK application starts -- Sets up the interface and UI components ------------------------------------------------------------- -- Create a new CSS provider and load the CSS file object css = CssProvider:new() set(css, "load from path", css_file) set(css, "add provider") -- Attach CSS to the style context -- Create the main application window object window = ApplicationWindow:new(app) set(window, "name", "Main") set(window, "title", "Main Window") set(window, "default size", 300, 100) set(window, "present") -- Make the window visible -- Create a vertical box container for layout object panel = Box:new(1, 10) -- Orientation: vertical (1), spacing: 10 set(panel, "name", "Main") set(window, "child", panel) -- Create a label with styled text object lbl = Label:new() set(lbl, "name", "L1") set(lbl, "tooltip text", "Label with markup") set(lbl, "markup", "<b>Hello World!</b>") -- Bold markup set(panel, "append", lbl) -- First horizontal box for row of widgets object bx1 = Box:new(1, 5) -- Horizontal (1), spacing: 5 set(panel, "append", bx1) -- Add an image to the first row object img = Picture:new(locate_file("apple-red.png")) set(img, "size request", 50, 50) -- Fixed size for the image set(bx1, "append", img) -- Second row: use a CenterBox for better layout control object btnbox2 = CenterBox:new() set(panel, "append", btnbox2) -- Add a GTK ActionBar at the bottom object ab = ActionBar:new() set(panel, "append", ab) -- Exit button on the left of the ActionBar object btn1 = Button:new("E_xit") set(btn1, "name", "styled") set(ab, "pack start", btn1) connect(btn1, "clicked", "quit", app) -- Quit app on click -- OK button on the right of the ActionBar object btn3 = Button:new("_OK") set(btn3, "name", "styled") set(window, "default widget", btn3) -- Triggered by Enter key set(ab, "pack end", btn3) -- Uncomment this to enable GTK interactive debugging -- interactive_debugging(1) return 1 -- Return success end function -- Register the interface function as a callback for app activation constant init = call_back(routine_id("interface")) ------------------------------------------------------------- -- Entry point: connects app activation to interface callback -- and starts the GTK application event loop function main() connect(app, "activate", init, 0) return Application:run(app) end function -- Run the program main()
8. Re: ChatGPT & Euphoria
- Posted by irv 4 days ago
- 197 views
And here is the complete code to implement a gtk4 picture widget. Each widget takes similar code to implement, except for the listviews. The main "wrapper" for gtk4 is only about 750 lines so far. Big improvement over the more than 10,000 in the previous EuGTK. Comments and formatting by ChatGPT:
-------------------------------------- namespace Picture -------------------------------------- /* 💡 What This Module Does: This code binds the GTK4 GtkPicture widget to Euphoria by defining the function names and their signatures in the widget[Picture] structure. It lists all the common GTK methods you can call on a GtkPicture widget getters, setters, and constructors. The new function is a convenience function that creates a new GtkPicture widget from a given filename string. ⏺ It dynamically looks up the GTK C function gtk_picture_new_for_filename. ⏺ It converts the Euphoria string to a C-compatible string using allocate_string. ⏺ Calls the GTK function and gets back a widget handle. ⏺ Calls init to initialize internal widget state. ⏺ Registers the widget in the Euphoria GTK registry, returning a usable handle. This enables you to easily create and manipulate image widgets in your GTK application with Euphoria by just calling Picture:new("image.png"). */ -- Include GTK base definitions and types include gtk4.e -- Define the Picture widget metadata widget[Picture] = { "gtk_picture_", -- GTK function prefix for Picture widget {Widget}, -- Inherits from base Widget -- List of GTK Picture methods with their parameter and return types: {"get_alternative_text", {P}, S}, -- Get alternative text (string) {"get_can_shrink", {P}, B}, -- Get whether image can shrink (boolean) {"get_content_fit", {P}, B}, -- Get content fit property (boolean) {"get_file", {P}, S}, -- Get filename or URI (string) {"get_keep_aspect_ratio", {P}, B}, -- Get whether aspect ratio is kept (boolean) {"get_paintable", {P}, B}, -- Get paintable state (boolean) -- Constructors for different ways to create a Picture: {"new_for_file", {P, S}}, -- Create from file (pointer, string) {"new_for_filename", {P, S}}, -- Create from filename (pointer, string) {"new_for_paintable", {P, P}}, -- Create from paintable object {"new_for_pixbuf", {P, P}}, -- Create from GdkPixbuf object {"new_for_resource", {P, S}}, -- Create from resource path -- Setters for various properties: {"set_alternative_text", {P, S}}, {"set_can_shrink", {P, B}}, {"set_content_fit", {P, B}}, {"set_file", {P, S}}, {"set_filename", {P, S}}, {"set_keep_aspect_ratio", {P, B}}, {"set_paintable", {P, B}}, {"set_pixbuf", {P, P}}, {"set_resource", {P, S}}, "GtkPicture" -- GTK type name for the widget } object self = widget[Picture]-- Reference to the Picture widget metadata ------------------------------------------------------ export function new(object f) ------------------------------------------------------ -- Exported function to create a new Picture widget -- from a filename (string f) -- Define the C function pointer for gtk_picture_new_for_filename atom fn = define_c_func(LIB, self[1] & "new_for_filename", {P}, P) -- Allocate the filename string as a C string and call GTK to create the Picture widget atom handle = c_func(fn, {allocate_string(f)}) -- Initialize Picture widget in registry (sets up properties, etc.) init(Picture) -- Register and return the widget handle return register(Picture, handle) end function
Here's a screenshot: https://photos.app.goo.gl/Yo3RjS2aGqED3B5JA
9. Re: ChatGPT & Euphoria
- Posted by petelomax 4 days ago
- 187 views
ChatGPT is helping me write a new GTK4 "wrapper".
Not the end of the world, perhaps, but one thing I noted is that due to that application/"activate" nonsense, gtk4 completely prevents eg:
constant {sw,sh} = get_global("SCREENSIZE")
I suspect it'll be a dead duck if it don't run on android, if it does I might be interested...
10. Re: ChatGPT & Euphoria
- Posted by irv 4 days ago
- 187 views
Oh, it will be a dead duck anyway. Just something to occupy my time. There are lots of problems with GTK4, they have made some things needlessly complicated. Besides, the very last thing we need is Yet Another Phone App.
11. Re: ChatGPT & Euphoria
- Posted by Icy_Viking 4 days ago
- 181 views
Oh, it will be a dead duck anyway. Just something to occupy my time. There are lots of problems with GTK4, they have made some things needlessly complicated. Besides, the very last thing we need is Yet Another Phone App.
Regardless if its a dead duck or not. That is pretty cool you can use chatGPT to help make a wrapper. I'll think about this next time I start work on a wrapper. Also, GTK4 looks like a mess compared to GTK3. Having a GUI made in and for Euphoria would probably be a better option.
12. Re: ChatGPT & Euphoria
- Posted by irv 4 days ago
- 176 views
Regardless if its a dead duck or not. That is pretty cool you can use chatGPT to help make a wrapper. I'll think about this next time I start work on a wrapper. Also, GTK4 looks like a mess compared to GTK3. Having a GUI made in and for Euphoria would probably be a better option.
I don't think that is practical. Way slow, for one thing.
13. Re: ChatGPT & Euphoria
- Posted by petelomax 4 days ago
- 167 views
- Last edited 3 days ago
Having a GUI made in and for Euphoria would probably be a better option.
I don't think that is practical. Way slow, for one thing.
Erm, unless you are talking about the sort of complex 2D/3D drawing on a single canvas you'd typically find in a game, that's simply not so. Over the past year or so I've taken it on myself to (successfully) implement scrollbars, buttons, [graphs, same code as of old,] lists, tables, tabs, textfields, and trees in pure hll Phix code, all on top of a plain canvas which (often) draws things pixel-by-pixel (esp on WinAPI, since the now-ancient GDI is rubbish at anti-aliasing), and pretty much the very last thing you'd notice is performance issues. While not exactly trivial, the code has (so far) turned out far more elegant than expected. I'm planning on (slowly) continuing that effort for checkboxes, datepicks, dropdowns, frames, labels, progressbars, radios, sliders, spincontrols, and splitters, so it's not likely to get shipped any time soon.
It is a bit Windows 10/11 look-and-feel biased, but the buttons at least can perfectly replicate GTK2 and GTK3 as well, which proved more slightly fiddly than actually difficult.
I'm also currently in a bit of a quandary whether to completely abandon WinAPI/GTK/HTML layout management and do my own, or try and progress such things in parallel.
14. Re: ChatGPT & Euphoria
- Posted by petelomax 3 days ago
- 141 views
Besides, the very last thing we need is Yet Another Phone App.
I think I somewhat strongly disagree there: we would all benefit from a few more actually useful phone apps, but yeah, not yet more games.
One simple idea is a loyalty card/train ticket app, not much more than a simple custom/customisable image viewer, that makes it fast and easy to pull up all those qr codes / barcodes up on my screen, without wading through special offers and completely different navigation methods of all the individual apps - the morrisons more card app deserves a special mention for the clever way it shows your more card, then always covers it with a popup when you turn your phone round to scan it. Another, I forget which, likes to show a non-scannable version of your card, that when tapped on shows an ever-so-slightly bigger version that does scan..