nielsie95
2007-06-18 09:12:35
Hey,
some of you may have noticed this thread.. In that thread I posted the Bezier Curve function.
With that function I made (another) mouse function; BezierMouse..
Features
Images

The first image displays (top-bottom) BenMouse - RsNMouse - BezierMouse (0 randomness).
You can see that BezierMouse with 0 randomness is the same as RsNMouse.

The second image displays (top-bottom) BenMouse - RsNMouse - BezierMouse (25 randomness).
You can see that BezierMouse with 25 randomness (just like BenMouse) creates a random path..
Please test the code beneath in paint and tell me what you think.
some of you may have noticed this thread.. In that thread I posted the Bezier Curve function.
With that function I made (another) mouse function; BezierMouse..
Features
- Randomness at the endpoint.
- Randomness in the spline.
- It will slowdown when it's reaching the end.
- It will speed up when it's starting.
- All of the above points are fully customize-able.
Images

The first image displays (top-bottom) BenMouse - RsNMouse - BezierMouse (0 randomness).
You can see that BezierMouse with 0 randomness is the same as RsNMouse.

The second image displays (top-bottom) BenMouse - RsNMouse - BezierMouse (25 randomness).
You can see that BezierMouse with 25 randomness (just like BenMouse) creates a random path..
Please test the code beneath in paint and tell me what you think.
program BezierMouse;
{.Include SRL/SRL.SCAR}
const Speed = 13;
Randomness = 25;
SlowDown = 12;
function GetMidPoints(Ar: TPointArray; Points: Integer): TPointArray;
var
i: integer;
TempX, TempY: Extended;
begin
SetArrayLength(Result, Points);
TempX := Ar[1].x - Ar[0].x;
TempY := Ar[1].y - Ar[0].y;
TempX := TempX div Points;
TempY := TempY div Points;
for i := 0 to Points -1 do
if i > 0 then Result[i] := Point(Round(TempX * (i + 1)) + Ar[0].x, Round(TempY * (i + 1)) + Ar[0].y) else
Result[i] := Point(Round(TempX * (i)) + Ar[0].x, Round(TempY * (i)) + Ar[0].y)
end;
function CreateSplinePoints(sp, ep: TPoint): TPointArray;
var
i: Integer;
TempArray: TPointArray;
RanX, RanY: Extended;
begin
SetArrayLength(Result, 4);
TempArray := [sp, ep];
TempArray := GetMidPoints(TempArray, 4);
Result[0] := sp;
Result[3] := ep;
for i := 1 to 2 do
begin
case Random(3) of
0: RanX := ((Randomness + Random(Randomness * 2)) * (Rand * 2));
1: RanX := ((Randomness * Rand) + Random(Round(Randomness * 1.25))) * (Rand * 2);
2: RanX := ((Randomness + Random(Randomness)) * (Rand));
end;
if Random(2) = 0 then RanX := -(RanX);
case Random(3) of
0: RanY := ((Randomness + Random(Round(Randomness * 2))) * (Rand * 2));
1: RanY := ((Randomness * Rand) + Random(Round(Randomness * 1.25))) * (Rand * 2);
2: RanY := ((Randomness + Random(Randomness)) * (Rand));
end;
if Random(2) = 1 then RanY := -(RanY);
Result[i] := Point(Round(TempArray[i].x + RanX), Round(TempArray[i].y + RanY));
end;
end;
function PointOnCubicBezier(cp: TPointArray; t, Curve: Extended): TPoint;
var
ax, ay, bx, by, cx, cy,
tSquared, tCubed: Extended;
i: integer;
begin
cx := Curve * (cp[1].x - cp[0].x);
bx := Curve * (cp[2].x - cp[1].x) - cx;
ax := cp[3].x - cp[0].x - cx - bx;
cy := Curve * (cp[1].y - cp[0].y);
by := Curve * (cp[2].y - cp[1].y) - cy;
ay := cp[3].y - cp[0].y - cy - by;
tSquared := t * t;
tCubed := tSquared * t;
result.x := Round((ax * tCubed) + (bx * tSquared) + (cx * t) + cp[0].x);
result.y := Round((ay * tCubed) + (by * tSquared) + (cy * t) + cp[0].y);
end;
function BezierSpline(cp: TPointArray; NumberOfPoints: Integer; Curve: Extended): TpointArray;
var
dt: Extended;
i: Integer;
begin
dt := 1.0 / (NumberOfPoints - 1);
SetArrayLength(Result, 0);
for i := 0 to NumberOfPoints do
begin
SetArrayLength(Result, Length(Result) +1);
Result[i] := PointOnCubicBezier(cp, i * dt, Curve);
end;
end;
procedure BezierMouse(cx, cy, rx, ry: Integer);
var
PointArray, ResultArray: TPointArray;
i, tx, ty, SlowDownWait, Dist: Integer;
begin
GetMousePos(tx, ty);
try
Dist := Distance(tx, ty, cx, cy);
if Dist <= Round((rx + ry) / 2) then Exit;
except Exit; end;
if Random(2) = 0 then PointArray := CreateSplinePoints(Point(tx, ty), Point(cx + Random(rx), cy + Random(ry))) else
PointArray := CreateSplinePoints(Point(tx, ty), Point(cx - Random(rx), cy - Random(ry)))
ResultArray := BezierSpline(PointArray, Round(Distance(tx, ty, cx, cy) / Abs(12 - (MouseSpeed mod 3))), 3.0);
for i := 0 to Length(ResultArray) -1 do
begin
MoveMouse(ResultArray[i].x, ResultArray[i].y);
SlowDownWait := Round((i div (Length(ResultArray) -1)) * 100);
if SlowDownWait <= (SlowDown / 2) then Wait(Ceil(MouseSpeed + iAbs(((SlowDown / 2) +1) - SlowDownWait) * (MouseSpeed div 5))) else
if SlowDownWait >= (100 - SlowDown) then Wait(Ceil(MouseSpeed + iAbs((101 - SlowDown) - SlowDownWait) * (MouseSpeed div 5))) else
if (MouseSpeed < 3) and (Random(2) = 0) then Wait(0) else Wait(Ceil(MouseSpeed + Random(MouseSpeed div 5)));
if Distance(cx, cy, ResultArray[i].x, ResultArray[i].y) <= Round((rx + ry) / 2) then Break;
end;
end;
var i, tx, ty: integer;
begin
SetupSRL;
MouseSpeed := Speed;
for i := 0 to 2 do
begin
case i of
0 : WriteLn('MMouse - BenMouse: True - Straight line');
1 : WriteLn('MMouse - BenMouse: False - Straight line');
2 : WriteLn('BezierMouse - Randomness: '+IntToStr(Randomness)+' - Straight line');
end
if i = 1 then BenMouse := False;
tx := 30;
ty := 50 + (150 * i);
MoveMouse(tx, ty);
HoldMouse(tx, ty, True);
case i of
0, 1: MMouse(tx + 700, ty, 0, 0);
2: BezierMouse(tx + 700, ty, 0, 0);
end;
GetMousePos(x, y);
ReleaseMouse(x, y, True);
MoveMouse(tx, ty);
HoldMouse(tx, ty, True);
ty := 100 + (150 * i);
case i of
0 : WriteLn('MMouse - BenMouse: True - Diagonal line');
1 : WriteLn('MMouse - BenMouse: False - Diagonal line');
2 : WriteLn('BezierMouse - Randomness: '+IntToStr(Randomness)+' - Diagonal line');
end
case i of
0, 1: MMouse(tx + 700, ty, 0, 0);
2: BezierMouse(tx + 700, ty, 0, 0);
end;
GetMousePos(x, y);
ReleaseMouse(x, y, True);
end;
end.

This seems to resemble me moving the mouse the most






