GRAFIKA TP (ELEMENTY ANIMACJI)

 

Program przedstawia  wykresy funkcji trygonometrycznych sinus, cosinus, tangens.

 

program sinusik;

uses crt,graph;

var

st,tr,a,b,c:integer;

pi,x,y,wym:real;

d:char;

procedure sinus;

begin

wym:=50;

for a:=0 to 659 do

begin

x:=(a-319)/wym;

y:=sin(x);

y:=y*wym;

c:=round(y);

b:=239 -c ;

putpixel(a,b,3);

end;

end;

procedure cosinus;

begin

for a:=0 to 659 do

begin

x:=(a-319)/wym;

y:=cos(x);

y:=y*wym;

c:=round(y);

b:=239 -c ;

putpixel(a,b,7);

end;

end;

procedure tangens;

begin

for a:=250 to 400 do

begin

x:=(a-319)/wym;

y:=(sin(x)/cos(x));

y:=y*wym;

c:=round(y);

b:=239 -c ;

putpixel(a,b,14);

end;

end;

begin

initgraph(st,tr,'d:/tp/bgi');

line(0,239,639,239);

line(319,50,319,419);

settextstyle(3,0,3);

outtextxy(70,10,'WYKRES FUNKCJI y=sin(x), y=cos(x) i tg(x)');

setcolor(blue);

settextstyle(2,0,6);

 

outtextxy(400,400,'wykonal Stanislaw ZAWALNY');

setcolor(white);

outtextxy(325,52,'Y');

outtextxy(631,255,'X');

outtextxy(321,241,'0');

outtextxy(470,241,'PI');

outtextxy(615,241,'2PI');

outtextxy(150,241,'-PI');

outtextxy(325,180,'1');

outtextxy(325,283,'-1');

outtextxy(395,241,'0,5PI');

outtextxy(546,241,'1,5PI');

outtextxy(222,242,'-0,5PI');

outtextxy(75,241,'-1,5PI');

sinus;

cosinus;

tangens;

OUTTEXTXY(400,430,'nacisnij K aby zakoäczyc');

setcolor(3);

line(30,430,50,430);

outtextxy(60,420,'sin(x)');

setcolor(7);

line(30,450,50,450);

outtextxy(60,440,'cos(x)');

setcolor(14);

line(30,470,50,470);

outtextxy(60,460,'tg(x)');

d:=readkey;

case d of

'k':halt(1);

end;

readln;

closegraph;

end.

 

Program wykreśla wielokąt i wszystkie jego przekątne

 

program przekatne_wielokata;

uses crt,graph;

const m=40;

type wierzcholki=array [1..m,1..2] of real;

var n,xs,ys:integer;

    bok:real;

    w:wierzcholki;

 

procedure grafika;

var ster,tryb:integer;

begin

 ster:=detect;

 initgraph (ster,tryb,'d:\tp\bgi');

end;

 

procedure czytaj (var n:integer; var bok:real);

 begin

   repeat

     write ('Ile bokow:  ');

     readln (n);

   until (n>2) and (n<=m);

 

   repeat

     write ('Dlugosc boku:  ');

     readln (bok);

   until bok>0;

 end;

 

procedure wielokat (n:integer; bok:real; var w:wierzcholki);

var i:integer;

    r,alfa:real;

 begin

   r:=bok/(2*sin(pi/n));

   alfa:=2*pi/n;

   for i:=1 to n do

     begin

       w[i,1]:=r*cos((i-1)*alfa);

       w[i,2]:=r*sin((i-1)*alfa);

     end;

 end;

 

procedure rysujodcinek (xp,yp,xk,yk:integer);

var xs,ys:integer;

  begin

    xs:=getmaxx div 2;

    ys:=getmaxy div 2;

    line (xp+xs,ys-yp,xk+xs,ys-yk);

  end;

 

procedure przekatne (w:wierzcholki; n:integer);

var i,j:integer;

  begin

    for i:=1 to n-1 do

     for j:=i+1 to n do

      rysujodcinek (round(w[i,1]), round(w[i,2]), round (w[j,1]), round (w[j,2]));

  end;

 

begin

  clrscr;

  czytaj (n,bok);

  grafika;

  xs:=getmaxx div 2;

  ys:=getmaxy div 2;

  wielokat (n,bok,w);

{  rysujodcinek(xp,yp,xk,yk);}

  przekatne(w,n);

  repeat until keypressed;

  closegraph;

end.

 

Program pokazuje animacje kulki

 

program animacja_kulki;

uses crt,graph;

var r:pointer;

    dx,dy:integer;

    ster,tryb,x,y,rozmiar,m,i:integer;

begin

 clrscr;

 ster:=vga; tryb:=2;

 initgraph (ster,tryb,'d:\tp\bgi');

 circle (320,30,30);

 rozmiar:=imagesize (290,0,350,60);

 getmem (r,rozmiar);

 getimage (290,0,350,60,r^);

 m:=50;

 x:=290;

 y:=0;

 dx:=0;

 dy:=round (450/m);

 for i:=1 to m do

  begin

   putimage (x,y,r^,copyput);

   delay (200);

   clearviewport;

   x:=x+dx;

   y:=y+dy;

 end;

 closegraph;

 repeat until keypressed;

end.

 

Tak można zbudować wirtualna tarczę

 

Program tarcza;

USES graph,crt;

CONST xg=319;yg=239;

VAR d,c,k,m,n,gd,gm:integer;

    ml,nl:STRING;

BEGIN

clrscr;

 gd:=9;gm:=2;

 InitGraph(gd,gm,'c:\TP\bgi');

SetBkColor(15);

 SetFillStyle(6,3);Bar(xg-240,yg+240,xg+240,yg-240);

 SetFillStyle(1,15);Bar(xg-220,yg+220,xg+220,yg-220);

  FOR k:=0 TO 9 DO

   BEGIN

    FOR d:=0 TO 19 DO

     BEGIN

       SetColor(k+3);circle(xg,yg,(200-d)-k*20)

     END;

   END;

 SetColor(15);

 OutTextxy((xg-19),(yg-4),'10');

  FOR m:=1 TO 9 DO

   BEGIN

    FOR d:=0 TO 1 DO

 

     BEGIN

       str(m,ml);

       OutTextxy((xg-200)+(m-1)*20+((11-m)*40-6)*d,yg-4,ml)

     END;

   END;

  FOR n:=1 TO 9 DO

   BEGIN

    FOR c:=0 TO 1 DO

     BEGIN

       str(n,nl);

       OutTextxy(xg,(yg-200)+(n-1)*20+((11-n)*40-6)*c,nl)

     END

   END;

 readln;

ClearDevice;

{pawie oko}

   FOR k:=0 TO 9 DO

    BEGIN

     FOR d:=0 TO 39 DO

      BEGIN

       SetColor(k+3);circle(xg,yg-20*k,200-d-20*k);

      END;

    END; readln;

CloseGraph

END.

 

 

powrót