[Delphi]根据 高斯正态分布随机函数RandG发生的…

2008-04-09 04:21:08来源:互联网 阅读 ()

新老客户大回馈,云服务器低至5折

{*

采用RandG(0,1)来生成标准正态分布数据

1、一次生成10k个数据进行统计,速度相当快(Celeron 1.1G 256M ddr266)<1秒

2、绘出的曲线因为选择范围是8,故看起来并不是十分陡峭,可以将其改为16,那么就更加陡峭了

3、算法:映射到1..1000个数据点,大于等于 8的,正向封顶,设其为1000;小于等于 -8 的,负向封底,设其为1;如上面所说,为了使曲线看起来更加陡峭,可以在这里改为16封顶。其实,我最初是用 2-2来封及 4-4来封定封底的,效果已经不错了。

}

unit Unit1;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls, StdCtrls, Math;

type

TfrmMain = class(TForm)
imgAxis: TImage;
btnRandG: TButton;
GroupBox1: TGroupBox;
Splitter1: TSplitter;
grpControl: TGroupBox;
chkLogFrequency: TCheckBox;
chkDrawEdge: TCheckBox;
chkDrawLines: TCheckBox;
cboxCopyMode: TComboBox;
procedure FormShow(Sender: TObject);
procedure btnRandGClick(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
totalCount :Integer;
sampleDatas :array[1..1000] of Integer;
procedure DrawAxis;
procedure GaussIt(const ASampleData:Extended);
procedure ReDraw;
procedure DrawEdge;//画边

procedure Log(const logName:string);
public
{ Public declarations }
end;

var
frmMain: TfrmMain;

implementation

{$R *.dfm}
procedure TfrmMain.DrawAxis;
begin
imgAxis.Canvas.Pen.Color :=clLime;
imgAxis.Canvas.Pen.Mode :=pmXor;
imgAxis.Canvas.MoveTo(imgAxis.Width div 2,imgAxis.Height);
imgAxis.Canvas.LineTo(imgAxis.Width div 2,0);
imgAxis.Canvas.MoveTo(0,imgAxis.Height -10);
imgAxis.Canvas.LineTo(imgAxis.Width,imgAxis.Height -10);
end;
procedure TfrmMain.ReDraw;
var
bmp :TBitmap;
i :Integer;
begin//根据数组里面的数和totalCount重新画图
bmp :=TBitmap.Create;
try
bmp.Width :=imgAxis.Width;
bmp.Height:=imgAxis.Height;
bmp.Canvas.Brush.Color :=clBlack;
bmp.Canvas.FillRect(bmp.Canvas.ClipRect);
bmp.Canvas.Pen.Color :=clRed;
bmp.Canvas.Pen.Width :=1;
//根据Image高度和1->1000发生的频数设置画线的高度
//应该计算出图像所能反映的最小分辨率,应能体现到频数有1的变化
for i:=1 to 1000 do
begin
sampleDatas[i] :=(sampleDatas[i]*(bmp.Height-10)) *250 div totalCount;//频数->频率->实际图像高度值
sampleDatas[i] :=bmp.Height-10 -sampleDatas[i];//高度转换为实际坐标
bmp.Canvas.MoveTo(i,bmp.Height-10);
if chkDrawLines.Checked then
bmp.Canvas.LineTo(i,sampleDatas[i]);
end;
//Log(''''height.txt'''');
if cboxCopyMode.Items[cboxCopyMode.ItemIndex]=''''cmBlackness'''' then
imgAxis.Canvas.CopyMode :=cmBlackness
else if cboxCopyMode.Items[cboxCopyMode.ItemIndex]=''''cmDstInvert'''' then
imgAxis.Canvas.CopyMode :=cmDstInvert
else if cboxCopyMode.Items[cboxCopyMode.ItemIndex]=''''cmMergeCopy'''' then
imgAxis.Canvas.CopyMode :=cmMergeCopy
else if cboxCopyMode.Items[cboxCopyMode.ItemIndex]=''''cmMergePaint'''' then
imgAxis.Canvas.CopyMode :=cmMergePaint
else if cboxCopyMode.Items[cboxCopyMode.ItemIndex]=''''cmNotSrcCopy'''' then
imgAxis.Canvas.CopyMode :=cmNotSrcCopy
else if cboxCopyMode.Items[cboxCopyMode.ItemIndex]=''''cmNotSrcErase'''' then
imgAxis.Canvas.CopyMode :=cmNotSrcErase
else if cboxCopyMode.Items[cboxCopyMode.ItemIndex]=''''cmPatCopy'''' then
imgAxis.Canvas.CopyMode :=cmPatCopy
else if cboxCopyMode.Items[cboxCopyMode.ItemIndex]=''''cmPatInvert'''' then
imgAxis.Canvas.CopyMode :=cmPatInvert
else if cboxCopyMode.Items[cboxCopyMode.ItemIndex]=''''cmPatPaint'''' then
imgAxis.Canvas.CopyMode :=cmPatPaint
else if cboxCopyMode.Items[cboxCopyMode.ItemIndex]=''''cmSrcAnd'''' then
imgAxis.Canvas.CopyMode :=cmSrcAnd
else if cboxCopyMode.Items[cboxCopyMode.ItemIndex]=''''cmSrcCopy'''' then
imgAxis.Canvas.CopyMode :=cmSrcCopy
else if cboxCopyMode.Items[cboxCopyMode.ItemIndex]=''''cmSrcErase'''' then
imgAxis.Canvas.CopyMode :=cmSrcErase
else if cboxCopyMode.Items[cboxCopyMode.ItemIndex]=''''cmSrcInvert'''' then
imgAxis.Canvas.CopyMode :=cmSrcInvert
else if cboxCopyMode.Items[cboxCopyMode.ItemIndex]=''''cmSrcPaint'''' then
imgAxis.Canvas.CopyMode :=cmSrcPaint
else if cboxCopyMode.Items[cboxCopyMode.ItemIndex]=''''cmWhiteness'''' then
imgAxis.Canvas.CopyMode :=cmWhiteness;

imgAxis.Canvas.CopyRect(imgAxis.Canvas.ClipRect,bmp.Canvas,bmp.Canvas.ClipRect);
//imgAxis.Canvas.Draw(0,0,bmp);//这个不能控制CopyMode
finally
bmp.Destroy;

标签:

版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有

上一篇:DBGridEh实现单击标题栏排序方法 选择自 snowfall 的 Blog

下一篇:模拟进程调度(delphi写的)