A négyütemű Otto-motor működő
modellje
Készítsük el a négyütemű Otto-motor
működő modelljét. A motornak négy hengere legyen. Az egyes fázisokat a hengerek
alatt feliratozzuk. Minden hengerben legyen két szelep és egy gyertya. A
szelepek a működési fázisnak megfelelően nyíljanak és záródjanak. A főtengelyt
körökkel érzékeltessük, melynek kerületéről indulnak ki a hajtókarok.
Az animációt egy Start feliratú gombbal lehessen
elindítani és egy Stop feliratúval lehessen megállítani. Legyen lehetőség a
motor fordulatszámának változtatására.
A program futtatási képe:
A program listája:
unit UMotor;
interface
uses
Windows, Messages, SysUtils, Variants, Classes,
Graphics, Controls, Forms, Dialogs, StdCtrls, ExtCtrls;
type
TfmMotor = class(TForm)
btStart: TButton;
btKilepes: TButton;
tiIdozito: TTimer;
btStop: TButton;
btVP: TButton;
btVM: TButton;
edSeb: TEdit;
procedure FormCreate(Sender: TObject);
procedure btKilepesClick(Sender: TObject);
procedure FormPaint(Sender: TObject);
procedure tiIdozitoTimer(Sender: TObject);
procedure btStartClick(Sender: TObject);
procedure btStopClick(Sender: TObject);
procedure btVPClick(Sender: TObject);
procedure btVMClick(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
THenger= Object
Fx, Fy, Fd, Fs: Real;
Fc: TColor;
X, Y, D, R, T: Integer;
Mf: Integer;
Procedure Init(Ix, Iy, Id: Real);
Procedure SetFazis(ISz: Real);
Function GetSzog: Integer;
Function GetMFazis: Integer;
Procedure SetColor(Ic: TColor);
Procedure FrameDraw;
Procedure Show;
Procedure Hide;
End;
Const HSz=4;
Sd=5;
var
fmMotor: TfmMotor;
Xm, Ym: Integer;
Ht: Array[1..HSz] Of THenger;
F: Integer;
Animacio: Boolean;
implementation
{$R *.dfm}
Procedure THenger.Init(Ix, Iy, Id: Real);
Begin
Fx:= Ix; Fy:= Iy; Fd:= Id;
X:= Round(FX*Xm); Y:= Round(FY*Ym); D:= Round(FD*Xm);
R:= Round(0.4*D);
End;
Procedure THenger.SetFazis(ISz:Real);
Begin
Fs:= ISz;
T:= Round(R*Sin(FS*Pi/180));
Case Round(FS) Of
0..89: Mf:=1;
90..269: Mf:=2;
270..449: Mf:=3;
450..629: Mf:=4;
630..719: Mf:=1;
End;
End;
Function THenger.GetSzog:Integer;
Begin
GetSzog:= Round(Fs);
End;
Function THenger.GetMFazis: Integer;
Begin
GetMFazis:= Mf;
End;
Procedure THenger.SetColor(Ic: TColor);
Begin
Fc:= Ic;
End;
Procedure THenger.FrameDraw;
Begin
With fmMotor.Canvas Do
Begin
{henger}
Pen.Width:= 2;
Moveto(X, Round(Y+1.8*D));
LineTo(X, Y);
LineTo(Round(X+0.05*D), Round(Y-0.05*D));
Lineto(Round(X+0.95*D), Round(Y-0.05*D));
LineTo(X+D, Y);
LineTo(X+D, Round(Y+1.8*D));
{gyertya}
Pen.Width:= 5;
MoveTo(Round(X+0.5*D), Round(Y-0.15*D));
LineTo(Round(X+0.5*D), Y);
{szelepek}
Pen.Width:= 3;
MoveTo(Round(X+0.1*D), Round(Y-0.05*D));
LineTo(Round(X+0.3*D), Round(Y-0.05*D));
MoveTo(Round(X+0.2*D), Round(Y-0.25*D));
LineTo(Round(X+0.2*D), Round(Y-0.05*D));
MoveTo(Round(X+0.7*D), Round(Y-0.05*D));
LineTo(Round(X+0.9*D), Round(Y-0.05*D));
MoveTo(Round(X+0.8*D), Round(Y-0.25*D));
LineTo(Round(X+0.8*D), Round(Y-0.05*D));
Pen.Width:= 1;
{főtengely}
Arc(Round(X+D*0.5)-R, Round(Y+2.8*D)-R,
Round(X+D*0.5)+R, Round(Y+2.8*D)+R,
Round(X+D*0.5)-R, Round(Y+2.8*D),
Round(X+D*0.5)-R, Round(Y+2.8*D));
End;
End;
Procedure THenger.Show;
Begin
With fmMotor.Canvas Do
Begin
Pen.Color:= Fc;
Rectangle(Round(X+0.02*D), Round(Y+0.1*D+0.5*D+T),
Round(X+D-0.02*D), Round(Y+0.7*D+0.5*D+T));
MoveTo(Round(X+D*0.5),Round(Y+2.8*D));
LineTo(Round(X+D*0.5+R*Cos(FS*Pi/180)),Round(Y+2.8*D+R*Sin(FS*Pi/180)));
MoveTo(Round(X+D*0.5),Round(Y+D*0.7+0.5*D)+T);
LineTo(Round(X+D*0.5+R*Cos(FS*Pi/180)),Round(Y+2.8*D+R*Sin(FS*Pi/180)));
Font.Size:= 12;
If ((GetSzog-90) Mod 180)=0 Then
Begin
{aláírás, szelepek}
Pen.Width:= 3;
Case GetMFazis of
1: Begin
Pen.Color:= clBtnFace;
Brush.Color:= clBtnFace;
Rectangle(Round(X+0.1*D),Round(Y-0.25*D),
Round(X+0.305*D),Round(Y+0.06*D));
Rectangle(Round(X+0.7*D),Round(Y-0.25*D),
Round(X+0.905*D),Round(Y+0.06*D));
Pen.Color:= clBlack;
MoveTo(Round(X+0.1*D), Round(Y+0.05*D));
LineTo(Round(X+0.3*D), Round(Y+0.05*D));
MoveTo(Round(X+0.2*D), Round(Y-0.15*D));
LineTo(Round(X+0.2*D), Round(Y+0.05*D));
MoveTo(Round(X+0.7*D), Round(Y-0.05*D));
LineTo(Round(X+0.9*D), Round(Y-0.05*D));
MoveTo(Round(X+0.8*D), Round(Y-0.25*D));
LineTo(Round(X+0.8*D), Round(Y-0.05*D));
TextOut(Round(X+0.3*D), Round(Y+3.3*D), 'Szívás ')
End;
2: Begin
Pen.Color:= clBtnFace;
Brush.Color:= clBtnFace;
Rectangle(Round(X+0.1*D), Round(Y-0.25*D),
Round(X+0.305*D), Round(Y+0.06*D));
Pen.Color:= clBlack;
MoveTo(Round(X+0.1*D), Round(Y-0.05*D));
LineTo(Round(X+0.3*D), Round(Y-0.05*D));
MoveTo(Round(X+0.2*D), Round(Y-0.25*D));
LineTo(Round(X+0.2*D), Round(Y-0.05*D));
TextOut(Round(X+0.3*D), Round(Y+3.3*D), 'Sűrítés ');
End;
3: TextOut(Round(X+0.3*D), Round(Y+3.3*D), 'Munkaütem ');
4: Begin
Pen.Color:= clBtnFace;
Brush.Color:= clBtnFace;
Rectangle(Round(X+0.1*D), Round(Y-0.25*D),
Round(X+0.305*D), Round(Y+0.06*D));
Rectangle(Round(X+0.7*D), Round(Y-0.25*D),
Round(X+0.905*D), Round(Y+0.06*D));
Pen.Color:= clBlack;
MoveTo(Round(X+0.1*D), Round(Y-0.05*D));
LineTo(Round(X+0.3*D), Round(Y-0.05*D));
MoveTo(Round(X+0.2*D), Round(Y-0.25*D));
LineTo(Round(X+0.2*D), Round(Y-0.05*D));
MoveTo(Round(X+0.7*D), Round(Y+0.05*D));
LineTo(Round(X+0.9*D), Round(Y+0.05*D));
MoveTo(Round(X+0.8*D), Round(Y-0.15*D));
LineTo(Round(X+0.8*D), Round(Y+0.05*D));
TextOut(Round(X+0.3*D), Round(Y+3.3*D), 'Kipufogás ');
End;
End;
Pen.Width:= 1;
End;
Arc(Round(X+D*0.5)-R, Round(Y+2.8*D)-R,
Round(X+D*0.5)+R, Round(Y+2.8*D)+R,
Round(X+D*0.5)-R, Round(Y+2.8*D),
Round(X+D*0.5)-R, Round(Y+2.8*D));
End;
End;
Procedure THenger.Hide;
Begin
SetColor(clBtnFace);
Show;
SetColor(clBlack);
End;
procedure TfmMotor.btKilepesClick(Sender: TObject);
begin
Close;
end;
procedure TfmMotor.FormCreate(Sender: TObject);
begin
Xm:= ClientWidth;
Ym:= ClientHeight;
Animacio:= False;
edSeb.Text:= IntToStr(tiIdozito.Interval);
end;
procedure TfmMotor.FormPaint(Sender: TObject);
Const Xt: Array[1..4] Of Real= (0.1,0.3,0.5,0.7);
Ft: Array[1..4] Of Integer= (0,540,180,360);
Var I: Word;
begin
For I:= 1 to HSz Do With HT[i] Do
Begin
Init(Xt[I],0.1,0.18); F:= Ft[I]; SetFazis(F); SetColor(clBlack);
FrameDraw; Show;
End;
end;
procedure TfmMotor.tiIdozitoTimer(Sender: TObject);
Var I: Word;
begin
If Not Animacio Then Exit;
For I:= 1 To HSz Do With HT[I] do
Begin
Hide;
F:= GetSzog; Inc(F, Sd); F:= F Mod 720; SetFazis(F);
Show;
End;
end;
procedure TfmMotor.btStartClick(Sender: TObject);
begin
Animacio:= True;
end;
procedure TfmMotor.btStopClick(Sender: TObject);
begin
Animacio:= False;
end;
procedure TfmMotor.btVPClick(Sender: TObject);
Var V: Word;
begin
With tiIdozito Do
Begin
V:= Interval; If V>1 Then Dec(V); Interval:= V;
edSeb.Text:= IntToStr(Interval);
End;
end;
procedure TfmMotor.btVMClick(Sender: TObject);
Var V: Word;
begin
With tiIdozito Do
Begin
V:= Interval; Inc(V); Interval:= V;
edSeb.Text:= IntToStr(Interval);
End;
end;
end.