procedure TForm1.Button1Click(Sender: TObject);
var
w, x,
sinX, sinY,
cosX, cosY,
sinXorY, cosXorX,
KreisX, KreisY: Integer;
const
FX = 200;
FY = 50;
sinStartX = 200;
sinStartY = 100;
cosStartX = 100;
cosStartY = 200;
procedure CanLine(Can: TCanvas; x1, y1, x2, y2: Integer);
begin
Can.MoveTo(x1, y1);
Can.LineTo(x2, y2);
end;
function mySin(PixelX: Integer; PiInPixel, OneInPixel: Word): Integer;
var
x: Extended;
begin
x := Pi * (PixelX / PiInPixel);
Result := Trunc(sin(x) * OneInPixel);
end;
function myCos(PixelX: Integer; PiInPixel, OneInPixel: Word): Integer;
var
x: Extended;
begin
x := Pi * (PixelX / PiInPixel);
Result := Trunc(cos(x) * OneInPixel);
end;
procedure XorLine(Can: TCanvas; x1, y1, x2, y2: Integer);
begin
with Can, TPen.Create do
try
Mode := Pen.Mode;
Pen.Mode := pmNot;
MoveTo(x1, y1);
LineTo(x2, y2);
Pen.Mode := Mode;
finally
Free;
end;
end;
begin
with Canvas do
begin
FillRect(ClipRect);
MoveTo(sinStartX, sinStartY-FY);
LineTo(sinStartX, sinStartY+FY);
MoveTo(sinStartX, sinStartY);
LineTo(sinStartX+(FX*2), sinStartY);
MoveTo(cosStartX-FY, cosStartY);
LineTo(cosStartX+FY, cosStartY);
MoveTo(cosStartX, cosStartY);
LineTo(cosStartX, cosStartY+(FX*2));
sinX := sinStartX;
sinY := sinStartY;
cosX := cosStartY;
cosY := cosStartX;
KreisY := sinY;
KreisX := cosY;
for w := -FX to FX do
begin
if not(w = -FX) then
begin
//alte Xor-Linen löschen
XorLine(Canvas, 0, sinXorY, ClipRect.Right, sinXorY);
XorLine(Canvas, cosXorX, 0, cosXorX, ClipRect.Bottom);
end;
//sin zeichnen
x := w;
MoveTo(sinX, sinY);
sinX := sinStartX + FX + w;
sinY := sinStartY + mySin(x, FX, FY);
LineTo(sinX, sinY);
//cos zeichnen
x := w;
MoveTo(cosY, cosX);
cosX := cosStartY + FX + w;
cosY := cosStartX + myCos(x, FX, FY);
LineTo(cosY, cosX);
//Kreis zeichen aus den Y-Werten von Sinus und Cosinus
MoveTo(KreisX, KreisY);
KreisY := sinY;
KreisX := cosY;
LineTo(KreisX, KreisY);
//Xor-Line zeichnen
sinXorY := sinY;
cosXorX := cosY;
XorLine(Canvas, 0, sinXorY, ClipRect.Right, sinXorY);
XorLine(Canvas, cosXorX, 0, cosXorX, ClipRect.Bottom);
Sleep(10); //eine kurze Verzögerung damit es langsammer geht
Application.ProcessMessages;
end;
//Letzte Xor-Linen löschen
XorLine(Canvas, 0, sinXorY, ClipRect.Right, sinXorY);
XorLine(Canvas, cosXorX, 0, cosXorX, ClipRect.Bottom);
end;
end; {Popov}