mixster
2009-10-14 11:17:35
It is related to previous thread by me (here) and so uses that logic to generate a unique point to click on along with readability-first code. Of course, also included is a shortened version with minimal readability, but looks cooler.
The shorter code is less accurate (will throw the odd point that is 1 pixel out of a "perfect" ellipse) but won't be any more off than that.
Short description: cx and cy are centre x/y values, mx and my max x/y offset in either direction, clickType follows MouseBox rules of 1 for left click, 2 for right click, 3 for move only (at least I hope it does).
NO, N2, BAD BOY
procedure MouseOval_(cx, cy, mx, my, clickType: Integer);
var
r: Extended;
m: Integer;
p: TPoint;
begin
if not InRange(clickType, 1, 3) then
begin
srl_Warn('MouseOval', 'ClickType is NOT a valid number!', warn_AllVersions);
exit;
end;
r := mx / my;
m := Random(my - 1);
if Random(2) = 0 then
m := -m - 1;
p.y := cy + m;
m := Random(Round(Sqrt(Sqr(my) - Sqr(m)) * r) - 1);
if Random(2) = 0 then
m := -m - 1;
p.x := cx + m;
case clickType of
1,2: Mouse(p.x, p.y, 0, 0, clickType = 1);
3: MMouse(p.x, p.y, 0, 0);
end;
end;
procedure MouseOval(cx, cy, mx, my, clickType: Integer);
var
o: TPoint;
begin
if not InRange(clickType, 1, 3) then
begin
srl_Warn('MouseOval', 'ClickType is NOT a valid number!', warn_AllVersions);
exit;
end;
o.y := Random(my) * ((Random(2) * 2) - 1);
o.x := Random(Round(Sqrt(Sqr(my) - Sqr(o.y)) * mx / my)) * ((Random(2) * 2) - 1);
case clickType of
1,2: Mouse(cx + o.x, cy + o.y, 0, 0, clickType = 1);
3: MMouse(cx + o.x, cy + o.y, 0, 0);
end;
end;The shorter code is less accurate (will throw the odd point that is 1 pixel out of a "perfect" ellipse) but won't be any more off than that.
Short description: cx and cy are centre x/y values, mx and my max x/y offset in either direction, clickType follows MouseBox rules of 1 for left click, 2 for right click, 3 for move only (at least I hope it does).
NO, N2, BAD BOY