绘制正弦曲线和余弦曲线

本例效果图:

绘制正弦曲线和余弦曲线

unit Unit1;



interface



uses

  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,

  Dialogs;



type

  TForm1 = class(TForm)

    procedure FormPaint(Sender: TObject);

    procedure FormClick(Sender: TObject);

  end;



var

  Form1: TForm1;



implementation



{$R *.dfm}



const

  BoolArr: array[Boolean] of string = ('余弦曲线', '正弦曲线');

var

  f: Boolean = True;



procedure TForm1.FormClick(Sender: TObject);

begin

  f := not f;

  Repaint;

end;



procedure TForm1.FormPaint(Sender: TObject);

var

  x: Integer;

  y,radian: Double;

begin

  Canvas.Pen.Width := 2;

  Canvas.Pen.Color := clRed;

  Canvas.MoveTo(0, ClientWidth div 2);

  for x := 0 to ClientWidth do

  begin

    radian := x / ClientWidth * 4 * pi;

    if f then y := Sin(radian) else y := Cos(radian);

    y := (1-y) * ClientHeight / 2;

    Canvas.LineTo(Round(x), Round(y));

  end;

  Text := BoolArr[f];

end;



end.


 
   

你可能感兴趣的:(绘制正弦曲线和余弦曲线)