Back
{ fPlot2D)
author: Nikolai Shokhirev )
created: (June 06, 2002)
last modified: August 08, 2003)
ŠNikolai V. Shokhirev, 2002-2003 }
unit fPlot2D;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, Spin, ExtCtrls, uMatTypes, uGraph2D, Buttons, uDisplay;
type
TFormPlot = class(TForm)
PanelBox: TPanel;
PanelControl: TPanel;
CheckBoxX: TCheckBox;
CheckBoxY: TCheckBox;
SpinButtonX: TSpinButton;
SpinButtonY: TSpinButton;
LabelNx: TLabel;
LabelNy: TLabel;
EditIntervals: TEdit;
Label1: TLabel;
Label2: TLabel;
EditRatio: TEdit;
SpeedButtonRefresh: TSpeedButton;
procedure FormCreate(Sender: TObject);
procedure SpinButtonXDownClick(Sender: TObject);
procedure SpinButtonXUpClick(Sender: TObject);
procedure SpinButtonYDownClick(Sender: TObject);
procedure SpinButtonYUpClick(Sender: TObject);
procedure CheckBoxXClick(Sender: TObject);
procedure CheckBoxYClick(Sender: TObject);
procedure SpeedButtonRefreshClick(Sender: TObject);
private
{ Private declarations }
fxMin, fxMax, fyMin, fyMax: TFloat;
fXAxis, fYAxis: boolean;
fNXTicks, fNYTicks: TInt;
fCurveColor: TColor;
fReFunc: TYofX;
fImFunc: TYofX;
fNInterval: TInt;
PlotBox2D: TPlotBox2D;
fYTitle: string;
fXTitle: string;
procedure PaintPlot(Sender: TObject);
procedure PlotBox2DMouseDown(Sender: TObject;
Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
public
{ Public declarations }
procedure Init;
procedure PlotFunction;
property Xmin: TFloat read fXmin write fXmin;
property Xmax: TFloat read fXmax write fXmax;
property Ymin: TFloat read fYmin write fYmin;
property Ymax: TFloat read fYmax write fYmax;
property XTitle: string read fXTitle write fxTitle;
property YTitle: string read fYTitle write fYTitle;
property ReFunc: TYofX write fReFunc;
property ImFunc: TYofX write fImFunc;
// property FrameColor: TColor read fFrameColor write fFrameColor;
end;
var
FormPlot: TFormPlot;
implementation
{$R *.DFM}
procedure TFormPlot.FormCreate(Sender: TObject);
begin
fNXTicks := 3;
LabelNx.Caption := 'Nx = '+ IntToStr(fNXTicks);
fNYTicks := 3;
LabelNy.Caption := 'Ny = '+ IntToStr(fNYTicks);
fCurveColor := clBlue;
// fYFunc: TYofX;
fNInterval := 64;
fXAxis := CheckBoxX.Checked;
fYAxis := CheckBoxY.Checked;
end;
procedure TFormPlot.Init;
begin
PlotBox2D := TPlotBox2D.Create(self, PanelBox);
PlotBox2D.FrameColor := clBlue;
PlotBox2D.BrushColor := clWhite;
PlotBox2D.PenWidth := 1;
PlotBox2D.XCaption := fXAxis;
PlotBox2D.YCaption := fYAxis;
PlotBox2D.NXTicks := fNXTicks;
PlotBox2D.NYTicks := fNYTicks;
PlotBox2D.XTitle := fXTitle;
PlotBox2D.YTitle := fYTitle;
PlotBox2D.SetLimits(Xmin, Xmax, Ymin, Ymax);
PlotBox2D.OnPaint := PaintPlot;
PlotBox2D.PlotFrame;
PlotBox2D.OnMouseDown := PlotBox2DMouseDown;
PlotBox2D.Hint := ' Click to get coordinates';
PlotBox2D.ShowHint := true;
end;
procedure TFormPlot.PaintPlot(Sender: TObject);
begin
if Assigned(PlotBox2D) then
begin
PlotBox2D.PlotFrame;
PlotFunction;
end;
end;
procedure TFormPlot.PlotFunction;
var
i: TInt;
x, dx: TFloat;
begin
fNInterval := StrToIntDef(EditIntervals.Text, 64);
dx := (Xmax - Xmin)/fNInterval;
if Assigned(fReFunc) then
begin
x := XMin;
PlotBox2D.PenColor := clBlack;
PlotBox2D.MoveToF(x, fReFunc(x));
for i := 1 to fNInterval do
begin
x := x + dx;
PlotBox2D.LineToF(x, fReFunc(x));
end;
end;
if Assigned(fImFunc) then
begin
x := XMin;
PlotBox2D.PenColor := clRed;
PlotBox2D.MoveToF(x, fImFunc(x));
for i := 1 to fNInterval do
begin
x := x + dx;
PlotBox2D.LineToF(x, fImFunc(x));
end;
end;
end;
procedure TFormPlot.PlotBox2DMouseDown(Sender: TObject;
Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
ShowMessage('x = '+FloatToStr(PlotBox2D.Xi2r(X))+','+#13#10+
'y = '+FloatToStr(PlotBox2D.Yi2r(Y)));
end;
procedure TFormPlot.SpinButtonXDownClick(Sender: TObject);
begin
dec(fNXTicks);
if fNXTicks < 2 then fNXTicks := 2;
LabelNx.Caption := 'Nx = '+ IntToStr(fNXTicks);
PlotBox2D.NXTicks := fNXTicks;
PlotBox2D.PlotFrame;
PlotFunction;
end;
procedure TFormPlot.SpinButtonXUpClick(Sender: TObject);
begin
inc(fNXTicks);
LabelNx.Caption := 'Nx = '+ IntToStr(fNXTicks);
PlotBox2D.NXTicks := fNXTicks;
PlotBox2D.PlotFrame;
PlotFunction;
end;
procedure TFormPlot.SpinButtonYDownClick(Sender: TObject);
begin
dec(fNYTicks);
if fNYTicks < 2 then fNYTicks := 2;
LabelNy.Caption := 'Ny = '+ IntToStr(fNYTicks);
PlotBox2D.NYTicks := fNYTicks;
PlotBox2D.PlotFrame;
PlotFunction;
end;
procedure TFormPlot.SpinButtonYUpClick(Sender: TObject);
begin
inc(fNYTicks);
LabelNy.Caption := 'Ny = '+ IntToStr(fNYTicks);
PlotBox2D.NYTicks := fNYTicks;
PlotBox2D.PlotFrame;
PlotFunction;
end;
procedure TFormPlot.CheckBoxXClick(Sender: TObject);
begin
fXAxis := CheckBoxX.Checked;
if Assigned(PlotBox2D) then
begin
PlotBox2D.XCaption := fXAxis;
PlotBox2D.PlotFrame;
PlotFunction;
end;
end;
procedure TFormPlot.CheckBoxYClick(Sender: TObject);
begin
fYAxis := CheckBoxY.Checked;
if Assigned(PlotBox2D) then
begin
PlotBox2D.YCaption := fYAxis;
PlotBox2D.PlotFrame;
PlotFunction;
end;
end;
procedure TFormPlot.SpeedButtonRefreshClick(Sender: TObject);
begin
if Assigned(PlotBox2D) then
begin
PlotBox2D.XYRatio := StrToFloatDef(EditRatio.Text, -1.0);
PlotBox2D.PlotFrame;
PlotFunction;
end;
end;
end.
Top
Generated by Lore's Source to HTML Converter(http://www.newty.de/lsc/index.html) |