⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ftestdisplay.cpp

📁 C++ Math Lib. C++ Builder must use.
💻 CPP
字号:
//---------------------------------------------------------------------------
// N.V.Shokhirev
// created: 20040804
// modified: 20040809
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop

#include "fTestDisplay.h"
//#include <math.h>
#include "dynarrays.h"
#include "dynarrutils.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner): TForm(Owner)
{
  pPlotBox2D = new PlotBox2D(this);
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FormCreate(TObject *Sender)
{
  pPlotBox2D->Parent = PanelBox;
  pPlotBox2D->NYTicks = 5;
  pPlotBox2D->NXTicks = 5;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::PlotBox2DPaint(TObject *Sender)
{
  FArr1D x(100);
  FArr1D y(100);
  FArr1D z(100);
  IArr2D m(20,20);
  int ix1, ix2, iy1, iy2;
  double x1, x2, y1, y2, xx, dx;
  xx = -3.0;
  dx = 0.06;
  for (int i = 1; i <= 100; i++)
  {
    x(i) = xx; xx += dx;
    y(i) = exp(-xx*xx);
    z(i) = xx*y(i);
  };
  switch (RadioGroup1->ItemIndex)
  {
    case 0:
    {
      minmax(x, x1, x2, true);
      minmax(y, y1, y2, true);
      minmax(z, y1, y2, false);
      pPlotBox2D->SetLimits(x1,x2,y1,y2);
      pPlotBox2D->PlotFrame();
      pPlotBox2D->PlotArrays(x,y,clRed);
      pPlotBox2D->PlotArrays(x,z,clBlue);
      };
      break;
    case 1:
    {
      x1 = y.L1();
      x2 = y.H1();
      minmax(y, y1, y2, true);
      minmax(z, y1, y2, false);
      pPlotBox2D->SetLimits(x1,x2,y1,y2);
      pPlotBox2D->PlotFrame();
      pPlotBox2D->PlotArray(y,clRed);
      pPlotBox2D->PlotArray(z,clBlue);
      };
      break;
    case 2:
    {
      for(int i2=m.L2(); i2 <=m.H2(); i2++)
      {
        for(int i1=m.L1(); i1 <=m.H1(); i1++)
        {
          m(i1,i2)= (i1+i2) % 5;
        }
      }
      x1 = m.L1();
      x2 = m.H1()+1;
      y1 = m.L2();
      y2 = m.H2()+1;
      pPlotBox2D->SetLimits(x1,x2,y1,y2);
      pPlotBox2D->PlotFrame();
      for(int i2=m.L2(); i2 <=m.H2(); i2++)
      {
        iy1 = pPlotBox2D->Yr2i(i2);
        iy2 = pPlotBox2D->Yr2i(i2+1);
        for(int i1=m.L1(); i1 <=m.H1(); i1++)
        {
          ix1 = pPlotBox2D->Xr2i(i1);
          ix2 = pPlotBox2D->Xr2i(i1+1);
          if(m(i1,i2)==0)
          {
            pPlotBox2D->Canvas->Brush->Color = clBlack;
            pPlotBox2D->Canvas->Pen->Color = clBlack;
          }
          else
          {
            pPlotBox2D->Canvas->Brush->Color = clWhite;
            pPlotBox2D->Canvas->Pen->Color = clWhite;
          }
          pPlotBox2D->Canvas->Rectangle(ix1,iy2,ix2,iy1);
        }
      }
      pPlotBox2D->SetPenColor(clRed);
      pPlotBox2D->LineF(x1,y1,x2,y1);
      pPlotBox2D->LineF(x1,y1,x1,y2);
      pPlotBox2D->LineF(x1,y2,x2,y2);
      pPlotBox2D->LineF(x2,y1,x2,y2);
      pPlotBox2D->SetPenColor(clBlack);
    };
    break;
    default:;
  };
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FormDestroy(TObject *Sender)
{
  delete pPlotBox2D;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
  pPlotBox2D->SetLimits(-3.0,3.0,0.0,10.0);
  pPlotBox2D->PlotFrame();
  pPlotBox2D->OnPaint = PlotBox2DPaint;
  pPlotBox2D->SetPenColor(clRed);
  PlotBox2DPaint(this);
}
//---------------------------------------------------------------------------

void __fastcall TForm1::RadioGroup1Click(TObject *Sender)
{
  Button1->Click();
}
//---------------------------------------------------------------------------

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -