[Bill Williams 22 May 02 CST 20:00]
Attached is the source code of a cleaned up version of the Ass and three
haystacks program. All that the modifed version Ass_2.pas does is to
demonstrate the effect of changing the gain of the three loops by increasing
the gain for haystack number 1 and decreasing the gain for haystacks 2 and 3.
To prevent the program from exploding as a result of loop one becoming unstable
as a result of excessive gain, the slowing factor is increased proportionately
for loop 1.
When running the program pressing any key will increase the gain for loop one
by a factor of 4 and _decrease_ the gain for loops 2 and 3 also by a factor of
4.
Bill Powers, earlier today, has suggested another method of shifting the gain.
Achiving stablity the way I've done it seems to result in the program becoming
rather slugish.
Bill Williams
···
______________________________________________________________________
Do you want a free e-mail for life ? Get it at http://www.email.ro/
program ASS_2; (* 23 May 02 *)
uses dos, crt, graph, grutils;
var
(*
c, count : integer;
*)
key : char;
textN : string;
Xa, Ya, X1, Y1, X2, Y2, X3, Y3, Xs1, Xs2, Xs3, Ys1, Ys2, Ys3 : real;
Ex1, Ex2, Ex3, Ey1, Ey2, Ey3, Rx1, Rx2, Rx3, Ry1, Ry2, Ry3 : real;
ix1, ix2, ix3, iy1, iy2, iy3, gx1, gx2, gx3, gy1, gy2, gy3 : real;
ox1, ox2, ox3, oy1, oy2, oy3, sx1, sx2, sx3, sy1, sy2, sy3 : real;
a, s, g, oEx1, oEx2, oEx3, oEy1, oEy2, oEy3 : real;
Begin (* main *)
initgraphics;
Xa := 0; Ya := - 40;
X1 := 200; Y1 := - 140;
X2 := - 200; Y2 := - 140;
X3 := 0; Y3 := + 140;
Ix1 := 0; Ix2 := 0; Ix3 := 0;
Iy1 := 0; Iy2 := 0; Iy3 := 0;
Rx1 := 200; Rx2 := -200; Rx3 := 0;
Ry1 := -140; Ry2 := -140; Ry3 := +140;
a := 50; sx1 := a; sx2 := a; sx3 := a; sy1 := a; sy2 := a; sy3 := a;
a:= 1; gx1 := a; gx2 := a; gx3 := a; gy1 := a; gy2 := a; gy3 := a;
repeat
setcolor(yellow);
line(round(Xa + 320), round(Ya + 240 ),round(x1 + 320),round(y1 + 240 ));
line(round(Xa + 320 ),round(Ya + 240),round(x2 + 320),round(y2 + 240 ));
line(round(Xa + 320 ),round(Ya+ 240 ),round(x3 + 320),round(y3+ 240 ));
setcolor(lightblue);
circle(round(Xa + 320 ),round(Ya + 240 ),10);
setcolor(lightred);
circle(round(X1 + 320),round(Y1 + 240 ),5);
circle(round(X2 + 320),round(Y2 + 240),5);
circle(round(X3 + 320),round(Y3 + 240),5);
setcolor(lightgray);
outtextxy(round(X1 + 335),round(y1 + 240),'1');
outtextxy(round(X2 + 305),round(y2+ 240),'2');
outtextxy(round(X3 + 320),round(y3 + 20+ 240),'3');
if keypressed then key := readkey;
outtextxy(5,450,'press q to exit program');
delay(30);
setcolor(black);
circle(round(Xa+ 320),round(Ya + 240),10);
line(round(Xa + 320 ),round(Ya + 240 ),round(x1 + 320 ),round(y1 + 240 ));
line(round(Xa + 320 ),round(Ya + 240 ),round(x2 + 320),round(y2 + 240 ));
line(round(Xa + 320),round(Ya + 240 ),round(x3 + 320),round(y3 + 240));
if keypressed then
begin
a := 4 ;
gx1 := gx1 * a;
gy1 := gy1 * a;
sx1 := sx1 * a;
sy1 := sy1 * a;
gx2 := gx2/a;
gy2 := gy2/a;
gx3 := gx3/a;
gy3 := gy3/a;
end;
Ex1 := Rx1 - Xa;
Ix1 := Gx1 * Ex1;
Ox1 := Ox1 + ( Ix1 - Ox1 )/Sx1;
Ex2 := Rx2 - Xa;
Ix2 := Gx2 * Ex2;
Ox2 := Ox2 + ( Ix2 - Ox2 )/Sx2;
Ex3 := Rx3 - Xa;
Ix3 := Gx3 * Ex3;
Ox3 := Ox3 + ( Ix3 - Ox3 )/Sx3;
Ey1 := Ry1 - ya;
Iy1 := Gy1 * Ey1;
Oy1 := Oy1 + ( Iy1 - Oy1 )/Sy1;
Ey2 := Ry2 - ya;
Iy2 := Gy2 * Ey2;
Oy2 := Oy2 + ( Iy2 - Oy2 )/Sy2;
Ey3 := Ry3 - ya;
Iy3 := Gy3 * Ey3;
Oy3 := Oy3 + ( Iy3 - Oy3 )/Sy3;
Xa := Ox1 + Ox2 + Ox3;
Ya := Oy1 + Oy2 + Oy3;
until key in [ 'q','Q']; (* end of repeat loop *)
closegraph;
end.