home *** CD-ROM | disk | FTP | other *** search
/ Delphi 5 for Professionals / DELPHI5.iso / AddOns / Components / TEECHART / Delphi1_And_Delphi2 / EXAMPLES / EXTENDED / UCONTOU.PAS < prev    next >
Encoding:
Pascal/Delphi Source File  |  1998-10-24  |  4.6 KB  |  178 lines

  1. {*********************************************}
  2. { TeeChart Delphi Component Library           }
  3. { Contour Series Demo                         }
  4. { Copyright (c) 1995-1998 by David Berneda    }
  5. { All rights reserved                         }
  6. {*********************************************}
  7. unit ucontou;
  8. {$P-}
  9.  
  10. interface
  11.  
  12. uses
  13.   WinProcs,WinTypes, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  14.   TeEngine, TeeSurfa, TeeProcs, Chart, TeeComma, StdCtrls, ExtCtrls;
  15.  
  16. type
  17.   TContourForm = class(TForm)
  18.     Panel1: TPanel;
  19.     Memo1: TMemo;
  20.     Button1: TButton;
  21.     CheckBox1: TCheckBox;
  22.     TeeCommander1: TTeeCommander;
  23.     Chart1: TChart;
  24.     ContourSeries: TContourSeries;
  25.     CheckBox2: TCheckBox;
  26.     SurfaceSeries: TSurfaceSeries;
  27.     CheckBox3: TCheckBox;
  28.     Panel2: TPanel;
  29.     ScrollBar1: TScrollBar;
  30.     CheckBox4: TCheckBox;
  31.     CheckBox5: TCheckBox;
  32.     procedure CheckBox1Click(Sender: TObject);
  33.     procedure Button1Click(Sender: TObject);
  34.     procedure FormCreate(Sender: TObject);
  35.     procedure CheckBox2Click(Sender: TObject);
  36.     procedure ContourSeriesGetLevel(Sender: TContourSeries; LevelIndex: Integer;
  37.       var Value: Double; var Color: TColor);
  38.     procedure CheckBox3Click(Sender: TObject);
  39.     procedure ScrollBar1Change(Sender: TObject);
  40.     procedure CheckBox4Click(Sender: TObject);
  41.     procedure CheckBox5Click(Sender: TObject);
  42.   private
  43.     { Private declarations }
  44.     Function RandomXYZ(x,z:Integer):Double;
  45.   public
  46.     { Public declarations }
  47.   end;
  48.  
  49. implementation
  50.  
  51. {$R *.DFM}
  52.  
  53. procedure TContourForm.CheckBox1Click(Sender: TObject);
  54. begin
  55.   With Chart1.View3DOptions do
  56.   if CheckBox1.Checked then  { 2D }
  57.   begin
  58.     Rotation:=0;
  59.     Elevation:=270;
  60.   end
  61.   else { 3D }
  62.   begin
  63.     Rotation:=317;
  64.     Elevation:=342;
  65.   end;
  66.  
  67.   { In 2D view (from top), we should hide the Left axis }
  68.   Chart1.LeftAxis.Visible:=not CheckBox1.Checked;
  69. end;
  70.  
  71. procedure TContourForm.Button1Click(Sender: TObject);
  72. begin
  73.   Close;
  74. end;
  75.  
  76. Function TContourForm.RandomXYZ(x,z:Integer):Double;
  77.  
  78.   Function ToAngle(Value:Integer):Double;
  79.   begin
  80.     result:=((Value+10)*18.0)*Pi/180.0;
  81.   end;
  82.  
  83. begin
  84.   result:=(500.0*(Sin(ToAngle(x)) + Sqr(Cos(ToAngle(z)))));
  85. end;
  86.  
  87. procedure TContourForm.FormCreate(Sender: TObject);
  88. var x,z:Integer;
  89. begin
  90.   { First we add XYZ points to the Contour series... }
  91.   With ContourSeries do
  92.   begin
  93.     Clear;   { We add values from 0 to 1000.  21x21 cells = 441 }
  94.     for x:= -10 to 10 do
  95.         for z:= -10 to 10 do
  96.             AddXYZ( x, RandomXYZ(x,z) ,z, '', clTeeColor);
  97.   end;
  98.  
  99.   { Then we specify how many "contour levels" we want }
  100.   ContourSeries.NumLevels:=10;
  101.  
  102.   { We specify the Y levels position to the "middle" }
  103.   With ContourSeries do
  104.     YPosition:=(YValues.MaxValue+YValues.MinValue)/2.0;
  105.  
  106.   ScrollBar1.Position:=1000-Round(ContourSeries.YPosition);
  107.  
  108.   { We can set some Chart properties to improve aspect }
  109.   Chart1.Chart3DPercent:=100;
  110.  
  111.   { We can also use a Surface series... }
  112.   SurfaceSeries.AssignValues(ContourSeries);
  113. end;
  114.  
  115. procedure TContourForm.CheckBox2Click(Sender: TObject);
  116. begin
  117.   ContourSeries.ColorEachPoint:=CheckBox2.Checked;
  118. end;
  119.  
  120. procedure TContourForm.ContourSeriesGetLevel(Sender: TContourSeries;
  121.   LevelIndex: Integer; var Value: Double; var Color: TColor);
  122. begin
  123.   { Here we specify the 10 Level values }
  124.   Case LevelIndex of
  125.     0: Value:=0;
  126.     1: Value:=100;
  127.     2: Value:=200;
  128.     3: Value:=300;
  129.     4: Value:=400;
  130.     5: Value:=500;
  131.     6: Value:=600;
  132.     7: Value:=700;
  133.     8: Value:=800;
  134.     9: Value:=900;
  135.   end;
  136.   { We can also specify here the exact Color for each level.
  137.     For example:
  138.  
  139.      if Value=500 then Color:=clRed;
  140.   }
  141. end;
  142.  
  143. procedure TContourForm.CheckBox3Click(Sender: TObject);
  144. begin
  145.   SurfaceSeries.Active:=CheckBox3.Checked; { show / hide surface }
  146. end;
  147.  
  148. procedure TContourForm.ScrollBar1Change(Sender: TObject);
  149. begin
  150.   { We don't want each Level to have automatic Y position }
  151.   ContourSeries.YPositionLevel:=False;
  152.  
  153.   { Force the Level Y position }
  154.   ContourSeries.YPosition:=1000-ScrollBar1.Position;
  155. end;
  156.  
  157. procedure TContourForm.CheckBox4Click(Sender: TObject);
  158. begin
  159.   { Turn on / off the automatic Y level positions }
  160.   ContourSeries.YPositionLevel:=CheckBox4.Checked;
  161. end;
  162.  
  163. procedure TContourForm.CheckBox5Click(Sender: TObject);
  164. Var tmp:TBrushStyle;
  165. begin
  166.   { Show / hide Chart Walls using the Brush style }
  167.   if CheckBox5.Checked then tmp:=bsSolid
  168.                        else tmp:=bsClear;
  169.   With Chart1 do
  170.   begin
  171.     LeftWall.Brush.Style   :=tmp;
  172.     BottomWall.Brush.Style :=tmp;
  173.     BackWall.Brush.Style   :=tmp;
  174.   end;
  175. end;
  176.  
  177. end.
  178.