[solved] Trouble with TLazCanvas.Arc lazarus / 39-Graphics ---------------------------------------------------------------------- Valdas · 2023-03-16 18:23 Hello, I' trying to adopt an example from the this post to produce an Arc.  Instead of 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 cnv.Ellipse(0, 0, BITMAP_SIZE, BITMAP_SIZE); I'm using 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 cnv.Arc(0, 0, 20, 20, 0, 180 * 16); But I'm not getting the Arc, only a green field.  Am I missing something? ---------------------------------------------------------------------- wp · 2023-03-16 19:12 Can you show your code so that I can reproduce it? ---------------------------------------------------------------------- wp · 2023-03-16 19:53 I see: TLazCanvas does not implement its Arc method, it inherites the one from TFpCustomCanvas, and this does - nothing... Here is a quick-and-dirty procedure which you can call instead. It draws the arc as short line segments; their angular length is 5 degree - this is not optimized: for very small arcs you can increase the value because many points will be overlapping; and for large arcs you must decrease the value if you can distinguish the individual straight-line segments in the curve. (Ideally the procedure should be tuned to determine the correct value by itself). 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 uses  Math;procedure Arc(ACanvas: TLazCanvas; ALeft, ATop, ARight, ABottom: Integer;  AStartDeg, ASweepDeg: Double);var  a, b: Double;  phi, phi_end, dphi: Double;  sinphi, cosphi: Double;  x, y: Integer;  Center: TPoint;  done: Boolean = false;begin  a := (ARight - ALeft) / 2;  // major ellipse axis  b := (ABottom - ATop) / 2;  // minor ellipse axis  Center := Point((ALeft + ARight) div 2, (ATop + ABottom) div 2);  dphi := DegToRad(5);  // 5-degree steps, not optimized  if ASweepDeg < 0 then dphi := -dphi;  phi := DegToRad(AStartDeg);  phi_end := DegToRad(AStartDeg + ASweepDeg);  sincos(phi, sinphi, cosphi);  x := Center.X + round(cosphi * a);  y := Center.Y - round(sinphi * b);  ACanvas.MoveTo(x, y);  repeat    phi := phi + dphi;    if ((ASweepDeg > 0) and (phi > phi_end)) or ((ASweepDeg < 0) and (phi < phi_end)) then    begin      phi := phi_end;      done := true;    end;    sincos(phi, sinphi, cosphi);    x := Center.X + round(cosphi * a);    y := Center.Y - round(sinphi * b);    ACanvas.LineTo(x, y);  until done;end;  ALeft, ATop, ARight, ABottom define the rectangle enclosing the *full* ellipse from which the arc is cut. AStartDeg is the start angle of the arc, in degrees, measured from the x axis in counter-clockwise direction. ASweepDeg is the "length" of the arg given in degrees also. If positive the arc runs in counter-clockwise direction, otherwise in clockwise direction. The following sample draws a rounded rectangle: 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   Arc(cnv, 0, 0, 30, 30, 180, -90);  cnv.Line(15, 0, img.Width-15, 0);  Arc(cnv, img.Width-30, 0, img.Width-1, 30, 0, 90);  cnv.Line(img.Width-1, 15, img.Width-1, img.Height-15);  Arc(cnv, img.Width-30, img.Height-30, img.Width-1, img.Height-1, 0, -90);  cnv.Line(img.Width-15, img.Height-1, 15, img.Height-1);  Arc(cnv, 0, img.Height-30, 30, img.Height-1, -90, -90);  cnv.Line(0, img.Height-15, 0, 15); ---------------------------------------------------------------------- Valdas · 2023-03-17 05:59 Thank you!