program Pendulum;
{$N+}
uses crt, graph;
const
x2 : word = 0;
y2 : word = 0;
type
TPendulum = object
public
constructor Init(xC, yC, len, radius : word; min, max : single);
destructor Done;
function GetX(a : single) : word;
function GetY(a : single) : word;
function GetAngle : single;
procedure Show;
procedure Hide;
procedure Next;
private
x0, y0 : word;
l, r, x, y, c : word;
minAngle, maxAngle, angle : single;
end;
constructor TPendulum.Init(xC, yC, len, radius : word; min, max : single);
begin
x2 := GetMaxX div 2;
y2 := GetMaxY div 2;
minAngle := min;
maxAngle := max;
angle := minAngle;
l := len;
r := radius;
c := 5;
if (x = 0) and (y = 0) then begin
x0 := x2;
y0 := 0;
end else begin
x0 := xC;
y0 := yC;
end;
end;
destructor TPendulum.Done;
begin
writeln('Bye ...');
end;
function TPendulum.GetX(a : single) : word;
begin
GetX := round(l * cos(a)) + x0;
end;
function TPendulum.GetY(a : single) : word;
begin
GetY := round(l * sin(a)) + y0;
end;
function TPendulum.GetAngle : single;
const
step : single = 0.5;
begin
if (angle > maxAngle) or (angle < minAngle) then begin
sound(7);
nosound;
step := -step;
if angle > maxAngle then
minAngle := minAngle + c
else
maxAngle := maxAngle - c;
end;
angle := angle + step;
GetAngle := angle * PI / 180;
end;
procedure TPendulum.Next;
var
a : single;
begin
a := GetAngle;
x := GetX(a);
y := GetY(a);
end;
procedure TPendulum.Show;
begin
SetColor(White);
line(x0, y0, x, y);
circle(x, y, r);
end;
procedure TPendulum.Hide;
begin
SetColor(Black);
line(x0, y0, x, y);
circle(x, y, r);
end;
var
gd, gm : integer;
p : TPendulum;
begin
gd := detect;
initgraph(gd, gm, 'c:\bp7\bgi');
p.Init(GetMaxX div 2, GetMaxY div 2, 200, 20, 45, 135);
repeat
p.Hide;
p.Next;
p.Show;
delay(10);
until keypressed or (p.minAngle > p.maxAngle);
repeat until keypressed;
p.Done;
CloseGraph;
end.
{$N+}
Uses Graph,Crt;
Type type_mayat=record {tip mayatnika}
DlinaNiti:real;
MassaNiti:real;
MassaSharika:real;
RadiusSharika:real;
a_begin,a_new,a_old:real;
J,w0:real;
end;
Var
p_menu:pointer;
Var T, curr_t: Integer;
main_mayat:type_mayat; {Maytnik}
dT,fT,g,b:real;{Shag po vremeni, Polnoe vremya, g, koef triniya}
tmp_1:integer; {svobodnie peremennie}
tmp_2,tmp_3,tmp_4,tmp_5:real;{svobodnie peremennie}
Key:char;
graphtmp2,graphtmp3:integer; {graficheskie peremenie}
Procedure GraphOn; {vklyuchenie graphiki}
Var
Gd,Gm,ErrorCode:integer;
Begin
Gd:=detect;
initgraph(Gd,Gm,'d:\pascal\bgi');
ErrorCode:=GraphResult;
if ErrorCode <> grOk then
begin
WriteLn('oshibka:');
WriteLn(GraphErrorMsg(ErrorCode));
Halt(1);
end;
End;
Procedure GraphOff;{Otklu4enie graphiki}
Begin
CloseGraph;
End;
Procedure mayatnik(DlinaNiti_:integer;
MassaNiti_,MassaSharika_,RadiusSharika_,a_begin_:real);
Begin
with main_mayat do
begin
DlinaNiti:=DlinaNiti_;
MassaNiti:=MassaNiti_;
MassaSharika:=MassaSharika_;
RadiusSharika:=RadiusSharika_;
a_begin:=a_begin_;
a_new:=a_begin_;
J:=(1/3)*MassaNiti*sqr(DlinaNiti)+MassaSharika*(2/5*sqr(RadiusSharika)+sqr(DlinaNiti));
w0:=sqrt(g*(MassaSharika*DlinaNiti+MassaNiti*DlinaNiti/2)/J);
{vi4islenie sobstvennoi 4astoti}
end;
End;
Procedure dvizh_mayat; {phizika mayatnika}
Var
costmp:double;
Begin
with main_mayat do
begin
a_old:=a_new;
a_new:=a_begin*cos(w0*fT);{novii ugol mayatnika}
if a_begin>0 then
begin
costmp:=cos(a_begin)+(b*DlinaNiti*sqr(a_new-a_old))/(dT*MassaSharika*g);
{vi4islenie novogo cos ugla amplitudi}
if (costmp<>0) then
a_begin:=arctan(sqrt(1-sqr(costmp))/costmp);
{vi4islenie novoi amplitudi}
end
else a_begin:=0;
fT:=fT+dT;
end;
End;
Procedure ris_mayat; {risovanie mayatnika}
Var
xNow,yNow:real;
Begin
with main_mayat do
begin
xNow:=graphtmp2+DlinaNiti*cos(a_new-pi/2);
yNow:=21-DlinaNiti*sin(a_new-pi/2);
setfillstyle(0,0);
bar(graphtmp2-round(DlinaNiti+RadiusSharika),21,
graphtmp2+round(DlinaNiti+RadiusSharika),21+round(DlinaNiti+RadiusSharika));
setcolor(7);
setlinestyle(0,0,3);
line(graphtmp2,21,round(xNow),round(yNow));
setlinestyle(0,0,1);
setcolor(1);
setfillstyle(1,1);
fillellipse(round(xNow),round(yNow),
round(RadiusSharika),round(RadiusSharika));
end;
End;
Begin
GraphOFF;
writeln('vvedite dlinu niti (recom. 250)');
readln(tmp_1);
writeln('vvedite massu niti (recom. 20)');
readln(tmp_2);
writeln('vvedite massu sharika (recom. 30)');
readln(tmp_3);
writeln('vvedite radis sharika (recom. 15)');
readln(tmp_4);
writeln('vvedite ugol otklonenia (recom. 0.5)');
readln(tmp_5);
writeln('vvedite shag po vremeni (recom. 0.1)');
readln(dT);
GraphOn;
b:=0.1;
fT:=0;
Key:=#0;
g:=9.8;
GraphOn;
graphtmp2:=round(getmaxx/2);
graphtmp3:=round(getmaxx/3);
cleardevice;
mayatnik(tmp_1,tmp_2,tmp_3,tmp_4,tmp_5);
setcolor(15);
setfillstyle(3,15);
bar(graphtmp3,0,2*graphtmp3,20);
line(graphtmp3,20,2*graphtmp3,20);
repeat
if(main_mayat.a_begin<>0)then
begin
dvizh_mayat;
ris_mayat;
delay(500);
inc(T); if T = 10 then begin
T := 0; inc(curr_t);
putpixel(curr_t,
(getmaxy - 240) + trunc(180 * cos(main_mayat.a_new)),
red );
end;
end;
if keypressed then key:=readkey;
until (key=#27);
GraphOff;
End.
М | Murderer, убери пустые строки! Нечитабельно. Я начал убирать, ты закончи.. Lapp |