Breve experiência com a unit "Graph"
Preview: (a imagem não está correcta relativamente à função seno, mas ilustra bem na mesma o funcionamento do programa)
Código:
program Trigonometria;
uses graph, sysutils, windows;
type TPixel = record
X, Y : integer;
end;
var Driver, Modus : smallint;
Angle : integer;
i : integer;
const CircleCenter : TPixel = (X:200; Y:200);
function Real2String(const value : real) : string;
begin
Str(value, Real2String);
end;
function Int2String(const value : integer) : string;
begin
Str(value, Int2String);
end;
begin
try
repeat
write('Angulo (inteiro) (-360..360)? ');
readln(Angle);
until (Angle in [-360..360]);
DetectGraph(Driver, Modus);
InitGraph(Driver, Modus, '');
Circle(CircleCenter.X, CircleCenter.Y, 100);
Line(CircleCenter.X, 50, CircleCenter.X, 350);
Line(50, CircleCenter.Y, 350, CircleCenter.Y);
SetLineStyle(SolidLn,0,ThickWidth);
SetColor(red);
Line(CircleCenter.X, CircleCenter.Y,
round(100*cos((angle*pi)/180)+CircleCenter.X),
round(CircleCenter.Y-100*sin((angle*pi)/180)));
SetColor(white);
OutTextXY(220, 330, 'sin(' + Int2String(angle) + ') = ' + Real2String(sin((angle*pi)/180)));
OutTextXY(220, 340, 'cos(' + Int2String(angle) + ') = ' + Real2String(cos((angle*pi)/180)));
SetLineStyle(SolidLn,0,NormWidth);
Line(400, 200, 800, 200); // Horizontal
Line(600, 50, 600, 350); // Vertical
OutTextXY(610, 50, 'sin(x)');
for i:=30*round(-2*pi) to 30*round(2*pi) do begin
PutPixel(600+i, round(200-100*sin((i*pi)/180)), red);
end;
SetLineStyle(DashedLn,0,NormWidth);
SetColor(green);
Line(CircleCenter.X, round(CircleCenter.Y-100*sin((angle*pi)/180)), CircleCenter.X+400, round(CircleCenter.Y-100*sin((angle*pi)/180)));
readln; // pausa
CloseGraph;
except
ON e:exception do begin
MessageBox (0, @(e.message)[1] , 'ERRO!', 0 + MB_ICONHAND);
end;
end;
writeln; write('end'); readln; // pausa
end.