daily pastebin goal
24%
SHARE
TWEET

BitByAMouse

igendel Jul 16th, 2015 210 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. unit MainFormUnit;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. interface
  6.  
  7. uses
  8.   Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs,
  9.   ExtCtrls, Math;
  10.  
  11. type
  12.  
  13.   { TMainForm }
  14.  
  15.   TMainForm = class(TForm)
  16.     Shape: TShape;
  17.     procedure ShapeMouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer);
  18.  
  19.   private
  20.     { private declarations }
  21.   public
  22.     { public declarations }
  23.   end;
  24.  
  25. var
  26.   MainForm: TMainForm;
  27.  
  28. implementation
  29.  
  30. {$R *.lfm}
  31.  
  32. const
  33.   SYNC = 16;
  34.   MOUSE_SEQUENCE : array[0..SYNC] of Word = (
  35.     $0492, $0960, $0618, $014A,
  36.     $0A41, $0249, $0096, $0861,
  37.     $041A, $0168, $0690, $0942,
  38.     $0A14, $0294, $0069, $0816,
  39.     $04A1);
  40.  
  41. function SequenceToNybble(const s : Word) : Byte;
  42. begin
  43.   for Result := 0 to SYNC do if s = MOUSE_SEQUENCE[Result] then Exit;
  44.   Result := 255;
  45. end;
  46.  
  47. { TMainForm }
  48.  
  49. procedure TMainForm.ShapeMouseMove(Sender: TObject; Shift: TShiftState; X,
  50.   Y: Integer);
  51.  
  52. const
  53.   lastX    : Integer = 0;
  54.   lastY    : Integer = 0;
  55.   Sequence : QWord = 0; // 64-Bit
  56.  
  57. var
  58.   dx, dy : Byte;
  59.   Nybble : Byte;
  60.   b      : Byte;
  61.  
  62. begin
  63.  
  64.   dx := min(X - lastX + 1, 3);
  65.   dy := min(Y - lastY + 1, 3);
  66.  
  67.   Sequence := (Sequence SHL 4) + (dx SHL 2) + dy;
  68.   if (Sequence SHR 24) AND ($FFF) = MOUSE_SEQUENCE[SYNC] then
  69.    begin
  70.  
  71.      Nybble := SequenceToNybble((Sequence SHR 12) AND ($FFF));
  72.      if Nybble < SYNC then
  73.       begin
  74.  
  75.         b := Nybble SHL 4;
  76.         Nybble := SequenceToNybble(Sequence AND ($FFF));
  77.         if Nybble < SYNC then
  78.           begin
  79.  
  80.             Inc(b, Nybble);
  81.             Shape.Brush.Color := RGBToColor(b, b, b);
  82.             Sequence := 0;
  83.  
  84.           end;
  85.  
  86.       end;
  87.  
  88.    end;
  89.  
  90.   lastX := X;
  91.   lastY := Y;
  92.  
  93. end;
  94.  
  95. end.
RAW Paste Data
Top