Blob Blame Raw
unit Unit1;

{$mode objfpc}{$H+}

interface

uses
  Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, Math;

type

  { TForm1 }

  TForm1 = class(TForm)
    procedure FormMouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer);
  private
    { private declarations }
  public
    { public declarations }
  end;

const
  sectors = 16;

var
  Form1: TForm1;
  px: integer = 0;
  py: integer = 0;

implementation

{$R *.lfm}

procedure LinePolar(x1, y1, x2, y2: single);
var
  sector: integer;
  a1, r1, a2, r2, cx ,cy: single;

begin
  cx := Form1.ClientWidth/2;
  cy := Form1.ClientHeight/2;

  x1 := x1 - cx;
  y1 := y1 - cy;
  x2 := x2 - cx;
  y2 := y2 - cy;

  a1 := arctan2(y1, x1);
  r1 := sqrt(x1*x1 + y1*y1);
  a2 := arctan2(y2, x2);
  r2 := sqrt(x2*x2 + y2*y2);

  for sector := 0 to sectors-1 do begin
    x1 := r1 * cos(a1 + sector*2*pi/sectors) + cx;
    y1 := r1 * sin(a1 + sector*2*pi/sectors) + cy;
    x2 := r2 * cos(a2 + sector*2*pi/sectors) + cx;
    y2 := r2 * sin(a2 + sector*2*pi/sectors) + cy;

    Form1.Canvas.MoveTo(round(x1), round(y1));
    Form1.Canvas.LineTo(round(x2), round(y2));
  end;
end;

procedure TForm1.FormMouseMove(Sender: TObject; Shift: TShiftState; X,
  Y: Integer);
begin
  canvas.pen.width := 3;
  if ssRight in Shift then Form1.Refresh;
  if ssLeft in Shift then LinePolar(px, py, x, y);
  px := x;
  py := y;
end;

end.