unit librgraf; interface const MaxNrPuntos = 300; CR = #13; BS = #8; type Coord = record X, Y: real; end; Grafico = object colFondo, colEjes, colTexto, colGraf: integer; titX, titY: string[30]; Datos: array [1..MaxNrPuntos] of Coord; nrDatos: integer; procedure Inicializar; procedure Agregar(X, Y: real); procedure Dibujar(X, Y, tX, tY: integer); end; EntTexto = object X, Y, Ancho:integer; function Entrada(X1, Y1, A_car: integer; Pr: string): string; end; implementation uses Graph, crt; procedure Grafico.Inicializar; begin nrDatos := 0; colFondo := Green; colEjes := Black; colGraf := LightRed; colTexto := White; titX := 'Tiempo'; end; procedure Grafico.Agregar(X, Y: real); begin if nrDatos < MaxNrPuntos then begin inc(nrDatos); Datos[nrDatos].X := X; Datos[nrDatos].Y := Y; end; end; procedure Grafico.Dibujar(X, Y, tX, tY: integer); var I: integer; Xscale, Yscale, Ymin, Ymax, Xmin, Xmax: real; S: string; begin Xmin := Datos[1].X; Xmax := Xmin; Ymin := Datos[1].Y; Ymax := Ymin; for I := 2 to nrDatos do begin if Datos[I].X < Xmin then Xmin := Datos[I].X; if Datos[I].X > Xmax then Xmax := Datos[I].X; if Datos[I].Y < Ymin then Ymin := Datos[I].Y; if Datos[I].Y > Ymax then Ymax := Datos[I].Y; end; Xscale := 0.8 * tX / (Xmax - Xmin); Yscale := 0.8 * tY / (Ymax - Ymin); SetViewPort(X, Y, X+tX, Y+tY, true); SetFillStyle(SolidFill, colFondo); Bar(0, 0, tX-1, tY-1); SetColor(colEjes); Line(round(0.1*tX), tY-round(0.1*tY), round(0.1*tX), tY-round(0.9*tY)); if (Ymin*Ymax > 0) then begin Line(round(0.1*tX), tY-round(0.1*tY), round(0.1*tX), tY-round(0.9*tY)); end else begin Line(round(0.1*tX), tY - (round(Yscale * (0 - Ymin) + 0.1*tY)), round(0.9*tX), tY - (round(Yscale * (0 - Ymin) + 0.1*tY))); end; SetColor(colTexto); OutTextXY(round(0.1*tX), tY-14, titX); str(Ymin:10, S); OutTextXY(round(0.1*tX)+2, tY-round(0.1*tY)-10, S); str(Ymax:10, S); OutTextXY(round(0.1*tX)+2, tY-round(0.9*tY), S); SetColor(colGraf); MoveTo(round(Xscale * (Datos[1].X - Xmin) + 0.1*tX), tY - (round(Yscale * (Datos[1].Y - Ymin) + 0.1*tY))); for I := 2 to nrDatos do LineTo(round(Xscale * (Datos[I].X - Xmin) + 0.1*tX), tY - (round(Yscale * (Datos[I].Y - Ymin) + 0.1*tY))); end; function EntTexto.Entrada(X1, Y1, A_car: integer; Pr: string): string; var Car: char; S: string[80]; begin X := X1; Y := Y1; { Ojo, prever 1 caracter demas para el cursor! } Ancho := (A_car+1) * TextWidth('M'); SetViewPort(X, Y, X+Ancho, Y+TextHeight('O'), true); SetFillStyle(SolidFill, Black); Bar(0, 0, Ancho, TextHeight('O')); { Inicializamos el string con el prefijo provisto, mas _ } S := Pr + '_'; repeat OutTextXY(0, 0, S); { Mostramos el string en su actual estado } Car := Readkey; case Car of CR: ; BS: if S <> Pr then begin S := copy(S, 1, length(S)-1); Bar(0, 0, Ancho, TextHeight('O')); end; else if length(S) < A_car then begin S := copy(S, 1, length(S)-1) + Car + '_'; end; end; until Car = #13; { Descartamos el ultimo caracter (_) } Entrada := copy(S, length(Pr)+1, length(S)-length(Pr)-1); end; begin end.