this slowpoke moves

Draw Flashlight on Mouse

uses Math

type
  TRGBArray = ARRAY[0..0] OF TRGBTriple;
  pRGBArray = ^TRGBArray;
  
const d = 250;

var
  Form1: TForm1;
  orig, temp: TBitmap;
  r : TRect;
  hypotenuse : Array of Array of Integer;
  
//

procedure TForm1.FormCreate(Sender: TObject);
var
  c : TCanvas;
  i, j : Integer;
begin
  DoubleBuffered := true;
  ShowCursor(false);
  Top := 0;
  Left := 0;
  ClientWidth := Screen.Width;
  ClientHeight := Screen.Height;
  r := Rect(0 , 0, ClientWidth, ClientHeight);
  orig := TBitmap.Create;
  orig.PixelFormat := pf24Bit;
  orig.Width := ClientWidth;
  orig.Height := ClientHeight;
  temp := TBitmap.Create;
  temp.Canvas.Brush.Color := clBlack;
  temp.PixelFormat := pf24Bit;
  temp.Width := ClientWidth;
  temp.Height := ClientHeight;
  c := TCanvas.Create;
  try
    c.Handle := GetWindowDC(GetDesktopWindow);
    orig.Canvas.CopyRect(r, c, r);
  finally
    c.Free;
  end;
  Canvas.Draw(0, 0, orig);
  setLength(hypotenuse, d+1, d+1);
  for i := 0 to d do for j := 0 to d do hypotenuse[i, j] := Round(Hypot(i, j));
end;

procedure TForm1.FormClick(Sender: TObject);
begin
  Close;
end;

procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
  orig.Free;
  temp.Free;
end;

procedure TForm1.FormPaint(Sender: TObject);
begin
  Canvas.Draw(0, 0, temp);
end;

procedure TForm1.FormKeyPress(Sender: TObject; var Key: Char);
begin
  Close;
end;

procedure TForm1.FormMouseMove(Sender: TObject; Shift: TShiftState; X,
  Y: Integer);
var
  i, j, x0, x1, y0, y1, h : Integer;
  O, T : PRGBArray;
begin
  x0 := max(0, X - d);
  x1 := min(orig.Width-1, X + d);
  y0 := max(0, Y - d);
  y1 := min(orig.Height-1, Y + d);
  temp.Canvas.FillRect(r);
  for j := y0 to y1 do begin
    O := orig.Scanline[j];
    T := temp.ScanLine[j];
    for i := x0 to x1 do begin
      h := hypotenuse[Abs(X-i), Abs(Y-j)];
      if h < d then begin
        h := Trunc(h/d*255);
        T[i].rgbtRed := max(0, O[i].rgbtRed - h);
        T[i].rgbtGreen := max(0, O[i].rgbtGreen - h);
        T[i].rgbtBlue := max(0, O[i].rgbtBlue - h);
      end;
    end;
  end;
  Repaint;
end;

Keine Kommentare:

Kommentar veröffentlichen

Beliebte Posts

Translate