Questo sito utilizza cookies solo per scopi di autenticazione sul sito e nient'altro. Nessuna informazione personale viene tracciata. Leggi l'informativa sui cookies.
Username: Password: oppure
Ipocicloide - GRAFICA.PAS

GRAFICA.PAS

Caricato da: Poggi Marco
Scarica il programma completo

  1. unit Grafica;
  2.  
  3. interface
  4. uses graph, crt;
  5.  
  6. function inizio_graf:boolean;
  7. procedure assi;
  8. procedure fine_graf;
  9.  
  10. type finestra=record
  11.       x0,y0,xf,yf:double;
  12.      end; {fine record finestra }
  13.  
  14. type punto=object
  15.       px,py,maxx,maxy:word;
  16.       gx,gy:double;
  17.       f:finestra;
  18.       constructor inizio(g:finestra);
  19.       constructor inizio(a,b,c,d:double);
  20.       constructor IsoInizio(cx0,cy0,cxf:double);
  21.       destructor DistruggiPunto;
  22.       procedure assi(c:word);
  23.       procedure SetX(a:double);
  24.       procedure SetY(a:double);
  25.       procedure SetXY(a,b:double);
  26.       procedure punto(x,y:double; c:word);
  27.       procedure rettangolo(x,y,x1,y1:double; c:word);
  28.       procedure RuotaPunto(x,y,al:double; c:word);
  29.       procedure TraslaRuotaPunto(x0,y0,x,y,al:double; c:word);
  30.       procedure cerchio(xc,yc,r:double; c:word);
  31.       procedure ellisse(xc,yc,rx,ry:double; c:word);
  32.       procedure linea(c:finestra; col:word);
  33.      end; { fine classe punto }
  34.  
  35. const nero=black;
  36.       blu=blue;
  37.       verde=green;
  38.       ciano=cyan;
  39.       rosso=red;
  40.       magenta=magenta;
  41.       marrone=brown;
  42.       GrigioChiaro=LightGray;
  43.       GrigioScuro=DarkGray;
  44.       BluChiaro=LightBlue;
  45.       VerdeChiaro=LightGreen;
  46.       CianoChiaro=LightCyan;
  47.       RossoChiaro=LightRed;
  48.       MagentaChiaro=LightMagenta;
  49.       giallo=yellow;
  50.       bianco=white;
  51.  
  52.       lampeggio=blink; { solo per il testo }
  53.  
  54. implementation
  55.  
  56. function inizio_graf:boolean;
  57. var sg,ng,ec:smallint(*integer*);
  58.     ch:boolean;
  59. begin
  60.  sg:=detect;
  61.  initgraph(sg, ng, '');
  62.  ec:=graphresult;
  63.  if ec=grok then
  64.  begin
  65.   ch:=true;
  66.   settextstyle(DefaultFont, HorizDir, 1);
  67.  end
  68.  else
  69.  begin
  70.   ch:=false;
  71.   gotoxy(1, wherey+1);
  72.   write('Errore grafico: ',grapherrormsg(ec));
  73.   repeat until keypressed;
  74.   writeln(' ',readkey);
  75.  end;
  76.  inizio_graf:=ch;
  77. end;
  78.  
  79. procedure assi;
  80. var finx,finy,sx,sy:word;
  81. begin
  82.  finx:=getmaxx;
  83.  finy:=getmaxy;
  84.  sx:=finx div 2;
  85.  sy:=finy div 2;
  86.  setcolor(7);
  87.  line(sx,0,sx-3,10);
  88.  line(sx,0,sx+3,10);
  89.  line(finx,sy,finx-10,sy-3);
  90.  line(finx,sy,finx-10,sy+3);
  91.  setcolor(15);
  92.  line(sx,0,sx,finy);
  93.  line(0,sy,finx,sy);
  94.  outtextxy(finx-10,sy-15,'x');
  95.  outtextxy(sx+10,0,'y');
  96. end;
  97.  
  98. procedure fine_graf;
  99. var tasto:char;
  100. begin
  101.  repeat ; until keypressed;
  102.  tasto:=readkey;
  103.  closegraph;
  104. end;
  105.  
  106. constructor punto.inizio(a,b,c,d:double);
  107. var t:finestra;
  108. begin
  109.  with t do
  110.  begin
  111.   x0:=a;
  112.   y0:=b;
  113.   xf:=c;
  114.   yf:=d;
  115.  end;
  116.  inizio(t);
  117. end;
  118.  
  119. constructor punto.inizio(g:finestra);
  120. begin
  121.  maxx:=GetMaxX;
  122.  maxy:=GetMaxY;
  123.  f:=g;
  124.  with f do
  125.  begin
  126.   gx:=maxx/(xf-x0);
  127.   gy:=maxy/(yf-y0);
  128.   SetX(x0);
  129.   SetY(y0);
  130.  end;
  131. end;
  132.  
  133. constructor punto.IsoInizio(cx0,cy0,cxf:double);
  134. begin
  135.  maxx:=GetMaxX;
  136.  maxy:=GetMaxY;
  137.  with f do
  138.  begin
  139.   x0:=cx0;
  140.   xf:=cxf;
  141.   y0:=cy0;
  142.   gx:=maxx/(xf-x0);
  143.   gy:=gx;
  144.   yf:=(maxy/gy)+y0;
  145.   SetX(x0);
  146.   SetY(y0);
  147.  end;
  148. end;
  149.  
  150. destructor punto.DistruggiPunto;
  151. begin
  152.  { Distruttore }
  153. end;
  154.  
  155. procedure punto.assi(c:word);
  156. var cx0,cy0:longint;
  157. begin
  158.  with f do
  159.  begin
  160.   cx0:=round(gx*(0.0-x0));
  161.   cy0:=maxy-round(gy*(0.0-y0));
  162.  end;
  163.  SetColor(c);
  164.  if (cy0>=0) and (cy0<=maxx) then
  165.  begin
  166.   line(0, cy0, maxx, cy0); { asse x }
  167.  end;
  168.  if (cx0>=0) and (cx0<=maxy) then
  169.  begin
  170.   line(cx0, 0, cx0, maxy); { asse y }
  171.  end;
  172. end;
  173.  
  174. procedure punto.SetX(a:double);
  175. begin
  176.  a:=gx*(a-f.x0);
  177.  if (a>=0) and (a<=maxx) then px:=round(a)
  178.  else px:=maxx+10;
  179. end;
  180.  
  181. procedure punto.SetY(a:double);
  182. begin
  183.  a:=maxy-(gy*(a-f.y0));
  184.  if (a>=0) and (a<=maxx) then py:=round(a)
  185.  else py:=maxy+10;
  186. end;
  187.  
  188. procedure punto.SetXY(a,b:double);
  189. begin
  190.  SetX(a);
  191.  SetY(b);
  192. end;
  193.  
  194. procedure punto.punto(x,y:double; c:word);
  195. begin
  196.  SetX(x);
  197.  SetY(y);
  198.  putpixel(px, py, c);
  199. end;
  200.  
  201. procedure punto.rettangolo(x,y,x1,y1:double; c:word);
  202. var lato:finestra;
  203. begin
  204.  with lato do
  205.  begin
  206.   x0:=x;
  207.   y0:=y;
  208.   xf:=x1;
  209.   yf:=y;
  210.   linea(lato, c);
  211.   x0:=x1;
  212.   yf:=y1;
  213.   linea(lato, c);
  214.   x0:=x;
  215.   y0:=y1;
  216.   linea(lato, c);
  217.   xf:=x;
  218.   yf:=y;
  219.   linea(lato, c);
  220.  end;
  221. end;
  222.  
  223. procedure punto.RuotaPunto(x,y,al:double; c:word);
  224. var rx,ry:double;
  225. begin
  226.  rx:=x*cos(al)-y*sin(al);
  227.  ry:=y*cos(al)+x*sin(al);
  228.  punto(rx, ry, c);
  229. end;
  230.  
  231. procedure punto.TraslaRuotaPunto(x0,y0,x,y,al:double; c:word);
  232. var rx,ry:double;
  233. begin
  234.  rx:=x*cos(al)-y*sin(al);
  235.  ry:=y*cos(al)+x*sin(al);
  236.  punto(rx+x0, ry+y0, c);
  237. end;
  238.  
  239. procedure punto.cerchio(xc,yc,r:double; c:word);
  240. var al,dal:double;
  241. begin
  242.  al:=0;
  243.  dal:=1/(gy*2*pi*r);
  244.  while al<=2*pi do
  245.  begin
  246.   TraslaRuotaPunto(xc, yc, r, 0, al, c);
  247.   al:=al+dal;
  248.  end;
  249. end;
  250.  
  251. procedure punto.linea(c:finestra; col:word);
  252. var x1,y1:word;
  253. begin
  254.  with c do
  255.  begin
  256.   SetXY(x0, y0);
  257.   x1:=px;
  258.   y1:=py;
  259.   SetXY(xf, yf);
  260.   SetColor(col);
  261.   line(x1, y1, px, py);
  262.  end;
  263. end;
  264.  
  265. procedure punto.ellisse(xc,yc,rx,ry:double; c:word);
  266. var al,dal,be,rm:double;
  267. begin
  268.  al:=0;
  269.  be:=2*pi;
  270.  rm:=0.5*(rx+ry);
  271.  dal:=0.5/(gy*be*rm);
  272.  while al<=be do
  273.  begin
  274.   punto(xc+rx*cos(al), yc+ry*sin(al), c);
  275.   al:=al+dal;
  276.  end;
  277. end;
  278.  
  279.  
  280. begin
  281.  {Inizializzazione}
  282. end.