ChatGPT et la programmation Amiga

11 sujets de 1 à 11 (sur un total de 11)

  • Jul

      #380289

      Par curiosité, j’ai demandé à ChatGPT de créer un visualiseur d’ensemble de Mandelbrot en C pour Amiga, en utilisant MUI pour l’interface. Après quelques allers-retours il s’en est fort bien tiré !

      Voici le code C généré (à compiler avec VBCC) :

      #include <exec/types.h>
      #include <intuition/intuition.h>
      #include <libraries/mui.h>
      #include <graphics/gfxbase.h>
      #include <graphics/gfxmacros.h>
      #include <graphics/view.h>
      #include <graphics/gfx.h>
      #include <clib/muimaster_protos.h>
      #include <clib/exec_protos.h>
      #include <clib/graphics_protos.h>
      #include <stdlib.h>
      #include <stdio.h>
      #include <math.h>
      
      // Ajout de la déclaration explicite de DoMethod
      #ifndef __AROS__
      ULONG DoMethod(APTR obj, ULONG methodID, ...);
      #endif
      
      struct Library *MUIMasterBase;
      struct GfxBase *GfxBase;
      
      #define MAX_ITER 1000
      
      #ifndef MAKE_ID
      #define MAKE_ID(a,b,c,d) ((ULONG)(a)<<24 | (ULONG)(b)<<16 | (ULONG)(c)<<8 | (ULONG)(d))
      #endif
      
      struct RastPort rastPort;
      struct BitMap *bitmap;
      
      void mandelbrot(Object *progressBar, struct Window *muiWindow, ULONG width, ULONG height) {
          float x0, y0, x, y, xtemp;
          int i, j, iteration;
          int color;
      
          float aspect_ratio = (float)width / height;
          float scale_x = 3.5; // Ajusté dynamiquement
          float scale_y = 2.0; // Ajusté dynamiquement
      
          // Ajustement de l'échelle pour remplir la zone d'affichage
          if (aspect_ratio > 1.75) {
              scale_y = scale_y * 1.75 / aspect_ratio;
          } else {
              scale_x = scale_x * aspect_ratio / 1.75;
          }
      
          float x_offset = -0.75; // Ajusté dynamiquement
          float y_offset = 0.0;   // Ajusté dynamiquement
      
          InitRastPort(&rastPort);
          rastPort.BitMap = bitmap;
      
          for (i = 0; i < height; i++) {
              for (j = 0; j < width; j++) {
                  x0 = ((float)j / width * scale_x - scale_x / 2.0) + x_offset;
                  y0 = ((float)i / height * scale_y - scale_y / 2.0) + y_offset;
                  x = 0.0;
                  y = 0.0;
                  iteration = 0;
      
                  while (x * x + y * y <= 4.0 && iteration < MAX_ITER) {
                      xtemp = x * x - y * y + x0;
                      y = 2.0 * x * y + y0;
                      x = xtemp;
                      iteration++;
                  }
      
                  color = iteration == MAX_ITER ? 0 : iteration * 255 / MAX_ITER;
                  SetAPen(&rastPort, color);
                  WritePixel(&rastPort, j, i);
              }
              set(progressBar, MUIA_Gauge_Current, (i + 1) * 100 / height);
              
              // Copie de la ligne calculée sur la surface d'affichage
              BltBitMapRastPort(bitmap, 0, i, muiWindow->RPort, 10, 50 + i, width, 1, 0xC0);
          }
      }
      
      int main(void) {
          Object *app, *window, *mainGroup;
          Object *mandelbrotButton, *progressBar, *display;
          struct Window *muiWindow;
          ULONG signals = 0;
          BOOL running = TRUE;
      
          MUIMasterBase = OpenLibrary("muimaster.library", 0);
          if (!MUIMasterBase) {
              return 20;
          }
      
          GfxBase = (struct GfxBase *)OpenLibrary("graphics.library", 0);
          if (!GfxBase) {
              CloseLibrary(MUIMasterBase);
              return 20;
          }
      
          bitmap = AllocBitMap(320, 240, 8, BMF_DISPLAYABLE | BMF_INTERLEAVED, NULL);
          if (!bitmap) {
              CloseLibrary((struct Library *)GfxBase);
              CloseLibrary(MUIMasterBase);
              return 20;
          }
      
          app = ApplicationObject,
              MUIA_Application_Title, "Mandelbrot Viewer",
              MUIA_Application_Version, "$VER: MandelbrotViewer 1.0",
              MUIA_Application_Copyright, "©2024 ChatGPT 4.0",
              MUIA_Application_Author, "ChatGPT 4.0",
              MUIA_Application_Description, "Mandelbrot Set Viewer",
              MUIA_Application_Base, "MANDELBROTVIEWER",
              SubWindow, window = WindowObject,
                  MUIA_Window_Title, "Mandelbrot Viewer",
                  MUIA_Window_ID, MAKE_ID('M','A','I','N'),
                  MUIA_Window_Width, 340,
                  MUIA_Window_Height, 340,
                  MUIA_Window_CloseGadget, TRUE,
                  MUIA_Window_DepthGadget, TRUE,
                  MUIA_Window_SizeGadget, TRUE,
                  MUIA_Window_DragBar, TRUE,
                  MUIA_Window_SizeRight, TRUE,
                  WindowContents, mainGroup = VGroup,
                      Child, mandelbrotButton = SimpleButton("Generate Mandelbrot"),
                      Child, display = RectangleObject,
                          MUIA_Background, MUII_BACKGROUND,
                          MUIA_Frame, MUIV_Frame_InputList,
                          MUIA_Weight, 100,
                          MUIA_ObjectID, MAKE_ID('D','I','S','P'),
                      End,
                      Child, progressBar = GaugeObject,
                          MUIA_Gauge_Horiz, TRUE,
                          MUIA_Gauge_InfoText, "%ld%%",
                          MUIA_Gauge_Max, 100,
                          MUIA_Gauge_Current, 0,
                          MUIA_Weight, 10,
                      End,
                  End,
              End,
          End;
      
          if (!app) {
              FreeBitMap(bitmap);
              CloseLibrary((struct Library *)GfxBase);
              CloseLibrary(MUIMasterBase);
              return 20;
          }
      
          DoMethod(window, MUIM_Notify, MUIA_Window_CloseRequest, TRUE, app, 2, MUIM_Application_ReturnID, MUIV_Application_ReturnID_Quit);
      
          set(window, MUIA_Window_Open, TRUE);
      
          GetAttr(MUIA_Window_Window, window, (ULONG *)&muiWindow);
      
          while (running) {
              ULONG result = DoMethod(app, MUIM_Application_NewInput, &signals);
              if (result == MUIV_Application_ReturnID_Quit) {
                  running = FALSE;
              }
              if (signals) {
                  signals = Wait(signals | SIGBREAKF_CTRL_C);
                  if (signals & SIGBREAKF_CTRL_C) break;
              }
      
              // Vérifier si le bouton mandelbrot a été sélectionné
              ULONG state;
              GetAttr(MUIA_Selected, mandelbrotButton, &state);
              if (state) {
                  set(mandelbrotButton, MUIA_Selected, FALSE);  // Réinitialiser l'état du bouton
      
                  ULONG displayWidth, displayHeight;
                  GetAttr(MUIA_Width, display, &displayWidth);
                  GetAttr(MUIA_Height, display, &displayHeight);
      
                  // Ajuster la taille du bitmap pour correspondre à la taille de la fenêtre
                  if (bitmap) {
                      FreeBitMap(bitmap);
                  }
                  bitmap = AllocBitMap(displayWidth - 32, displayHeight - 8, 8, BMF_DISPLAYABLE | BMF_INTERLEAVED, NULL);
      
                  // Calculer l'échelle et le décalage en fonction de la taille de la zone d'affichage
                  float aspect_ratio = (float)displayWidth / displayHeight;
                  float scale_x = 3.5; // Ajusté dynamiquement
                  float scale_y = 2.0; // Ajusté dynamiquement
      
                  if (aspect_ratio > 1.75) {
                      scale_y = scale_y * 1.75 / aspect_ratio;
                  } else {
                      scale_x = scale_x * aspect_ratio / 1.75;
                  }
      
                  float x_offset = -0.75; // Ajusté dynamiquement
                  float y_offset = 0.0;   // Ajusté dynamiquement
      
                  mandelbrot(progressBar, muiWindow, displayWidth - 32, displayHeight - 8);
              }
          }
      
          set(window, MUIA_Window_Open, FALSE);
          MUI_DisposeObject(app);
          FreeBitMap(bitmap);
          CloseLibrary((struct Library *)GfxBase);
          CloseLibrary(MUIMasterBase);
      
          return 0;
      }
      

      Et le résultat :

      Ce n’est pas parfait mais c’est amusant de voir qu’il ne se débrouille pas si mal sur notre machine. Je n’ai rien retouché au code.

      Prédateur Chess | Amiga 500 + ACA500 | Amiga 1200 + ACA1233

      stephbb75

        #380293

        Salut,

        Oui cela semble bien.
        J’avais testé au début, c’était une catastrophe 🤣

        Faudrait que je re teste pour voir mais la pas le temps…

        https://youtube.com/@stephbb75

        Alok Sharma

          #380306

          Excellent content ,Thanks for sharing this. It’s pretty nice and very helpful contents in this article, everyone can use it wisely. Visit for: top payroll software

          top payroll software

          kamelito

            #380325

            Il existe une version de ChatGPT qui a été « entraînée » avec de la doc Amiga.

            __sam__

              #380330

              Le code C de la boucle de mandelbro pourrait être largement optimisé.

              Samuel.

              Amiga A500 + GVP530 (8Mo/fpu/mmu/scsi) - en panne 🙁
              A500 (+ 1Mo PPS), A1200 (Blizzard-IV/fpu/64Mo)
              A500 Vampire V2+ ^8^ 🙂
              (mais aussi TO8, TO8D, TO9. Groupe PULS.)

              abzalon2436

                #380333

                Vraiment impressionant ce que chatgpt arrive a sortir …
                Je testerai bien ca pour voir, mais ou trouver le sdk de mui ?

                Jul

                  #380342

                  Il existe une version de ChatGPT qui a été « entraînée » avec de la doc Amiga.

                  Je l’ai essayé : il s’interrompt en pleine génération de code. J’ai moi-même créé un GPT de traduction qui souffre des mêmes problèmes (traductions incomplètes). Cela dit, je voulais vraiment tester le GPT “vanilla”, en l’occurence ChatGPT 4o.

                  Le code C de la boucle de mandelbro pourrait être largement optimisé.

                  Oui, ce code est très lent. J’ai moi-même écrit des générateurs Mendelbrot beaucoup plus rapides. Mais, comme dit plus haut, pour cette expérience je n’ai pas interféré avec le code produit par ChatGPT. Au reste, je pourrais lui dire d’améliorer ce code. 🙂

                  Vraiment impressionant ce que chatgpt arrive a sortir …
                  Je testerai bien ca pour voir, mais ou trouver le sdk de mui ?

                  Les includes de MUI sont sur Aminet : https://aminet.net/package/dev/mui/mui38dev.

                  Prédateur Chess | Amiga 500 + ACA500 | Amiga 1200 + ACA1233

                  abzalon2436

                    #380357

                    Les includes de MUI sont sur Aminet : https://aminet.net/package/dev/mui/mui38dev.

                    Merci 🙂
                    J’avais regardé sur aminet mais pas trouvé, je dois avoir taper les mauvais mots clés ! C’est vraique quand on tape mui dans la recherche on a des milliers de résultats …
                    Il fallait tout simplement regarder par autre alphabétique sur le nom du package …

                    abzalon2436

                      #380358

                      Nickel ca compile, premiere fois que je compile du C sur Amiga !
                      A l’époque je faisais que de l’assembleur. Par contre le C me rappelle le boulot mais on peut pas tout avoir ! 🙂

                      piark

                        #380439

                        Question, vous utilisez quoi pour compiler du C sur Amiga ?

                        Jul

                          #380440

                          Question, vous utilisez quoi pour compiler du C sur Amiga ?

                          J’utilise CubicIDE avec VBCC :

                          Il ne coûte plus que 20€. Attention, par contre, de remplir les critères de compatibilité. En particulier, je ne crois pas qu’il soit installable sur une partition FFS, car il y a trop de sous-répertoires et les chemins deviennent trop longs. Ma partition Work est en PFS.

                          Prédateur Chess | Amiga 500 + ACA500 | Amiga 1200 + ACA1233

                        11 sujets de 1 à 11 (sur un total de 11)

                        • Vous devez être connecté pour répondre à ce sujet.

                        Forums AmigaOS, MorphOS et AROS Développement ChatGPT et la programmation Amiga

                        Amiga Impact