Program calculate RLC circuit with graphics view

Delphi & Pascal (česká wiki)
Přejít na: navigace, hledání
Category: KMP (Club of young programmers)

Author: Ján Benkovič
web: www.tbteacher.host.sk

Program: Rlc-graf.pas

Program calculate RLC circuit with graphics view.
{ RLC-GRAF.PAS                           Copyright (c) Jan Benkovic }
{ Program na vypocet RLC obvodov s grafickym zobrazenim.            }
{                                                                   }
{ Datum:17.03.2000                             http://www.trsek.com }
 
uses crt,graph;
 
var
 gd,gm : integer;
 f,x,R : longint;
 c,l   : real;
 
function Xl(f:integer):longint;
 begin
  xl:=round(2*PI*f*L);
 end;
 
function Xc(f:integer):longint;
 begin
  Xc:=round(1/(2*PI*f*C));
 end;
 
function Z:longint;
 begin
  Z:=round(sqrt(sqr(R)+sqr(Xl(f)+Xc(f))));
 end;
 
procedure getgraph;
 begin
  detectgraph(gd,gm);
  initgraph(gd,gm,'');
  setcolor(green);
  outtextxy(1,1,'R');
  setcolor(red);
  outtextxy(1,11,'Xl');
  setcolor(blue);
  outtextxy(1,21,'Xc');
  setcolor(yellow);
  outtextxy(1,31,'Z');
 end;
 
begin
 Write('Napis R : ');
 read(R);
 Write('Napis C : ');
 read(C);
 Write('Napis L : ');
 read(L);
 getgraph;
 
 x:=0;
 f:=1;
 repeat
  putpixel(f+10,getmaxy-Xl(f)-20,red);
  putpixel(f+10,getmaxy-R-20,green);
  putpixel(f+10,getmaxy-Xc(f)-20,blue);
  putpixel(f+10,getmaxy-Z-20,yellow);
  f:=f+1;
 until f=400;
 readkey;
end.