home *** CD-ROM | disk | FTP | other *** search
- {*********************************************}
- { TeeChart Delphi Component Library }
- { Surface Series Demo }
- { Copyright (c) 1996 by David Berneda }
- { All rights reserved }
- {*********************************************}
- unit Surface;
-
- interface
-
- uses
- SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
- Forms, Dialogs, ExtCtrls, Teengine, Chart, StdCtrls, TeeSurfa,
- Spin, Series, Buttons, teeprocs, TeeComma;
-
- type
- TSurfaceForm = class(TForm)
- Chart1: TChart;
- Panel1: TPanel;
- CheckBox1: TCheckBox;
- SurfaceSeries1: TSurfaceSeries;
- SpinEdit1: TSpinEdit;
- SpinEdit2: TSpinEdit;
- Label2: TLabel;
- Timer1: TTimer;
- Animation1: TCheckBox;
- Label1: TLabel;
- RGColorMode: TRadioGroup;
- BitBtn3: TBitBtn;
- SpinEditRed: TSpinEdit;
- SpinEditBlue: TSpinEdit;
- SpinEditGreen: TSpinEdit;
- SpinEdit3: TSpinEdit;
- CheckBox3: TCheckBox;
- Label3: TLabel;
- TeeCommander1: TTeeCommander;
- procedure FormCreate(Sender: TObject);
- procedure CheckBox1Click(Sender: TObject);
- function SurfaceSeries1GetYValue(Sender: TChartSeries; X,
- Z: Longint): Double;
- procedure SpinEdit1Change(Sender: TObject);
- procedure SpinEdit2Change(Sender: TObject);
- procedure Animation1Click(Sender: TObject);
- procedure Timer1Timer(Sender: TObject);
- procedure RGColorModeClick(Sender: TObject);
- procedure SpinEditBlueChange(Sender: TObject);
- procedure CheckBox3Click(Sender: TObject);
- procedure BitBtn1Click(Sender: TObject);
- procedure BitBtn2Click(Sender: TObject);
- private
- { Private declarations }
- public
- { Public declarations }
- end;
-
- implementation
-
- {$R *.DFM}
- uses EditChar,SurfEdit,TeCanvas;
-
- procedure TSurfaceForm.FormCreate(Sender: TObject);
- begin
- { warning if video don't supports true or high color }
- if not Chart1.IsScreenHighColor then
- ShowMessage('This demo looks much better with'+#13+
- '16k colors or greater.');
-
- TeeEraseBack:=False; { <-- this will allow Win95+Plus! resize smoothly }
-
- { set the maximum allowed Surface grid dimensions for this demo }
- SpinEdit2.MaxValue:=MaxAllowedCells;
- SpinEdit3.MaxValue:=MaxAllowedCells;
-
- { default surface grid size for this demo }
- SpinEdit2.Value:=20;
- SpinEdit3.Value:=20;
-
- { initialize some values... }
- With SurfaceSeries1 do
- Begin
- FillSampleValues(20);
- Pen.Color:=clBlack;
- end;
- Chart1.Gradient.Visible:=Chart1.IsScreenHighColor;
- end;
-
- procedure TSurfaceForm.CheckBox1Click(Sender: TObject);
- begin
- SurfaceSeries1.WireFrame:=CheckBox1.Checked;
- end;
-
- function TSurfaceForm.SurfaceSeries1GetYValue(Sender: TChartSeries; X,
- Z: Longint): Double;
- var PiPortion,HalfPi,tmpx,tmpz:Double;
- begin
- result:=0;
- With SurfaceSeries1 do
- begin
- PiPortion:=Pi/(NumXValues);
- HalfPi:=Pi*0.5;
- tmpX:=x*PiPortion;
- tmpZ:=z*PiPortion;
- Case SpinEdit1.Value of { sample surfaces }
- 1: result:=0.5*sqr(Cos(x/(NumXValues*0.2)))+
- sqr(Cos(z/(NumXValues*0.2)))-
- cos(z/(NumXValues*0.5));
- 2: result:= sqr( Cos(tmpx) ) * sqr( Sin(tmpz) );
- 3: result:= cos(tmpx*tmpx)+sin(tmpz*tmpz);
- 4: result:= sqr(cos(tmpx))+sqr(sin(tmpz));
- 5: result:= -tmpx+sqr(tmpz)*sin(tmpx*tmpz);
- 6: result:= Sqrt(tmpx * tmpx + tmpz * tmpz);
- 7: result:= cos(abs(tmpx-HalfPi))*sin(tmpz);
- 8: result:= cos(abs(tmpx-HalfPi)*abs(tmpz-HalfPi));
- end;
- end;
- end;
-
- procedure TSurfaceForm.SpinEdit1Change(Sender: TObject);
- begin
- SurfaceSeries1.ReCreateValues;
- end;
-
- procedure TSurfaceForm.SpinEdit2Change(Sender: TObject);
- begin
- if Sender=SpinEdit2 then
- SurfaceSeries1.NumXValues:=SpinEdit2.Value
- else
- SurfaceSeries1.NumZValues:=SpinEdit3.Value;
- end;
-
- procedure TSurfaceForm.Animation1Click(Sender: TObject);
- begin
- Randomize;
- Timer1.Enabled:=Not Timer1.Enabled; { start / stop timer }
- end;
-
- procedure TSurfaceForm.Timer1Timer(Sender: TObject);
-
- Function RandomColor:TColor;
- begin { get a random color }
- result:=ColorPalette[1+Random(MaxDefaultColors)]
- end;
-
- begin
- Timer1.Enabled:=False; { stop animation timer }
-
- { Invert Left axis randomly }
- if Random(100)<2 then
- Chart1.LeftAxis.Inverted:=not Chart1.LeftAxis.Inverted;
-
- { Invert Bottom axis randomly }
- if Random(100)<2 then
- Chart1.BottomAxis.Inverted:=not Chart1.BottomAxis.Inverted;
-
- { Invert Depth axis randomly }
- if Random(100)<2 then
- Chart1.DepthAxis.Inverted:=not Chart1.DepthAxis.Inverted;
-
- { Change Color Mode (Single, Range or Palette) randomly }
- if Random(100)<2 then
- if RGColorMode.ItemIndex<2 then
- RGColorMode.ItemIndex:=RGColorMode.ItemIndex+1
- else
- RGColorMode.ItemIndex:=0;
-
- { Change Chart Gradient Colors randomly (only at 16k colors or greater) }
- if Random(100)<10 then Chart1.Gradient.StartColor:=RandomColor else
- if Random(100)<10 then Chart1.Gradient.EndColor:=RandomColor;
-
- if Random(100)<5 then
- Chart1.Gradient.Direction:=TGradientDirection(Random(Ord(High(TGradientDirection))));
-
- { Random change Surface and Chart colors }
- With SurfaceSeries1 do
- Begin
- Case RGColorMode.ItemIndex of
- 0: if Random(100)<15 then SeriesColor:=RandomColor; { single color }
- 1: begin { color range }
- if Random(100)<15 then
- StartColor:=RandomColor
- else
- if Random(100)<15 then
- EndColor:=RandomColor;
- end;
- end;
- { random change pen color }
- if Random(100)<15 then Pen.Color:=RandomColor;
- end;
-
- { Change Surface Example: }
- With SpinEdit1 do if Value<MaxValue then Value:=Value+1
- else Value:=MinValue;
- Timer1.Enabled:=True; { re-start animation timer }
- end;
-
- procedure TSurfaceForm.RGColorModeClick(Sender: TObject);
- begin
- Case RGColorMode.ItemIndex of
- 0: Begin
- SurfaceSeries1.UseColorRange:=False;
- SurfaceSeries1.UsePalette:=False;
- end;
- 1: Begin
- SurfaceSeries1.UseColorRange:=True;
- SurfaceSeries1.UsePalette:=False;
- end;
- 2: Begin
- SurfaceSeries1.UseColorRange:=False;
- SurfaceSeries1.UsePalette:=True;
- end;
- end;
- SpinEditRed.Enabled:=RGColorMode.ItemIndex=2;
- SpinEditGreen.Enabled:=RGColorMode.ItemIndex=2;
- SpinEditBlue.Enabled:=RGColorMode.ItemIndex=2;
- end;
-
- procedure TSurfaceForm.SpinEditBlueChange(Sender: TObject);
- begin
- With SurfaceSeries1 do
- Begin
- RedFactor:=SpinEditRed.Value*(2.0/100.0);
- GreenFactor:=SpinEditGreen.Value*0.01;
- BlueFactor:=SpinEditBlue.Value*0.01;
- CreateDefaultPalette(PaletteSteps);
- Repaint;
- end;
- end;
-
- procedure TSurfaceForm.CheckBox3Click(Sender: TObject);
- begin
- Chart1.Gradient.Visible:=Chart1.IsScreenHighColor and (not CheckBox3.Checked);
- Chart1.View3DWalls:=not CheckBox3.Checked;
- Chart1.AxisVisible:=not CheckBox3.Checked;
- if CheckBox3.Checked then
- Chart1.Color:=clBlack
- else
- Chart1.Color:=clScrollBar;
- end;
-
- procedure TSurfaceForm.BitBtn1Click(Sender: TObject);
- begin
- EditChart(Self,Chart1);
- end;
-
- procedure TSurfaceForm.BitBtn2Click(Sender: TObject);
- begin
- EditSeries(Self,SurfaceSeries1);
- end;
-
- end.
-