1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74
|
program Decharge_electrique;
uses crt,graph;
const c=180/pi;
dl=3;
eps=5;
Function Atn(x:real):real;
Var ordre:integer; S,c:real;
Begin
ordre:=21; {Imprativement impair}
c:=x*x;
S:=1/ordre;
While ordre>1 do Begin
ordre:=ordre-2;
S:=-c*S+1/ordre;
end;
Atn:=x*S;
end;
Function Arctan(x:real):real;
Var y:real;
begin
If abs(x)<1 then arctan:=atn(x)
else if x>0 then begin
y:=(x-1)/(x+1);
Arctan:=pi/4+Atn(y);
end
else begin
y:=(-x-1)/(-x+1);
Arctan:=-pi/4-Atn(y);
end;
end;
Function Puissance(x:real;n:integer):real;
Begin
If n=0 then Puissance:=1
else if odd(n) then Puissance:=x*Puissance(x,n-1)
else Puissance:=sqr(Puissance(x,n div 2));
end;
var ch:char;
x1,y1,x2,y2,x,y,gd,gm,x01,x02,y01,y02:integer;
distance,angle:real;
begin
gd:=detect;
initgraph(gd,gm,'c');
randomize;
x01:=5+random(50);y01:=random(479);
x02:=639-x01;y02:=random(479);
line(x01,y01,x01,y01);line(x02,y02,x02,y02);
while not (ch='s') do begin
x1:=x01;y1:=y01;
x2:=x02;y2:=y02;
randomize;
distance:=sqrt(abs(x2-x1)+abs(y2-y1));
while distance>eps do
begin
if x1=x2 then exit;
angle:=round(arctan((y2-y1)/(x2-x1))*c)+random(220)-90;
x:=x1+round(dl*cos(angle/c));
y:=y1+round(dl*sin(angle/c));
line(x1,y1,x,y);
x1:=x;
y1:=y;
distance:=sqrt(abs(x2-x1)+abs(y2-y1));
end;
ch:=readkey;
end;
closegraph;
end. |
Partager