Forum > Graphics

[solved] Trouble with TLazCanvas.Arc

(1/1)

Valdas:
Hello,

I' trying to adopt an example from the this post to produce an Arc.
 Instead of

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---cnv.Ellipse(0, 0, BITMAP_SIZE, BITMAP_SIZE); I'm using

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---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:
Can you show your code so that I can reproduce it?

wp:
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  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---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  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---  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:
Thank you!

Navigation

[0] Message Index

Go to full version