Blame lazarus/kaleidoscope/unit1.pas

64a39c
unit Unit1;
64a39c
64a39c
{$mode objfpc}{$H+}
64a39c
64a39c
interface
64a39c
64a39c
uses
64a39c
  Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, Math;
64a39c
64a39c
type
64a39c
64a39c
  { TForm1 }
64a39c
64a39c
  TForm1 = class(TForm)
64a39c
    procedure FormMouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer);
64a39c
  private
64a39c
    { private declarations }
64a39c
  public
64a39c
    { public declarations }
64a39c
  end;
64a39c
64a39c
const
64a39c
  sectors = 16;
64a39c
64a39c
var
64a39c
  Form1: TForm1;
64a39c
  px: integer = 0;
64a39c
  py: integer = 0;
64a39c
64a39c
implementation
64a39c
64a39c
{$R *.lfm}
64a39c
64a39c
procedure LinePolar(x1, y1, x2, y2: single);
64a39c
var
64a39c
  sector: integer;
64a39c
  a1, r1, a2, r2, cx ,cy: single;
64a39c
64a39c
begin
64a39c
  cx := Form1.ClientWidth/2;
64a39c
  cy := Form1.ClientHeight/2;
64a39c
64a39c
  x1 := x1 - cx;
64a39c
  y1 := y1 - cy;
64a39c
  x2 := x2 - cx;
64a39c
  y2 := y2 - cy;
64a39c
64a39c
  a1 := arctan2(y1, x1);
64a39c
  r1 := sqrt(x1*x1 + y1*y1);
64a39c
  a2 := arctan2(y2, x2);
64a39c
  r2 := sqrt(x2*x2 + y2*y2);
64a39c
64a39c
  for sector := 0 to sectors-1 do begin
64a39c
    x1 := r1 * cos(a1 + sector*2*pi/sectors) + cx;
64a39c
    y1 := r1 * sin(a1 + sector*2*pi/sectors) + cy;
64a39c
    x2 := r2 * cos(a2 + sector*2*pi/sectors) + cx;
64a39c
    y2 := r2 * sin(a2 + sector*2*pi/sectors) + cy;
64a39c
64a39c
    Form1.Canvas.MoveTo(round(x1), round(y1));
64a39c
    Form1.Canvas.LineTo(round(x2), round(y2));
64a39c
  end;
64a39c
end;
64a39c
64a39c
procedure TForm1.FormMouseMove(Sender: TObject; Shift: TShiftState; X,
64a39c
  Y: Integer);
64a39c
begin
64a39c
  canvas.pen.width := 3;
64a39c
  if ssRight in Shift then Form1.Refresh;
64a39c
  if ssLeft in Shift then LinePolar(px, py, x, y);
64a39c
  px := x;
64a39c
  py := y;
64a39c
end;
64a39c
64a39c
end.
64a39c