Truchet Tiling Curve: Some Extra Settings lazarus / 39-Graphics ---------------------------------------------------------------------- Boleeman · 2024-05-25 13:50 Thanks Dzandaa for getting the tiling working. Much Appreciated. Working solution in Dzandaa's Reply. Hi All. I was trying to create a Truchet Tiling Curve from some VB6 code, but I can't seem to get the four 1/4 of a circle sized arcs to work correctly in Lazarus. Any help from someone with a sound knowledge of Lazarus Arc creation would be greatly appreciated. Attached is a png picture of how the arcs in the tiles should be orientated, as well as the expected Truchet Tiling Curve. I have used this code to create the arcs in Lazarus but obviously it is incorrect. Cant seem to those ARCS right. 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       begin        // Draw quarter circles in opposing corners        ACanvas.Arc(Round(X), Round(Y), Round(X + WID), Round(Y + WID),        Round(X + RADIUS), Round(Y), Round(X), Round(Y + RADIUS));        ACanvas.Arc(Round(X + WID), Round(Y + WID), Round(X), Round(Y),        Round(X + WID), Round(Y + RADIUS), Round(X + RADIUS), Round(Y + WID));      end      else      begin        ACanvas.Arc(Round(X), Round(Y), Round(X + WID), Round(Y + WID),          Round(X + WID), Round(Y + RADIUS), Round(X + RADIUS), Round(Y));        ACanvas.Arc(Round(X), Round(Y + WID), Round(X + WID), Round(Y),        Round(X + RADIUS), Round(Y + WID), Round(X), Round(Y + RADIUS));    end; ---------------------------------------------------------------------- Boleeman · 2024-05-26 10:10 Now I am getting the pattern shown in the attached png. Still not correct, but an interesting pattern. ---------------------------------------------------------------------- Boleeman · 2024-05-26 10:35 Expected curve still not happening. Ahhhhh, the bug is where ? Worked out how to do the arcs, by lots of experimenting. Now I have the Arcs paired up correctly, but the final curve is not what is expected. What could be wrong now? 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.DrawPicture(ACanvas: TCanvas);var  r, c, max_r, max_c: Integer;  X, Y: Single;begin  ACanvas.Brush.Color := clWhite;  ACanvas.FillRect(0, 0, PaintBox1.Width, PaintBox1.Height);   max_c := PaintBox1.Width div WID + 1;  max_r := PaintBox1.Height div WID + 1;  Y := 0;  for r := 0 to max_r do  begin    X := 0;    for c := 0 to max_c do    begin      if Random > 0.5 then       begin           ACanvas.Pen.Width:=2;                // Draw quarter circles in opposing corners           // Draw Top Left quarter circle            ACanvas.Arc(Round(X - RADIUS ), Round(Y - RADIUS), Round(X + RADIUS), Round(Y + RADIUS),        Round(X), Round(Y + RADIUS), Round(X + RADIUS), Round(Y));         // Draw bottom-right quarter circle     ACanvas.Arc(Round(X - RADIUS + RADIUS  + RADIUS), Round(Y - RADIUS + RADIUS  + RADIUS), Round(X + RADIUS + RADIUS  + RADIUS), Round(Y + RADIUS + RADIUS  + RADIUS),       Round(X + RADIUS  + RADIUS), Round(Y - RADIUS + RADIUS  + RADIUS), Round(X  - RADIUS + RADIUS  + RADIUS), Round(Y + RADIUS + RADIUS ));       end      else      begin          ACanvas.Pen.Width:=2;                    // Draw bottom-left quarter circle       ACanvas.Arc(Round(X - RADIUS  - RADIUS  - RADIUS), Round(Y + RADIUS), Round(X - RADIUS), Round(Y + RADIUS + 2*RADIUS),      Round(X - RADIUS), Round(Y + 2*RADIUS), Round(X  - RADIUS - RADIUS), Round(Y  + RADIUS));       // Draw top-right quarter circle   ACanvas.Arc(Round(X - RADIUS), Round(Y - RADIUS), Round(X + RADIUS), Round(Y + RADIUS),        Round(X - RADIUS), Round(Y), Round(X), Round(Y + RADIUS));       end;      X := X + WID;    end;    Y := Y + WID;  end;   if chkFillIt.Checked then  begin    // Flood areas    Y := RADIUS;    for r := 0 to max_r do    begin      X := RADIUS;      for c := 0 to max_c do      begin        if ACanvas.Pixels[Round(X), Round(Y)] = clWhite then          FloodAtPoint(ACanvas, X, Y);        X := X + WID;      end;      Y := Y + WID;    end;  end;end;       Final curve should be smooth and round, as shown in the last attached png. ---------------------------------------------------------------------- Boleeman · 2024-05-26 12:15 I was analyzing the pattern and it seems sometimes there are 4 arcs drawn in the one tile position and other times there are no arcs drawn in a tile position. 2 arcs should always be drawn in a tile position, selecting from 2 possibilities. Somehow the tiling of the pairs of arcs is not done consistently, so that there are 2 arcs in every tiling position. See attached png to see what I mean. I did a manual copy and paste test of the pairs of arcs in MsPaint and was getting the required curve. So that means somewhere the program is messing up when tiling the 2 pairs of arcs. Sometimes 4 arcs are placed in one tiling position and other times there are no arcs, and at other times there are 2 arcs in one tiling position (correct placement). Could     if Random > 0.5 then     be the problem? Is there a better way of randomly choosing from 2 arc pair options? ---------------------------------------------------------------------- Dzandaa · 2024-06-03 13:11 Hi Boleeman, Here is a solution: Have a nice day. B-> ---------------------------------------------------------------------- Boleeman · 2024-06-03 19:55 Thanks Dzandaa for that solution. As always, Very Much Appreciated. ---------------------------------------------------------------------- Boleeman · 2024-06-03 21:02 I added a Get rid of any dark fill colours, so that there are only light fill colours. I was also trying to go a step further by minimizing any diagonally adjacent circles. See diagram to see what I mean. ---------------------------------------------------------------------- Boleeman · 2024-06-03 23:30 Added some extra settings to DZandaa's version. Limited the colors to lighter ones. Resize the from and watch the magic. Wondered how to antialiase the Arcs using BgraBMP ? (I tried but failed) ---------------------------------------------------------------------- Dzandaa · 2024-06-04 10:12 Hi, @Boleeman, This version use BGRAVirtualScreen with Antialiasing. It is slower for large Pictures. B-> ---------------------------------------------------------------------- Boleeman · 2024-06-04 11:31 Thanks DZandaa for the BGRAVirtualScreen with Antialiasing. I tried BgraBmp control but got a bit lost by it all. Your solution is great. I see how it is a bit slower but the Arc graphics are better. I did not know about Pict.CanvasBGRA.Arc I attached my crappy failed attempt (looks like I was doing it incorrectly with BgraBmp) Curve is moved by width of Panel1 and seems not anti-aliased. Also fill was gone. A great result with your BGRAVirtualScreen version. Thanks once again DZandaa.