Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   GUI-Design mit VCL / FireMonkey / Common Controls (https://www.delphipraxis.net/18-gui-design-mit-vcl-firemonkey-common-controls/)
-   -   Delphi laufende sinus-Kurve (https://www.delphipraxis.net/22626-laufende-sinus-kurve.html)

faux 20. Mai 2004 10:12


laufende sinus-Kurve
 
Hallo!

Ich hab mal mit dem Source eine laufende Sinuskurve gemacht:
Delphi-Quellcode:
procedure TForm1.Timer1Timer(Sender: TObject);
const
  b = 53;
var
  i: Integer;
begin
  with Form1 do
  begin
    Canvas.MoveTo(Width, Height);
      for i := Width downto -100 do
        if a <> 0 then
          Canvas.Pixels[i+a-1, round((sin(i * 0.12)) * 16)+16] := Color
        else
          Canvas.Pixels[i+b-1, round((sin(i * 0.12)) * 16)+16] := Color;
    Canvas.MoveTo(Width, Height);
      for i := Width downto -100 do
        Canvas.Pixels[i+a, round((sin(i * 0.12)) * 16)+16] := clBlack;
  end;
  inc(a);
  if a = b then
    a := 0;
end;
nur hab ich jetzt ein paar fragen:

1. Das Bild flimmert/ruckelt ein wenig. Ich glaube das liegt an meinem Quelltext. Wie kann ich das ändern? Meine Lösung ist nämlich sicherlich nicht die optimale Lösung.

2. Wie kann ich die Kurve runder (also nicht so eckig (pixelig)) machen?

Danke schon mal...

toms 20. Mai 2004 10:36

Re: laufende sinus-Kurve
 
Zitat:

1. Das Bild flimmert/ruckelt ein wenig. Ich glaube das liegt an meinem Quelltext. Wie kann ich das ändern?
Stichwort: Hier im Forum suchenBitBlt.

Nachtrag: Zusätzlich noch die Form auf DoubleBuffered := True; setzen


Nachtrag2:

Ok, hier dann mal ein Beispiel:

Delphi-Quellcode:
procedure TForm1.Timer1Timer(Sender: TObject);
const
  b = 53;
  a: Integer = 40;
var
  i: Integer;
  bmp: TBitmap;
begin
    bmp := TBitmap.Create;
    try
      bmp.Canvas.Font.Assign(Canvas.Font);
      bmp.Width := Width;
      bmp.Height := Height;

      bmp.Canvas.MoveTo(Width, Height);
      for i := Width downto -100 do
        if a <> 0 then
          bmp.Canvas.Pixels[i + a - 1, Round((sin(i * 0.12)) * 16) + 16] := Color
      else
        bmp.Canvas.Pixels[i + b - 1, Round((sin(i * 0.12)) * 16) + 16] := Color;
      bmp.Canvas.MoveTo(Width, Height);
      for i := Width downto -100 do
        bmp.Canvas.Pixels[i + a, Round((sin(i * 0.12)) * 16) + 16] := clBlack;

      BitBlt(Canvas.Handle,
        0, 0,
        bmp.Width,
        bmp.Height,
        bmp.Canvas.Handle,
        0, 0,
        SRCCOPY
        );

    finally
      bmp.Free;
    end;
  a := a + 1;
  if a = b then
    a := 0;
end;

faux 22. Mai 2004 10:53

Re: laufende sinus-Kurve
 
Danke für das Beispiel!

Nur gibts einen kleien Fehler:

Zitat:

Zitat von toms
Delphi-Quellcode:
procedure TForm1.Timer1Timer(Sender: TObject);
const
  b = 53;
  a: Integer = 40;
var
  i: Integer;
  bmp: TBitmap;
begin
    bmp := TBitmap.Create;
    try
      bmp.Canvas.Font.Assign(Canvas.Font);
      bmp.Width := Width;
      bmp.Height := Height;

      bmp.Canvas.MoveTo(Width, Height);
      for i := Width downto -100 do
        if a <> 0 then
          bmp.Canvas.Pixels[i + a - 1, Round((sin(i * 0.12)) * 16) + 16] := Color
      else
        bmp.Canvas.Pixels[i + b - 1, Round((sin(i * 0.12)) * 16) + 16] := Color;
      bmp.Canvas.MoveTo(Width, Height);
      for i := Width downto -100 do
        bmp.Canvas.Pixels[i + a, Round((sin(i * 0.12)) * 16) + 16] := clBlack;

      BitBlt(Canvas.Handle,
        0, 0,
        bmp.Width,
        bmp.Height,
        bmp.Canvas.Handle,
        0, 0,
        SRCCOPY
        );

    finally
      bmp.Free;
    end;
  a := a + 1; //a ist eine Konstante....^^
  if a = b then
    a := 0; //Da nochmal...
end;


MrKnogge 22. Mai 2004 11:35

Re: laufende sinus-Kurve
 
dann nimm doch variablen, die du vorher eben mit deinem konstanten-wert initialisierst.


Alle Zeitangaben in WEZ +1. Es ist jetzt 22:25 Uhr.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz