想在PaintBox上画正弦波,或者其他波形,如何实现? 想在PaintBox上画正弦波,或者其他波形,如何实现?最好能给出例子代码。谢谢大家。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 http://www.swissdelphicenter.ch/torry/showcode.php?id=789 FPoints: array [0..144] of TPoint; {...} procedure TForm1.CalculateGraph; var xRangePixels, yRangePixels: Integer; origin: TPoint; radian, interval: Double; i: Integer; begin { We calculate the sinus curve in the interval -2Pi..+2Pi, with a resolution of 4Pi/144, as a series of points that will be connected by a polyline. The graph is scaled to fit into the paintbox. The origin of the coordinate system is the center of the paintbox. The default windows coordinate system is inverted, the Y axis points downward! } xRangePixels := (paintbox1.Width - 2) div 4; { pixels in Pi } yRangePixels := (paintbox1.Height - 2) div 2; { pixels in 1 } origin := Point(paintbox1.Width div 2, paintbox1.Height div 2); radian := -2.0 * Pi; interval := 4.0 * Pi / 144.0; for i := 0 to High(FPoints) do begin FPoints[i].X := origin.x + Round(radian * xRangePixels / Pi); FPoints[i].Y := origin.y - Round(sin(radian) * yRangePixels); radian := radian + interval; end; end; procedure TForm1.PaintBox1Paint(Sender: TObject); var origin: TPoint; xRangePixels, yRangePixels: Integer; begin with PaintBox1.Canvas do begin { Fill background in white } Brush.Color := clBtnFace; Brush.Style := bsSolid; Fillrect(paintbox1.BoundsRect); { Paint a coordinate cross } origin := Point(paintbox1.Width div 2, paintbox1.Height div 2); Pen.Color := clBlack; Pen.Style := psSolid; Pen.Width := 1; MoveTo(1, origin.Y); LineTo(paintbox1.Width - 1, origin.y); MoveTo(origin.x, 1); LineTo(origin.x, paintbox1.Height - 1); { Paint some ticks and label the axis } Font.Name := 'Symbol'; Font.Size := 8; Font.Color := clBlack; xRangePixels := (paintbox1.Width - 2) div 4; { pixels in Pi } yRangePixels := (paintbox1.Height - 2) div 2; { pixels in 1 } { X axis } MoveTo(origin.x - 2 * xRangePixels, origin.y - 4); LineTo(origin.x - 2 * xRangePixels, origin.y + 4); TextOut(origin.x - 2 * xRangePixels + 2, origin.y + 2, '-2p'); MoveTo(origin.x - xRangePixels, origin.y - 4); LineTo(origin.x - xRangePixels, origin.y + 4); TextOut(origin.x - xRangePixels + 2, origin.y + 2, '-p'); MoveTo(origin.x + xRangePixels, origin.y - 4); LineTo(origin.x + xRangePixels, origin.y + 4); TextOut(origin.x + xRangePixels - 2 - TextWidth('p'), origin.y + 2, 'p'); MoveTo(origin.x + 2 * xRangePixels, origin.y - 4); LineTo(origin.x + 2 * xRangePixels, origin.y + 4); TextOut(origin.x + 2 * xRangePixels - 2 - TextWidth('2p'), origin.y + 2, '2p'); { Y axis } MoveTo(origin.x - 4, origin.y - yRangePixels); LineTo(origin.x + 4, origin.y - yRangePixels); TextOut(origin.x + 4, origin.y - yRangePixels, '1.0'); MoveTo(origin.x - 4, origin.y - yRangePixels div 2); LineTo(origin.x + 4, origin.y - yRangePixels div 2); TextOut(origin.x + 4, origin.y - (yRangePixels + TextHeight('1')) div 2, '0.5'); MoveTo(origin.x - 2, origin.y + yRangePixels div 2); LineTo(origin.x + 2, origin.y + yRangePixels div 2); TextOut(origin.x + 3, origin.y + (yRangePixels - TextHeight('1')) div 2, '-0.5'); MoveTo(origin.x - 2, origin.y + yRangePixels); LineTo(origin.x + 2, origin.y + yRangePixels); TextOut(origin.x + 3, origin.y + yRangePixels - TextHeight('1'), '-1.0'); {Paint the graph } Pen.Color := clBlue; Polyline(FPoints); end; end; procedure TForm1.FormResize(Sender: TObject); begin CalculateGraph; end; procedure TForm1.FormCreate(Sender: TObject); begin CalculateGraph; end; 求救,计算问题,大侠们请进 使用过指纹仪的高手进来(紧急事态啊!!!) delphi里使用api菜问题请教? 请问怎样创建一个新的文件或文件夹? 怎样将用fastReport的报表不通过御览直接输出图片,很急啊,先谢谢各位了 在DELPHI中,用什么函数来判断一个变量是否为数字,就象VB中的ISNUMERIC? 求一动态报表的源程序或demo!不胜感激! 哪位仁兄,研究过FASTREPORT的源码,请进来!! 我这里有一个不明白 菜鸟求教,关于自定义纸张 的问题 如何把timestamp字段值当成参数传给一个QUERY控件,分不够可以加,谢谢! 有人知道MDI吗?
FPoints: array [0..144] of TPoint; {...} procedure TForm1.CalculateGraph;
var
xRangePixels, yRangePixels: Integer;
origin: TPoint;
radian, interval: Double;
i: Integer;
begin
{
We calculate the sinus curve in the interval -2Pi..+2Pi,
with a resolution of 4Pi/144, as a series of points that
will be connected by a polyline. The graph is scaled to fit into
the paintbox. The origin of the coordinate system is the center
of the paintbox. The default windows coordinate system is inverted,
the Y axis points downward!
}
xRangePixels := (paintbox1.Width - 2) div 4; { pixels in Pi }
yRangePixels := (paintbox1.Height - 2) div 2; { pixels in 1 }
origin := Point(paintbox1.Width div 2, paintbox1.Height div 2);
radian := -2.0 * Pi;
interval := 4.0 * Pi / 144.0;
for i := 0 to High(FPoints) do
begin
FPoints[i].X := origin.x + Round(radian * xRangePixels / Pi);
FPoints[i].Y := origin.y - Round(sin(radian) * yRangePixels);
radian := radian + interval;
end;
end; procedure TForm1.PaintBox1Paint(Sender: TObject);
var
origin: TPoint;
xRangePixels, yRangePixels: Integer;
begin
with PaintBox1.Canvas do
begin
{ Fill background in white }
Brush.Color := clBtnFace;
Brush.Style := bsSolid;
Fillrect(paintbox1.BoundsRect); { Paint a coordinate cross }
origin := Point(paintbox1.Width div 2, paintbox1.Height div 2);
Pen.Color := clBlack;
Pen.Style := psSolid;
Pen.Width := 1;
MoveTo(1, origin.Y);
LineTo(paintbox1.Width - 1, origin.y);
MoveTo(origin.x, 1);
LineTo(origin.x, paintbox1.Height - 1); { Paint some ticks and label the axis }
Font.Name := 'Symbol';
Font.Size := 8;
Font.Color := clBlack;
xRangePixels := (paintbox1.Width - 2) div 4; { pixels in Pi }
yRangePixels := (paintbox1.Height - 2) div 2; { pixels in 1 } { X axis }
MoveTo(origin.x - 2 * xRangePixels, origin.y - 4);
LineTo(origin.x - 2 * xRangePixels, origin.y + 4);
TextOut(origin.x - 2 * xRangePixels + 2, origin.y + 2, '-2p');
MoveTo(origin.x - xRangePixels, origin.y - 4);
LineTo(origin.x - xRangePixels, origin.y + 4);
TextOut(origin.x - xRangePixels + 2, origin.y + 2, '-p');
MoveTo(origin.x + xRangePixels, origin.y - 4);
LineTo(origin.x + xRangePixels, origin.y + 4);
TextOut(origin.x + xRangePixels - 2 - TextWidth('p'), origin.y + 2, 'p');
MoveTo(origin.x + 2 * xRangePixels, origin.y - 4);
LineTo(origin.x + 2 * xRangePixels, origin.y + 4);
TextOut(origin.x + 2 * xRangePixels - 2 - TextWidth('2p'), origin.y + 2, '2p');
{ Y axis }
MoveTo(origin.x - 4, origin.y - yRangePixels);
LineTo(origin.x + 4, origin.y - yRangePixels);
TextOut(origin.x + 4, origin.y - yRangePixels, '1.0');
MoveTo(origin.x - 4, origin.y - yRangePixels div 2);
LineTo(origin.x + 4, origin.y - yRangePixels div 2);
TextOut(origin.x + 4, origin.y - (yRangePixels + TextHeight('1')) div 2, '0.5');
MoveTo(origin.x - 2, origin.y + yRangePixels div 2);
LineTo(origin.x + 2, origin.y + yRangePixels div 2);
TextOut(origin.x + 3, origin.y + (yRangePixels - TextHeight('1')) div 2, '-0.5');
MoveTo(origin.x - 2, origin.y + yRangePixels);
LineTo(origin.x + 2, origin.y + yRangePixels);
TextOut(origin.x + 3, origin.y + yRangePixels - TextHeight('1'), '-1.0'); {Paint the graph }
Pen.Color := clBlue;
Polyline(FPoints);
end;
end; procedure TForm1.FormResize(Sender: TObject);
begin
CalculateGraph;
end; procedure TForm1.FormCreate(Sender: TObject);
begin
CalculateGraph;
end;