SRL Archive - Help and Support

New MouseCircle procedure


Nebula

2012-03-20 21:14:18

Basically Iv'e been working on a fix to the MouseCircle Procedure (it doesn't work anymore).

The code I wrote below only clicks the circumference of the circle, I haven't been able to figure out how to get it to click within the area.

Does anyone know how I could get this to work? [use paint to test it]

program MouseCirclee;
{$i srl/srl.simba}

Procedure MouseCircle2(midx, midy, Radius: integer; button: variant);
var
x, y: Variant;
begin
x := RandomRange((midx - Radius), (midx + Radius + 1));
case Random(2) of
0: y := Round(sqrt(sqr(Radius) - sqr(x-midx)) + midy); //bottom half of circle
1: y := midy + (midy - (Round(sqrt(sqr(Radius) - sqr(x-midx)) + midy))); //top half of circle
end;
writeln(x);
writeln(y);
Mouse(x, y, 0, 0, Button);
end;

begin
repeat
SetupSRL;
activateclient;
Mousecircle2(100, 100, 15, true);
wait(600);
until(false);
end.

Nebula

mixster

2012-03-20 21:53:42

Are you sure it's broken? The code shouldn't have been changed - since it definitely worked - and it's mainly just an awesome equation (though I'm a little biased.)

You can simplify it since a circle is a mirror image at all angles, so rather than doing something complicated about top-half, bottom-half, just get a y value that's a distance from the centre and then randomly add it or subtract it, meaning you'll only need one mathematical line to get the y-offset value-y thing.

Procedure MouseCircle2(midx, midy, Radius: integer; button: variant);
var
x, y: Integer;
begin
x := RandomRange((midx - Radius), (midx + Radius + 1));
y := Round(Sqrt(Sqr(Radius) - Sqr(x - midx)));
case Random(2) of
0: y := midy + y;
1: y := midy - y;
end;
writeln(x);
writeln(y);
Mouse(x, y, 0, 0, Button);
end;

The problem is pretty clear now - y holds the maximum y value for a particular x value (making the point (x,y) always on the circumference,) so what you really want to do is y := Random(y + 1); to make y a value inside the circle, up to and including the circumference (or just Random(y) to not include the circumference.) You can combine this with the y := Round etc or make it part of the case or put it wherever else you want, though putting it somewhere silly would probably not fix the problem :)

Nebula

2012-03-20 22:09:37

It worked, thanks.
This is what I had to end up adding:

y := RandomRange(midy, y+ 1);