unit Unit1;

{$mode objfpc}{$H+}

interface

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

type

  { TForm1 }

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

const
  maxLen = 50;

var
  Form1: TForm1;
  pos: integer = 0;
  len: integer = 0;
  px: array[0..maxLen] of integer;
  py: array[0..maxLen] of integer;

implementation

{$R *.lfm}

procedure TForm1.FormMouseMove(Sender: TObject; Shift: TShiftState; X,
  Y: Integer);
begin
  pos := pos + 1;
  len := len + 1;
  if pos >= maxLen then pos := 0;
  if len > maxLen then len := maxLen;

  px[pos] := x;
  py[pos] := y;
end;

procedure TForm1.Timer1Timer(Sender: TObject);
begin
  Refresh;
  len := len - 1;
  if len < 0 then len := 0;
end;

procedure TForm1.FormPaint(Sender: TObject);
var
  i, p: Integer;
begin
  Canvas.MoveTo(px[pos], py[pos]);
  for i := 0 to len-1 do begin
    p := (maxLen + pos - i) mod maxLen;
    Canvas.Pen.Width := len - i;
    Canvas.LineTo(px[p], py[p]);
  end;
end;

end.

