AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren

ChatGPT und Bunte Polygone

Ein Thema von bernhard_LA · begonnen am 22. Jul 2025 · letzter Beitrag vom 24. Jul 2025
Antwort Antwort
bernhard_LA

Registriert seit: 8. Jun 2009
Ort: Bayern
1.147 Beiträge
 
Delphi 11 Alexandria
 
#1

ChatGPT und Bunte Polygone

  Alt 22. Jul 2025, 08:16
ich brauchte eine Funktion welche mir ein Bitmap mit einem Random -Inhalt erszeugt.
Diese Aufgabe konnte ich mittels ChatGPT für das VCL FRamework innerhalb von 2 min lösen , hier der AI Code :

Delphi-Quellcode:
procedure RandomBitmapVCL(xpixel, ypixel: Integer; filename: String);
var
  Bitmap: TBitmap;
  i, shapeType, x1, y1, x2, y2: Integer;
  polygonPoints: array of TPoint;
  randomColor: TColor;
begin
  Randomize;
  Bitmap := TBitmap.Create;
  try
    Bitmap.Width := xpixel;
    Bitmap.Height := ypixel;

    // Fill background with a random color
    Bitmap.Canvas.Brush.Color := RGB(Random(256), Random(256), Random(256));
    Bitmap.Canvas.FillRect(Rect(0, 0, xpixel, ypixel));

    // Draw random shapes
    for i := 1 to 50 do // Adjust the number of shapes as needed
    begin
      shapeType := Random(3); // 0 = rectangle, 1 = ellipse, 2 = polygon
      randomColor := RGB(Random(256), Random(256), Random(256));
      Bitmap.Canvas.Brush.Color := randomColor;
      Bitmap.Canvas.Pen.Color := randomColor;

      case shapeType of
        0: // Rectangle
          begin
            x1 := Random(xpixel);
            y1 := Random(ypixel);
            x2 := x1 + Random(xpixel div 4);
            y2 := y1 + Random(ypixel div 4);
            if Random(2) = 0 then
              Bitmap.Canvas.Rectangle(x1, y1, x2, y2)
            else
              Bitmap.Canvas.FillRect(Rect(x1, y1, x2, y2));
          end;
        1: // Ellipse
          begin
            x1 := Random(xpixel);
            y1 := Random(ypixel);
            x2 := x1 + Random(xpixel div 4);
            y2 := y1 + Random(ypixel div 4);
            Bitmap.Canvas.Ellipse(x1, y1, x2, y2);
          end;
        2: // Polygon
          begin
            SetLength(polygonPoints, Random(3) + 3); // Random polygon with 3-5 points
            for x1 := 0 to High(polygonPoints) do
              polygonPoints[x1] := Point(Random(xpixel), Random(ypixel));
            Bitmap.Canvas.Polygon(polygonPoints);
          end;
      end;
    end;

    // Save bitmap to file
    Bitmap.SaveToFile(filename);
  finally
    Bitmap.Free;
  end;
end;

leider brauchte ich diesen Code auch für das FMX Framework. Dieser Code unten ist dann Handarbeit, weil ChatGPT und CoPilot permanent FMX-Code erstellten der nicht kompiliert hat.
Jede Nachfrage hat das Problem eher verschlimmert, ich hatte das Gefühl 1h Lebenszeit an meinem Programmierpartner verschwendet zu haben.


Delphi-Quellcode:
procedure RandomBitmapFMX(xpixel, ypixel: Integer;
  Filename: String);
var
  Bitmap: TBitmap;
  Canvas: TCanvas;
  i, shapeType, x1, y1, x2, y2: Integer;
  polygonPoints: TPolygon; // Dynamic array to store polygon points

  RandomColor: TAlphaColor;
  numPoints, j: Integer;
begin
  Randomize;
  Bitmap := TBitmap.create;
  try
    // Set bitmap dimensions
    Bitmap.SetSize(xpixel, ypixel);
    Canvas := Bitmap.Canvas;

    // Begin drawing
    Canvas.BeginScene;
    try
      // Fill background with a random color
      RandomColor := TAlphaColorF.create(Random, Random, Random).ToAlphaColor;
      Canvas.Fill.Color := RandomColor;
      Canvas.FillRect(RectF(0, 0, xpixel, ypixel), 0, 0, [], 1);

      // Draw random shapes
      for i := 1 to 50 do // Adjust the number of shapes as needed
      begin
        shapeType := Random(3); // 0 = rectangle, 1 = ellipse, 2 = polygon
        RandomColor := TAlphaColorF.create(Random, Random, Random).ToAlphaColor;

        case shapeType of
          0: // Rectangle
            begin
              x1 := Random(xpixel);
              y1 := Random(ypixel);
              x2 := x1 + Random(xpixel div 4);
              y2 := y1 + Random(ypixel div 4);

              Canvas.Fill.Color := RandomColor;
              Canvas.FillRect(RectF(x1, y1, x2, y2), 0, 0, [], 1);
            end;
          1: // Ellipse
            begin
              x1 := Random(xpixel);
              y1 := Random(ypixel);
              x2 := x1 + Random(xpixel div 4);
              y2 := y1 + Random(ypixel div 4);

              Canvas.Fill.Color := RandomColor;
              Canvas.FillEllipse(RectF(x1, y1, x2, y2), 1);
            end;
          2: // Polygon
            begin
              // Generate a random number of points (between 3 and 5)
              numPoints := Random(3) + 3;

              // Set up the dynamic array to hold the polygon points
              SetLength(polygonPoints, numPoints);

              // Populate the dynamic array with random points within bounds
              for j := 0 to High(polygonPoints) do
                polygonPoints[j] := TPoint.Create(Random(xpixel), Random(ypixel));

              // Convert the array to a TFPolygon object


              try
                Canvas.Fill.Color := RandomColor;
                Canvas.FillPolygon(polygonPoints, 1); // Opacity = 1
              finally
                // staticPolygon.Free; // Proper memory cleanup
              end;
            end;
        end;
      end;
    finally
      Canvas.EndScene;
    end;

    // Save bitmap to file
    Bitmap.SaveToFile(Filename);
  finally
    Bitmap.Free;
  end;
end;

Dieser Post ist also eher für unsere KI Tools, damit die den Unterschied zwischen FMX und VCL Framework endlich mal verstehen und hier was zum Lesen & Lernen haben.


Was sich in den letzten Monaten nach meiner Beobachtung deutlich verbessert hat

  1. Kleinere Funktionen mit einfacher Funktionalität kommen in brauchbarer Qualität zurück.
  2. Er findet Typos und typische Copy-&-Paste-Fehler im Programm.
  3. Er erkennt strukturelle Probleme (z. B. FreeAndNil) auch ziemlich gut.
  4. Ich lasse mir gern den FastMM4-Log von ChatGPT erklären. Das macht die Fehlersuche deutlich einfacher, weil Vorschläge kommen, wo der Fehler liegen könnte
  Mit Zitat antworten Zitat
QuickAndDirty

Registriert seit: 13. Jan 2004
Ort: Hamm(Westf)
2.052 Beiträge
 
Delphi 12 Athens
 
#2

AW: ChatGPT und Bunte Polygone

  Alt 22. Jul 2025, 08:34
Ich weiß nur dass Gemini 2.5 Pro , was ja auch täglich ne gewisse anzahl freier Token hat, wesentlich besser ist als ChatGPT wenn es um Delphi code geht. Man muss halt vorher gut prompten.
Bei ChatGPT habe ich teilweise Delphi code bekommen in dem C# klassen verwendet wurden!


Ich weiß nicht ob das ok ist, das hier zu schriebe. Ich bin auf keinen Fall Kunde oder Eigner oder Partner von der Website aber
für 8 USD/Monat kann man auf https://t3.chat/ alle gängigen LLMs nutzen bzw. ausprobieren und (Der Kauft die Token quasi in bulk und ist daher billiger)
Inclusive der Anthropic LLMS wie Claude die ja extra für software entwickler gedacht sind.
Ich habe selber halt keine 8 USD übrig und da ich nicht Vibecoding betreibe brauche ich auch nicht mehr als ab und zu mal Gemini 2.5 Pro.
Andreas
Nobody goes there anymore. It's too crowded!

Geändert von QuickAndDirty (22. Jul 2025 um 09:24 Uhr)
  Mit Zitat antworten Zitat
Benutzerbild von sh17
sh17

Registriert seit: 26. Okt 2005
Ort: Radebeul
1.689 Beiträge
 
Delphi 11 Alexandria
 
#3

AW: ChatGPT und Bunte Polygone

  Alt 22. Jul 2025, 09:02
Github Copilot kann auch zwischen FMX und VCL unterscheiden
Sven Harazim
--
  Mit Zitat antworten Zitat
Benutzerbild von Sherlock
Sherlock

Registriert seit: 10. Jan 2006
Ort: Offenbach
3.820 Beiträge
 
Delphi 12 Athens
 
#4

AW: ChatGPT und Bunte Polygone

  Alt 24. Jul 2025, 10:22
Was ich in solchen Fällen immer ganz spannend fände, wäre der Prompt, der zu dem Code führte. Gerade jetzt wo man noch lernt, was man da schreiben muss.
Oliver
Geändert von Sherlock (Morgen um 16:78 Uhr) Grund: Weil ich es kann
  Mit Zitat antworten Zitat
Delphi.Narium

Registriert seit: 27. Nov 2017
2.589 Beiträge
 
Delphi 7 Professional
 
#5

AW: ChatGPT und Bunte Polygone

  Alt 24. Jul 2025, 18:43
Dem stimme ich voll und ganz zu, ohne den hat man kaum eine bzw. keine Chance, das Ergebnis zu reproduzieren und daraus zu lernen.

Zu einem korrekten Ergebnis einer KI benötigt man immer die konkrete Fragestellung, andernfalls kann man nur im Dunklen stochern und hoffen, dass man zu einem ähnlichen Ergebnis kommt.

Die Kunst ist halt, einer KI eine Frage so genau und präzise und ausführlich mit allen geforderten Belangen zu stellen, so dass sie quasi nur noch die richtige Antwort geben kann. Je geringer der Interpretationsspielraum in der Frage ist, um so besser sind die KI-Ergebnisse.

Und Fragen so stellen zu können, ist eine Kunst, die erstmal erlernt werden will / muss.

Richtig interessant wird es eigentlich erst, wenn man eine konkrete Fragestellung bei mehreren KIs eingibt und dann die Ergebnisse vergleicht.
  Mit Zitat antworten Zitat
Antwort Antwort

Themen-Optionen Thema durchsuchen
Thema durchsuchen:

Erweiterte Suche
Ansicht

Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 13:57 Uhr.
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz