CX gamer
2010-08-01 09:31:31
Hi,
I wanted to make a mouse function, so firstly I recorded my own mouse behaviour, this is the speed every 10 ms;
http://a.imageshack.us/img375/9711/speedf.png
I made a mouse function that moves with 'pulses';
This pulse determens the speed of the moving mouse and takes about 150 to 300 milliseconds.
Firstly it estimates the angle under which it must move, which is randomly chosen by a gauss function;
To get to that, I needed to convert a linear random to a gauss random, I achieved this by using this function;
Then it moves for the 150-300 ms along the pulse, encountering randomised angle-acceleration to ensure a random but smooth path. The mouse is also under the effect of some minor 'jitter', but is turned off at slow speeds.
At the end of a pulse, it uses the linear first part to determen where the next pulse should start, so it can continue without interrupts.
My script could use some tweaking, could you guys give it a few runs and tell me which constants you find best? Thanks. :)
You can also edit some of the coding if you find it nessecary.
This is a comparision; tell me which looks best. :D

One of them is MMouse, the other one is my script. Not saying which is which. :P
[PHP]program Mouse;
const
jitter = 1; // Randomized pixel movement
misjudgement = 0.04; // The amount the angle can be off during a pulse
freedom = 5; // Limiting the misjudgement
fps = 100; // The number of times it updates the mouse per second
accuracy = 0.8; // The accuracy of the angle estimated before each pulse
{*******************************************************************************
function getAngle(xs, ys : extended; xe, ye : integer) : extended;
By: CX
Description: Returns the angle considering 2 points
*******************************************************************************}
function getAngle(xs, ys : extended; xe, ye : integer) : extended;
begin
if xs = xe then
begin
if ys > ye then
begin
result := 3 * PI / 2;
end else
result := - PI / 2;
end else
result := arcTan((ye - ys)/(xe - xs));
if xs > xe then result := result + PI;
fixR(result);
end;
{*******************************************************************************
function randomGauss : extended;
By: CX
Description: Returns a random gaussian number between -1 and 1.
*******************************************************************************}
function randomGauss : extended;
var
r : extended;
begin
r := (random(20000) - 10000) / 10000;
result := 0.2 * r + 0.8 * pow(r, 5);
end;
{*******************************************************************************
function angleDiff(a1, a2 : extended) : extended;
By: CX
Description: Calculates the difference between 2 angles in radians
*******************************************************************************}
function angleDiff(a1, a2 : extended) : extended;
begin
a1 := fixR(a1);
a2 := fixR(a2);
result := a2 - a1;
if (result > PI) then result := - 2 * PI + result;
if (result < -PI) then result := 2 * PI + result;
end;
{*******************************************************************************
procedure MMouseBox(xs, ys, xe, ye : integer);
By: CX
Description: Moves the mouse inside the box
*******************************************************************************}
procedure MMouseBox(xs, ys, xe, ye : integer);
var
angle, speed, a, i, r, x, y, pulse : extended;
mx, my, xdes, ydes, frq, t, pulseLength : integer;
box : TBox;
begin
box.x1 := xs;
box.x2 := xe;
box.y1 := ys;
box.y2 := ye;
xdes := (xs + xe) / 2;
ydes := (ys + ye) / 2;
frq := 1000 / fps;
getMousePos(mx, my);
x := mx;
y := my;
i := 0;
angle := getAngle(x, y, xdes, ydes) + accuracy * randomGauss;
repeat
t := getTickCount;
pulseLength := randomRange(150, 300);
pulse := distance(round(x), round(y), xdes, ydes) / randomRange(325, 400);
repeat
r := random(11) / 1000 + 0.03;
i := i + r;
a := a + misjudgement * randomGauss;
angle := angle + a - angleDiff(getAngle(x, y, xdes, ydes), angle) / freedom;
speed := 200 * i * exp(-4 * i) * pulse;
x := x + round(cos(angle) * speed);
y := y + round(sin(angle) * speed);
if (speed > 2) then
begin
x := x + randomRange(-jitter, jitter + 1);
y := y + randomRange(-jitter, jitter + 1);
end;
wait(frq);
moveMouse(round(x), round(y));
until ((getTickCount - t) >= pulseLength);
i := speed / (200 * pulse);
angle := angle - angleDiff(getAngle(x, y, xdes, ydes), angle) * accuracy;
until IntInBox(round(x), round(y), box);
end;
begin
MMouseBox(536, 404, 616, 480);
end.[/PHP]
Well, it's a start. :)
I wanted to make a mouse function, so firstly I recorded my own mouse behaviour, this is the speed every 10 ms;
http://a.imageshack.us/img375/9711/speedf.png
I made a mouse function that moves with 'pulses';
This pulse determens the speed of the moving mouse and takes about 150 to 300 milliseconds.Firstly it estimates the angle under which it must move, which is randomly chosen by a gauss function;
To get to that, I needed to convert a linear random to a gauss random, I achieved this by using this function;
Then it moves for the 150-300 ms along the pulse, encountering randomised angle-acceleration to ensure a random but smooth path. The mouse is also under the effect of some minor 'jitter', but is turned off at slow speeds.At the end of a pulse, it uses the linear first part to determen where the next pulse should start, so it can continue without interrupts.
My script could use some tweaking, could you guys give it a few runs and tell me which constants you find best? Thanks. :)
You can also edit some of the coding if you find it nessecary.
This is a comparision; tell me which looks best. :D

One of them is MMouse, the other one is my script. Not saying which is which. :P[PHP]program Mouse;
const
jitter = 1; // Randomized pixel movement
misjudgement = 0.04; // The amount the angle can be off during a pulse
freedom = 5; // Limiting the misjudgement
fps = 100; // The number of times it updates the mouse per second
accuracy = 0.8; // The accuracy of the angle estimated before each pulse
{*******************************************************************************
function getAngle(xs, ys : extended; xe, ye : integer) : extended;
By: CX
Description: Returns the angle considering 2 points
*******************************************************************************}
function getAngle(xs, ys : extended; xe, ye : integer) : extended;
begin
if xs = xe then
begin
if ys > ye then
begin
result := 3 * PI / 2;
end else
result := - PI / 2;
end else
result := arcTan((ye - ys)/(xe - xs));
if xs > xe then result := result + PI;
fixR(result);
end;
{*******************************************************************************
function randomGauss : extended;
By: CX
Description: Returns a random gaussian number between -1 and 1.
*******************************************************************************}
function randomGauss : extended;
var
r : extended;
begin
r := (random(20000) - 10000) / 10000;
result := 0.2 * r + 0.8 * pow(r, 5);
end;
{*******************************************************************************
function angleDiff(a1, a2 : extended) : extended;
By: CX
Description: Calculates the difference between 2 angles in radians
*******************************************************************************}
function angleDiff(a1, a2 : extended) : extended;
begin
a1 := fixR(a1);
a2 := fixR(a2);
result := a2 - a1;
if (result > PI) then result := - 2 * PI + result;
if (result < -PI) then result := 2 * PI + result;
end;
{*******************************************************************************
procedure MMouseBox(xs, ys, xe, ye : integer);
By: CX
Description: Moves the mouse inside the box
*******************************************************************************}
procedure MMouseBox(xs, ys, xe, ye : integer);
var
angle, speed, a, i, r, x, y, pulse : extended;
mx, my, xdes, ydes, frq, t, pulseLength : integer;
box : TBox;
begin
box.x1 := xs;
box.x2 := xe;
box.y1 := ys;
box.y2 := ye;
xdes := (xs + xe) / 2;
ydes := (ys + ye) / 2;
frq := 1000 / fps;
getMousePos(mx, my);
x := mx;
y := my;
i := 0;
angle := getAngle(x, y, xdes, ydes) + accuracy * randomGauss;
repeat
t := getTickCount;
pulseLength := randomRange(150, 300);
pulse := distance(round(x), round(y), xdes, ydes) / randomRange(325, 400);
repeat
r := random(11) / 1000 + 0.03;
i := i + r;
a := a + misjudgement * randomGauss;
angle := angle + a - angleDiff(getAngle(x, y, xdes, ydes), angle) / freedom;
speed := 200 * i * exp(-4 * i) * pulse;
x := x + round(cos(angle) * speed);
y := y + round(sin(angle) * speed);
if (speed > 2) then
begin
x := x + randomRange(-jitter, jitter + 1);
y := y + randomRange(-jitter, jitter + 1);
end;
wait(frq);
moveMouse(round(x), round(y));
until ((getTickCount - t) >= pulseLength);
i := speed / (200 * pulse);
angle := angle - angleDiff(getAngle(x, y, xdes, ydes), angle) * accuracy;
until IntInBox(round(x), round(y), box);
end;
begin
MMouseBox(536, 404, 616, 480);
end.[/PHP]
Well, it's a start. :)
EDIT2: Math functions are important, people! I was trying to make it Simba-ready;
This is going to take me a while.

Please do ignore the amount it's sticking out, etc. These are constant values to your own preference.
So a better solution would be to take a random linear angle (0, 2PI), and a distance determined by a random gauss with an even power. Or just a random linear angle (0, PI) and a random gauss with an uneven power. Ofcourse, the corners would be omitted, so the domain of the circle would need to be larger than the square area, meaning that there need to be checks wether or not the cordinates are in the box or not.