CynicRus
2013-02-25 05:47:46
Hey. Spread algorithm mouse movements on a pre-calculated path. Perhaps to be useful.
Used algorithms:
1)Catmull-Rom spline
2)Kochanek-Bartels splines
Cheers,Cynic.
Used algorithms:
1)Catmull-Rom spline
2)Kochanek-Bartels splines
function randomPoint(minX, maxX, minY, maxY: longInt): tPoint;
begin
result.x := randomRange(minX, maxX);
result.y := randomRange(minY, maxY)
end;
function GenerateTPA(StartPt, EndPt: TPoint;count: integer): TPointArray;
var
TPA: TPointArray;
i: integer;
begin
for i := 0 to count - 1 do
begin
SetLength(TPA, i + 1);
TPA[i] := randomPoint(StartPt.x, EndPt.x, StartPt.y, EndPt.y)
end;
SortTPAFrom(TPA, StartPt);
ClearDoubleTPA(TPA);
SetLength(TPA, Length(TPA) + 1);
TPA[Length(TPA) - 1] := EndPt;
Result := TPA;
end;
function CalcMousePathCSM(Points: TPointArray; closed: boolean; asClosed: boolean): TPointArray;
var
C, i, CE, N1, N2, k: integer;
P1, P2, P0, C0, B0, P0C: TPoint;
begin
k := 0;
C := High(Points) - Low(Points) + 1;
CE := C;
if not closed then
dec(CE);
SetLength(result, CE * 3 + 1);
for i := 0 to C - 1 do
begin
P0 := Points[i];
N1 := i - 1;
if N1 < 0 then
if closed or asClosed then
N1 := C - 1
else
N1 := i;
N2 := i + 1;
if N2 > C - 1 then
if closed or asClosed then
N2 := 0
else
N2 := i;
P1 := Points[N1];
P2 := Points[N2];
P2.X := (P2.X - P1.X) / 2;
P2.Y := (P2.Y - P1.Y) / 2;
C0.X := P0.X - P2.X / 3;
C0.Y := P0.Y - P2.Y / 3;
B0.X := P0.X + P2.X / 3;
B0.Y := P0.Y + P2.Y / 3;
if i = 0 then
P0C := C0
else
begin
result[k] := C0;
inc(k);
end;
result[k] := P0;
inc(k);
if (i < C - 1) or closed then
begin
result[k] := B0;
inc(k);
end;
end;
if closed then
begin
result[k] := P0C;
inc(k);
result[k] := Points[0];
end;
end;
function CalcMousePathKBS(Points: TPointArray; pt, pb, pc: integer; closed: boolean; asClosed: boolean): TPointArray;
var
C, i, CE, N1, N2, N3, k: integer;
P1, P2, P3, P0, C0, B0, P0C, d0, d1: TPoint;
begin
k := 0;
C := High(Points) - Low(Points) + 1;
CE := C;
if not closed then
dec(CE);
SetLength(result, CE * 3 + 1);
for i := 0 to C - 1 do
begin
P0 := Points[i];
N1 := i - 1;
if N1 < 0 then
if closed or asClosed then
N1 := C - 1
else
N1 := i;
N2 := i + 1;
if N2 > C - 1 then
if closed or asClosed then
N2 := 0
else
N2 := i;
N3 := N2 + 1;
if N3 > C - 1 then
N3 := 0;
P1 := Points[N1];
P2 := Points[N2];
P3 := Points[N3];
d0.x := (1 - pt) * (1 + pb) * (1 + pc) / 2 * (P0.x - P1.x) + (1 - pt) * (1 - pb) * (1 - pc) / 2 * (P2.x - P0.x);
d0.y := (1 - pt) * (1 + pb) * (1 + pc) / 2 * (P0.y - P1.y) + (1 - pt) * (1 - pb) * (1 - pc) / 2 * (P2.y - P0.y);
d1.x := (1 - pt) * (1 + pb) * (1 - pc) / 2 * (P0.x - P1.x) + (1 - pt) * (1 - pb) * (1 + pc) / 2 * (P2.x - P0.x);
d1.y := (1 - pt) * (1 + pb) * (1 - pc) / 2 * (P0.y - P1.y) + (1 - pt) * (1 - pb) * (1 + pc) / 2 * (P2.y - P0.y);
C0.X := P0.X - d0.X / 3;
C0.Y := P0.Y - d0.Y / 3;
B0.X := P0.X + d1.X / 3;
B0.Y := P0.Y + d1.Y / 3;
if i = 0 then
P0C := C0
else
begin
result[k] := C0;
inc(k);
end;
result[k] := P0;
inc(k);
if (i < C - 1) or closed then
begin
result[k] := B0;
inc(k);
end;
end;
if closed then
begin
result[k] := P0C;
inc(k);
result[k] := Points[0];
end;
end;
procedure CalculatedMouseMove(x, y: integer);
var
StartPt: TPoint;
i, count, a: integer;
TPA: TPointArray;
begin
GetMousePos(StartPt.x, StartPt.y);
TPA := GenerateTPA(StartPt, Point(x, y),4);
a := Random(10);
case a of
0..5: TPA := CalcMousePathCSM(TPA, false, false);
6..10: TPA := CalcMousePathKBS(TPA, 0, 0, 0, false, false);
end;
ClearDoubleTPA(TPA);
count := Length(TPA);
for i := 0 to count - 1 do
begin
MoveMouse(TPA[i].x, TPA[i].y);
Sleep(Random(10));
end;
end;
Cheers,Cynic.