LordGregGreg
2007-06-15 17:25:37
From: hugolord
w00t first post after your new function testing now !
Alright, here is a tutorial thingy on how to use my new function
GregAlign(color, tol, keyPoints, x1, y1, x2, y2: Integer;
horizontal: Boolean)
Dont know what all of tghat means? well, then here is a tutorial picture to help you out!
and
function GregAlign(color, tol, keyPoints, x1, y1, x2, y2: Integer;
horizontal: Boolean): Boolean;
//Needs the color of the line (should be sorta horisontal already), the tolerance of the line color,
//how many key point you want to use (3-4 shold be good) , the rectance the line is in, and whether is a horizontal line or not
//Note, i havnt made the adjustment to vertitcle lines yet :P
var
j, i, dist, origy, here, origx, globalTries, pointtotest, distchange: Integer;
xkeyPoint: array[0..20] of Integer;
ykeyPoint: array[0..20] of Integer;
points: array of TPoint;
slope: double;
begin
Result := False;
origy := y1;
origx := x1;
here := 0;
globaltries := 0;
if (horizontal) then
begin
dist := (x2 - x1) DIV (keyPoints);
//FindColorsAbstract( points,color, tol, x1, y1, x2, y2,
//x3, y3, x4, y4);
//SimilarColors(col1, col2, tolerance: integer): Boolean;
//function GetColor(x,y: Integer): Integer;
repeat
globaltries := globaltries + 1;
y1 := origy;
x1 := origx;
here := 0;
repeat
//if(SimilarColors(color,getColor(x1,y1),tol);
x1 := x1 + 1;
y1 := origy;
repeat
y1 := y1 + 1;
if (SimilarColors(color, getColor(x1, y1), tol)) then
begin
Greg('Similar color...x is: ' + IntToStr(x1) + 'y is :' + IntToStr(y1));
xkeyPoint[here] := x1;
ykeyPoint[here] := y1;
here := here + 1;
x1 := x1 + dist;
break;
//Greg('Found one');
end;
until (y1 >= y2)
until (x1 >= x2);
Greg('we have recieved ' + IntToStr(here) + ' points to wokr with');
Greg('taking the first and last to calculate (y) slope...');
if ((xkeyPoint[here - 1] - xKeyPoint[0]) = 0) then
begin
Greg('wrong!');
end
else
begin
slope := (ykeyPoint[here - 1] - yKeyPoint[0]) DIV
(xkeyPoint[here - 1] - xKeyPoint[0]);
end;
//Greg('the slope is: '+inttostr(slope));
writeln('y is ' + IntToStr(ykeypoint[here - 1]) + ' and y1 is ' +
IntToStr(ykeypoint[0]) + 'the slope is ' + floattostr(slope));
Greg('verifying slope with third point to make sure its not stupid');
pointtotest := 1 + random(here - 1);
y1 := ykeyPoint[pointtotest];
x1 := xkeyPoint[pointtotest];
distchange := x1 - xkeypoint[0];
Greg('x1 is ' + IntToStr(x1) + ' and x is dist change is ' + IntToStr(distchange));
if ((ykeypoint[0] + (slope * distchange)) = y1) then
begin
Greg('the slope is not bogus');
if (slope > 0) then
begin
Greg('the slope is biger then zero, rotate left');
KeyDown(VK_LEFT);
wait(50 + Random(50));
KeyUp(VK_LEFT);
wait(500 + Random(500));
end;
if (slope < 0) then
begin
Greg('the slope is less than zero, rotate right');
KeyDown(VK_RIGHT);
wait(50 + Random(50));
KeyUp(VK_RIGHT);
wait(500 + Random(500));
end;
if (slope = 0) then
begin
Greg('we fixed the angle perfectly');
globaltries := 100000;
Result:=true;
end;
end
else
begin
Greg('bogus slope');
end;
until (globaltries > 20);
Greg('exited');
end;
end;Edit: you can see it used in my current realse
Ill atach it for you, but the most updated one will be at
http://www.villavu.com/forum/showthread.php?t=11265
cheers!