Eugeniusz Jakubas
programy źródłowe w Pascalu

Stąd można pobrać teksty źródłowe poniższych 57 programów w Pascalu pr-pascal.zip - 34 kB

35. Styczna

Program Styczna;
uses graph;
var karta,tryb,n:integer;
    skala,xp,yp,ip,ips:longInt;
    x,y,x0,y0,krok,h:real;
    xS,yS:string;
function f(x:real):real;
begin
  f:=x*x-4*x-2;
end;
procedure osie;
begin
 setColor(darkGray);setLineStyle(1,0,1);
 for n:=0 to 30 do line(xp mod ip+n*ip,0,xp mod ip+n*ip,380);
 for n:=0 to 22 do line(0,yp mod ip+n*ip,510,yp mod ip+n*ip);
 setLineStyle(0,0,1);
 for n:=0 to 2*(15 div skala) do
     line(xp mod ips+n*ips,0,xp mod ips+n*ips,380);
 for n:=0 to 2*(11 div skala) do
     line(0,yp mod ips+n*ips,510,yp mod ips+n*ips);
 rectangle(0,0,510,380);setColor(lightGray);setLineStyle(0,0,3);
 line(0,yp,510,yp);line(500,yp-5,508,yp);line(500,yp+5,508,yp);
 line(xp,0,xp,380); line(xp-5,10,xp,2); line(xp+5,10,xp,2);
 str(-16/skala+x0:2:4,xS); outTextXY(3,198,xS);
 str(16/skala+x0:2:4,xS);outTextXY(510-8*length(xS),198,xS);
 str(-12/skala+y0:2:4,yS); outTextXY(260,370,yS);
 str(12/skala+y0:2:4,yS); outTextXY(264,5,yS);
end;
procedure wykres;
begin
  x:=-16/skala+x0; krok:=0.005/skala;
  repeat
    x:=x+krok;
    y:=-f(x)*ips+yp;
    if (y>0) and (y<380) then
       putPixel(round(x*ips+xp),round(y),lightcyan);
    if x<x0 then h:=-0.0001/skala else h:=0.0001/skala;
    putPixel(round(x*ips+xp),
      round(-((f(x0+h)-f(x0))/h*(x-x0)+f(x0))*ips+yp),lightRed);
  until x>16/skala+x0;
  setColor(yellow);circle(255,190,2);
  str(x0:2:4,xS);str(y0:2:4,yS);
  outTextXY(260,200,'A ('+xS+', '+yS+')');
end;
begin
  karta:=vga; tryb:=vgaHi; initgraph(karta,tryb,'c:\tp\bgi');
  skala:=1; ip:=16; ips:=ip*skala;
  x0:=3; xp:=round(255-x0*ips);
  y0:=f(x0); yp:=round(190+y0*ips);
  osie; wykres;
  readln; closegraph;
end.