SRL Archive - SRL Archives

Uhm, MouseOval


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.

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

Nava2

2009-10-14 11:39:13

Cool, just how is it useful..?

(Added Feedback tag)

mixster

2009-10-14 11:41:48

No idea at all, but if MouseCircle is in, then I see that any reason it has MouseOval has too. I didn't submit until now as I couldn't really think of any use since people usually use M/Mouse with such small numbers that it makes virtually no difference, but meh

Narcle

2009-10-14 13:21:34

I was looking at your TPA oval thing on the other thread. I just thought of something that might actually be useful from this.

If you made like a TPAtoATPAOval search I think that could be usable. So it returns an array of oval tpas.

Now theres a challange. ;)

mormonman

2009-10-14 14:15:09

From: mixster
Side note: I like penis.


Me guesses that Nava added this?

Dan Cardin

2009-10-14 14:42:14

Oval = ellipse = MouseEllipse_ ?

mixster

2009-10-14 15:07:11

MouseEllipse would work too, but MouseOval is shorter, less confusing (double e for eek) and ovals has a v in it (v's are cool).

From: Narcle
I was looking at your TPA oval thing on the other thread. I just thought of something that might actually be useful from this.

If you made like a TPAtoATPAOval search I think that could be usable. So it returns an array of oval tpas.

Now theres a challange. ;)


So like TPAToATPA/Ex, except TPA's in an ellipse rather than circle or square? I could have a go at the least :)

Narcle

2009-10-14 15:08:51

From: mixster
MouseEllipse would work too, but MouseOval is shorter, less confusing (double e for eek) and ovals has a v in it (v's are cool).



So like TPAToATPA/Ex, except TPA's in an ellipse rather than circle or square? I could have a go at the least :)


Yep! Really you could use the regular TPAtoATPA/Ex and just filter it, but you would lose some points in the process.

Nava2

2009-10-14 15:22:04

From: mormonman
Me guesses that Nava added this?


nuh uh >.>

e: yes i did

mixster

2009-10-14 16:11:24

function TPAtoATPAOval(TPA: TPointArray; w, h: Integer): T2DPointArray;
var
a, b, c, l: LongInt;
r, m: Extended;
begin
r := h / w;
m := Sqr(w);

SetLength(Result, 0);
l := High(TPA);
c := 0;
for a := 0 to l do
begin
for b := 0 to c -1 do
if Sqr(Abs(TPA[a].X - Result[b][0].X)) + Sqr(Abs(TPA[a].Y - Result[b][0].Y) / r) <= m then
Break;
if (b < c) then
begin
SetLength(Result[b], Length(Result[b]) + 1);
Result[b][High(Result[b])] := TPA[a];
end else
begin
SetLength(Result, c + 1);
SetLength(Result[c], 1);
Result[c][0] := TPA[a];
Inc(c);
end;
end;
end;

Function DebugATPA(aPoints: T2DPointArray; bmp: integer): Boolean;

Var
Width, Height, I, L, Col: Integer;

Begin
Try
GetBitmapSize(bmp, Width, Height);

DisplayDebugImgWindow(0, 0);
DisplayDebugImgWindow(Width * 4, Height * 4);

For I := 0 To High(aPoints) Do
Begin
Col := Random(16777215);
For L := 0 To High(aPoints[i]) Do
FastSetPixel(bmp, aPoints[i][L].X, aPoints[i][L].Y, Col);
End;

//SafeDrawBitmap(bmp, GetDebugCanvas, 0, 0);
SafeCopyCanvas(GetBitmapCanvas(bmp), GetDebugCanvas, 0, 0, Width, Height, 0, 0, Width * 4, Height * 4);
DisplayDebugImgWindow(Width * 4, Height * 4);

Except
End;
Result := True;
End;

var
tpa: TPointArray;
tp2d: T2DPointArray;
t: Integer;
begin
Writeln('Begin');
tpa := TPAFromBox(IntToBox(0, 0, 50, 50));
tp2d := TPAtoATPAOval(tpa, 10, 20);
//tp2d := TPAtoATPA(tpa, 10);
t := BitmapFromString(50, 50, '');
DebugATPA(tp2d, t);
Writeln('End');
end.

Based upon TPAToATPAEx then modified so it should compile as plugin after adding stdcall to it.
I believe it gives the correct result (as you can see, was using TPAToATPA to ensure it was in the right ballpark). :)

EvilChicken!

2009-10-15 03:53:35

Can I just commit this?


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;

mixster

2009-10-15 13:51:57

If you want - first one was just an easier to read version and the TPAToATPAOval was just for sexy Narcle :)

Narcle

2009-10-15 16:38:58

Haha looks weird when u draw it. Naice mixster ;)

EvilChicken!

2009-10-15 16:52:05

Committed and modified MouseCircle to use your procedure.

Thanks, mixster. :)