Colored Sierpinski triangle: Another How To Problem to Solve lazarus / 39-Graphics ---------------------------------------------------------------------- Boleeman · 2024-11-16 12:17 Created a Colored Sierpinski triangle using a starter code from the Delphi version at https://rosettacode.org/wiki/Sierpinski_triangle/Graphical Worked out how to scale it but now I wanted to Mirror it and add it to the lower right corner to make a complete square from 2 Sierpinski Triangles. Not sure how to do that efficiently. Perhaps TBgrabmp Canvas has some sort of transformation to mirror or rotate 180 degrees ? Currently using a TImage called Image1. ---------------------------------------------------------------------- Dzandaa · 2024-11-16 18:11 Hi, Very Very Quick response: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure TForm1.DrawSerpTriangle(Image: TImage; StartX, StartY, Depth: integer);var  X, Y, Size, Inx, PosX, PosY: integer;  ScaleFactor: Double;  CanvasWidth, CanvasHeight: integer;begin  // Determine the size of the Sierpinski triangle (2^Depth x 2^Depth)  Size := 1 shl Depth;   CanvasWidth := Image.Width;  CanvasHeight := Image.Height;   ScaleFactor := Min(CanvasWidth / Size, CanvasHeight / Size);   for Y := 0 to Size - 1 do    for X := 0 to Size - 1 do    begin      // Calculate new color index based on X and Y positions      Inx := (Length(DepthColors24) * (X + Y)) div (Size + Size);       if (X and Y) = 0 then      begin        // Scale and draw the pixel on the canvas        PosX := StartX + Round(X * ScaleFactor);        PosY := StartY + Round(Y * ScaleFactor);        Image.Canvas.Pixels[PosX, PosY] := DepthColors24[Inx];        // Scale and draw the pixel on the canvas        Image.Canvas.Pixels[          Image.Canvas.Width - PosX,          Image.Canvas.Height - PosY        ] := DepthColors24[Inx];      end      else      begin{        Image.Canvas.Pixels[          StartX + Round(X * ScaleFactor),        StartY + Round(Y * ScaleFactor)        ] := clBlack;        Image.Canvas.Pixels[          Image.Canvas.Width - (StartX + Round(X * ScaleFactor)),          Image.Canvas.Height -(StartY + Round(Y * ScaleFactor))        ] := clBlack;                                                                 // Fill non-triangle parts with a background color        }      end;    end;end; ---------------------------------------------------------------------- ackarwow · 2024-11-16 18:34 Hi @Boleeman The Dzandaa's code seems to work perfectly. ---------------------------------------------------------------------- Boleeman · 2024-11-17 03:44 Wow ! Thankyou very much Dzandaa for coming to the rescue. I went on to make a few variations. There is probably a better "more efficient" way to do the variations in code, instead of copying portions of the image. ---------------------------------------------------------------------- Boleeman · 2024-11-17 12:00 One more "Problem-O" that I was having problems solving. I wanted to be able to fill in the largest 2 Black filled triangles with the Multicolored triangles of the same size (as shown in the attached png). I wondered if one could save the pixel locations and colors to an array or a collection of the top Multicolored triangle (outlined in red) and apply 2 transforms (move it to the bottom right quarter of Image1 and also mirror image the red outlined triangle below the original) Thinking that matrices might be needed (the morph program at https://forum.lazarus.freepascal.org/index.php/topic,69040.0.html  had a great pascal unit with lots of matix operations). . Perhaps even using Dzandaa's method (for half of the image width and height) but just doing it for the outlined smaller multicolored red outlined triangle) Anyhow I just wondered how it could possibly be done ?