其他分享
首页 > 其他分享> > 学绘秀曲线图

学绘秀曲线图

作者:互联网

学绘秀曲线图
偶然从 http://blog.csdn.net/hero82748274/archive/2010/02/10/5304386.aspx 看到了秀曲线图, 就用 GDI 模仿了一下; 如果用 GDI+ 绘制, 图形会细腻很多.

o_10021002.png

procedure TForm1.FormPaint(Sender: TObject);
var
  i,j,num,X,Y: Integer;
begin
  num := 60;
  X := 300;
  Y := 300;
  ClientWidth := 2 * X;
  ClientHeight := 2 * Y;

  Canvas.Pen.Width := 1;
  Canvas.Pen.Color := clWhite;
  Canvas.Brush.Color := clNavy;
  Canvas.FillRect(ClientRect);

  for i := 0 to num do for j := 0 to 1 do
  begin
    Canvas.MoveTo(X, i*10);
    if i < 30 then
      if j = 0 then Canvas.LineTo(X-i*10, Y) else Canvas.LineTo(X+i*10, Y)
    else
      if j = 0 then Canvas.LineTo(X-(num-1-i)*10, Y) else Canvas.LineTo(X+(num-1-i)*10, Y);
  end;
end;

o_10021003.png

procedure TForm1.FormPaint(Sender: TObject);
var
  i,j,num,n,X,Y: Integer;
  angle: Single;
  pts: array of array of TPoint;
begin
  num := 20;
  n := 6; { 改为 n := 11 就是成了下一个图形 }
  angle := -2 * PI / n;
  X := 210;
  Y := 210;
  ClientWidth := 2*X;
  ClientHeight := 2*Y;

  Canvas.Pen.Width := 1;
  Canvas.Pen.Color := clWhite;
  Canvas.Brush.Color := clNavy;
  Canvas.FillRect(ClientRect);

  SetLength(pts, n+1, num);
  for i := 0 to n do
  begin
    for j := 0 to num-1 do
    begin
      pts[i,j] := Point(Trunc(j*10*Cos(angle*i)+X), Trunc(j*10*Sin(angle*i)+Y));
      Canvas.MoveTo(pts[i,j].X, pts[i,j].Y);
      if i = 0 then
        Canvas.LineTo((num-j)*10+X, Y)
      else
        Canvas.LineTo(pts[i-1, num-1-j].X, pts[i-1, num-1-j].Y);
    end;
  end;
end;

o_10021004.png


posted on 2010-02-10 23:24  万一  阅读(5737)  评论(7)  编辑  收藏

标签:10,Canvas,LineTo,end,曲线图,num,pts,学绘秀
来源: https://blog.51cto.com/u_14617575/2873179