Unit Grafisch; { GRAPHICAL ROUTINES } INTERFACE Uses SysUtils, Extctrls, Types, Graphics, Algemeen; var Wijd,Hoog : integer; { Image width and height in pixels } xmin,xmax,ymin,ymax : double; { World coordinates limitations } procedure TV(beeld : TImage); { Screen definition } procedure ClearDevice; { Clear Screen } function Grijs(getal : double) : TColor; { Translates Real into Grey values } { Pixel coordinates <==> World coordinates } function x2i(x : double) : integer; function i2x(i : integer) : double; function y2j(y : double) : integer; function j2y(j : integer) : double; procedure teken_cirkel(m : punt; R : double); { Draw circle } procedure teken_driehoek(a,b,c : punt); { Draw triangle } procedure teken_zijde(a,b : punt); { Draw edge } procedure teken_mesh(rij: punten; mesh : drietal); { Draw mesh } procedure teken_extra(rij: punten; mesh : drietal); { Draw numbering } IMPLEMENTATION var scherm : TImage; procedure TV(beeld : TImage); begin scherm := beeld; end; procedure ClearDevice; { Clear Screen } var rechthoek : TRect; begin Wijd := scherm.Width-1; Hoog := scherm.Height-1; rechthoek := Rect(0,0,Wijd+1,Hoog+1); with scherm.Canvas do begin Brush.Color := clWhite; FillRect(rechthoek); end; end; function Grijs(getal : double) : TColor; { Translates Real into Grey values } var even,k : byte; effe : Tcolor; begin if getal < 0 then getal := 0; if getal > 1 then getal := 1; effe := 0; for k := 1 to 3 do begin even := Round(255*(1-getal)); effe := (effe shl 8) or even; end; Grijs := $00000000 or effe; end; function x2i(x : double) : integer; begin x2i := Round((x-xmin)/(xmax-xmin)*Wijd); end; function i2x(i : integer) : double; begin i2x := xmin + i/Wijd*(xmax-xmin); end; function y2j(y : double) : integer; begin y2j := Round(Hoog*(1-(y-ymin)/(ymax-ymin))); end; function j2y(j : integer) : double; begin j2y := ymin + (Hoog-j)/Hoog*(ymax-ymin); end; procedure teken_cirkel(m : punt; R : double); { Draw circle with midpoint (m) and radius (R) and with color (kleur) and pen width (dikte) } var L : integer; h : double; begin { Draw circles } with scherm.Canvas do begin MoveTo(x2i(m.x+R),y2j(m.y)); for L := 1 to 360 do begin h := L*Pi/180; LineTo(x2i(m.x+R*cos(h)),y2j(m.y+R*sin(h))); end; end; end; procedure teken_driehoek(a,b,c : punt); { Draw triangle with vertices (a,b,c) and color (kleur), pen width (dikte) } begin with scherm.Canvas do begin MoveTo(x2i(a.x),y2j(a.y)); LineTo(x2i(b.x),y2j(b.y)); LineTo(x2i(c.x),y2j(c.y)); LineTo(x2i(a.x),y2j(a.y)); end; end; procedure teken_zijde(a,b : punt); { Draw edge with end-pints (a,b) and color (kleur), pen width (dikte) } begin with scherm.Canvas do begin MoveTo(x2i(a.x),y2j(a.y)); LineTo(x2i(b.x),y2j(b.y)); end; end; procedure teken_mesh(rij: punten; mesh : drietal); { Draw triangular mesh given by sites (rij) and connectivity (mesh) } const d : integer = 2; var M,N,i,j,k,L : integer; begin N := Length(rij); for L := 0 to N-1 do begin i := x2i(rij[L].x); j := y2j(rij[L].y); scherm.Canvas.Ellipse(i-d,j-d,i+d,j+d); end; M := Length(mesh); for L := 0 to M-1 do begin i := mesh[L].A; j := mesh[L].B; k := mesh[L].C; teken_driehoek(rij[i],rij[j],rij[k]); end; end; procedure teken_extra(rij: punten; mesh : drietal); { Draw node numbering & triangle numbering given the sites (rij) and connectivity (mesh) } var M,N,i,j,k,L : integer; p,q : double; uit : string; begin scherm.Canvas.Brush.Color := clWhite; scherm.Canvas.Font.Size := 10; N := Length(rij); for L := 0 to N-1 do begin i := x2i(rij[L].x); j := y2j(rij[L].y); uit := IntToStr(L); scherm.Canvas.TextOut(i,j,uit); end; M := Length(mesh); for L := 0 to M-1 do begin i := mesh[L].A; j := mesh[L].B; k := mesh[L].C; uit := IntToStr(L); p := (rij[i].x+rij[j].x+rij[k].x)/3; q := (rij[i].y+rij[j].y+rij[k].y)/3; scherm.Canvas.TextOut(x2i(p),y2j(q),uit); end; end; END.