怎样画随机线以及填充图形颜色(100分)

  • 主题发起人 主题发起人 sdwddspcx
  • 开始时间 开始时间
S

sdwddspcx

Unregistered / Unconfirmed
GUEST, unregistred user!
怎样画任意线 画直线可以用LineTo 椭圆可以用Ellipse 那么随机线呢?

还有如果我画了一个圆 又如何在里面填充颜色呢?

请各位高手指点 谢谢![?][?]

 
看 看delphi自带的teeChart图表demo
 
with canvas do
begin
pen.color;=clblack;
pen.mode:=pmcopy;
brush.color:=clred;
brush.style:=bssolid;
ellipse(100,100,300,300);
end.
随即线:用这个函数试试:canvas.Polyline();
procedure TForm1.PaintBox1Paint(Sender: TObject);

begin
with Sender as TPaintBox do
begin
Canvas.Pen.Color := clWhite;
Canvas.Polyline([Point(40, 10), Point(20, 60), Point(70, 30),
Point(10, 30), Point(60, 60), Point(40, 10)]);
end;

end;
 
wujiangok_2001:
sorry 我说的不是那个意思 用过windows开始|附件里的画图工具吗 那里有填充和画线功能 我要实现的就是那个 你的不满足我的要求 呵呵 现在我已经自己作出来了 我现在没实现的是拖动图象的功能 就是用鼠标选取一定区域 可以将其移动 或许你 还有大家可以帮助我 呵呵 如果对功能方面有疑问 那么请看看windows的画图工具
 
问题解决了?你自己解决了,哪分怎分?
 
这个你试一下看看??
private
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.X := origin.x + Round(radian * xRangePixels / Pi);
FPoints.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 tickmarks 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;
 
很稀有的GIS(电子地图信息系统),包括了很多功能:垂直影射系统、位图背景、缩放、
区域选择、着色、符号图表显示、点置和输入输出图象数据等,完全遵循GNU通用公有许可证
spsgis.zip
http://www.csdn.net/dev/delphi/Samples/spsgis.zip
 
画多边形
procedure TForm1.Button1Click(Sender: TObject);
var
ptArray : array[0..9] of TPOINT;
PtCounts : array[0..1] of integer;
begin
PtArray[0] := Point(0, 0);
PtArray[1] := Point(0, 100);
PtArray[2] := Point(100, 100);
PtArray[3] := Point(100, 0);
PtArray[4] := Point(0, 0);
PtCounts[0] := 5;
PtArray[5] := Point(25, 25);
PtArray[6] := Point(25, 75);
PtArray[7] := Point(75, 75);
PtArray[8] := Point(75, 25);
PtArray[9] := Point(25, 25);
PtCounts[1] := 5;
PolyPolygon(Form1.Canvas.Handle,
PtArray,
PtCounts,
2);
end;
画多态多边形
type
TPtArray = array[0..0] of TPoint;
PPtArray = ^TPtArray;

procedure DrawDynamicPolyArray(NumPoints : integer;
Canvas : TCanvas);
var
p : PPtArray;
i : integer;
begin
{$IFOPT R+}
{$DEFINE CKRANGE}
{$R-}
{$ENDIF}
GetMem(p, sizeof(TPoint) * NumPoints);
Randomize;
for i := 0 to (NumPoints -1) do begin
p^.x := Random(Form1.Width);
p^.y := Random(Form1.Height);
end;
Polygon(Canvas.Handle, p, NumPoints);
FreeMem(p, sizeof(TPoint) * NumPoints);
{$IFDEF CKRANGE}
{$UNDEF CKRANGE}
{$R+}
{$ENDIF}
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
Form1.Canvas.Brush.Color := clWhite;
Form1.Canvas.FillRect(Rect(0, 0, Form1.Width, Form1.Height));
Form1.Canvas.Brush.Color := clRed;
DrawDynamicPolyArray(SpinEdit1.Value,
Form1.Canvas);
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
SpinEdit1.MinValue := 2;
SpinEdit1.MaxValue := 1000;
SpinEdit1.Value := 100;
end;

end.

 
画贝塞尔曲线
在Delph下调用PolyBezier();
procedure TForm1.Button1Click(Sender: TObject);
var point:array[0..6] of Tpoint;
h:HDC;
begin
h:=getdc(form1.handle);
point[0].x:=25; point[0].y:=25;
point[1].x:=35; point[1].y:=170;
point[2].x:=130;point[2].y:=120;
point[3].x:=150;point[3].y:=150;
point[4].x:=170;point[4].y:=280;
point[5].x:=250;point[5].y:=115;
point[6].x:=250;point[6].y:=225;
polybezier(h,point,7);
end;

PolyBezier 画一系列相连的曲线,每一段包含4个point,第一点是曲线起点,
第二点,第三点指定曲线形状的控制点,第四点是曲线终点。
本例中,1为起点,4为中点,7为终点,2,3,5,6为控制点。
OR 调用canvas.polybezier();

*** Drawing CURVES in Delphi? ***
Solution 1
From: dmitrys@phyast.la.asu.edu (Dmitry Streblechenko)

In article <4uijv6$kf7@newsbf02.news.aol.com,
gtabsoft2@aol.com (GTABSoft2) wrote:
Does anyone have source code or info on drawing Bezier curves? I must have
it for my component. Please respond to my email address.
I did this some time ago; I was too lazy to learn how to draw Bezier curves using Win API, so I did it using Polyline().

Note I used floating type values for points coordinates, (I used some kind of virtual screen), just change them to integer.



--------------------------------------------------------------------------------


PBezierPoint = ^TBezierPoint;
TBezierPoint = record
X,Y:double; //main node
Xl,Yl:double; //left control point
Xr,Yr:double; //right control point
end;

//P1 and P2 are two TBezierPoint's, t is between 0 and 1:
//when t=0 X=P1.X, Y=P1.Y; when t=1 X=P2.X, Y=P2.Y;

procedure BezierValue(P1,P2:TBezierPoint; t:double; var X,Y:double);
var t_sq,t_cb,r1,r2,r3,r4:double;
begin
t_sq := t * t;
t_cb := t * t_sq;
r1 := (1 - 3*t + 3*t_sq - t_cb)*P1.X;
r2 := ( 3*t - 6*t_sq + 3*t_cb)*P1.Xr;
r3 := ( 3*t_sq - 3*t_cb)*P2.Xl;
r4 := ( t_cb)*P2.X;
X := r1 + r2 + r3 + r4;
r1 := (1 - 3*t + 3*t_sq - t_cb)*P1.Y;
r2 := ( 3*t - 6*t_sq + 3*t_cb)*P1.Yr;
r3 := ( 3*t_sq - 3*t_cb)*P2.Yl;
r4 := ( t_cb)*P2.Y;
Y := r1 + r2 + r3 + r4;
end;


--------------------------------------------------------------------------------


To draw Bezier curve, split interval between P1 and P2 into several intervals based on how coarse you want your Bezier curve look (3 - 4 pixels looks Ok), then in a loop create an array of points using procedure above with t from 0 to 1 and draw that array of points using polyline().

Solution 2
From: saconn@iol.ie (Stephen Connolly)

gtabsoft2@aol.com (GTABSoft2) wrote:
Does anyone have source code or info on drawing Bezier curves? I must have
it for my component. Please respond to my email address.
I'm posting this here - 'cause: 1. I've seen people ask for this before, 2. The reference is so old I just had to. (BTW I have older references than this ;-P)

I'm sure that there is a standard Borland disclaimer to go with this:



--------------------------------------------------------------------------------


(********************************************************************)
(* GRAPHIX TOOLBOX 4.0 *)
(* Copyright (c) 1985, 87 by Borland International, Inc. *)
(********************************************************************)
unit GShell;

interface

{-------------------------------- snip ----------------------------}

procedure Bezier(A : PlotArray; MaxContrPoints : integer;
var B : PlotArray; MaxIntPoints : integer);

implementation

{-------------------------------- snip ---------------------------}

procedure Bezier{(A : PlotArray; MaxContrPoints : integer;
var B : PlotArray; MaxIntPoints : integer)};
const
MaxControlPoints = 25;
type
CombiArray = array[0..MaxControlPoints] of Float;
var
N : integer;
ContrPoint, IntPoint : integer;
T, SumX, SumY, Prod, DeltaT, Quot : Float;
Combi : CombiArray;

begin
MaxContrPoints := MaxContrPoints - 1;
DeltaT := 1.0 / (MaxIntPoints - 1);
Combi[0] := 1;
Combi[MaxContrPoints] := 1;
for N := 0 to MaxContrPoints - 2 do
Combi[N + 1] := Combi[N] * (MaxContrPoints - N) / (N + 1);
for IntPoint := 1 to MaxIntPoints do
begin
T := (IntPoint - 1) * DeltaT;
if T <= 0.5 then
begin
Prod := 1.0 - T;
Quot := Prod;
for N := 1 to MaxContrPoints - 1 do
Prod := Prod * Quot;
Quot := T / Quot;
SumX := A[MaxContrPoints + 1, 1];
SumY := A[MaxContrPoints + 1, 2];
for N := MaxContrPoints downto 1 do
begin
SumX := Combi[N - 1] * A[N, 1] + Quot * SumX;
SumY := Combi[N - 1] * A[N, 2] + Quot * SumY;
end;
end
else
begin
Prod := T;
Quot := Prod;
for N := 1 to MaxContrPoints - 1 do
Prod := Prod * Quot;
Quot := (1 - T) / Quot;
SumX := A[1, 1];
SumY := A[1, 2];
for N := 1 to MaxContrPoints do
begin
SumX := Combi[N] * A[N + 1, 1] + Quot * SumX;
SumY := Combi[N] * A[N + 1, 2] + Quot * SumY;
end;
end;
B[IntPoint, 1] := SumX * Prod;
B[IntPoint, 2] := SumY * Prod;
end;
end; { Bezier }

end. { GShell }
我能找到的资料都给你上了,你看看吧女伴:)
 
app2001&amp;wujiangok_2001:
谢谢你们的帮助  虽然不和我意  但至少想帮我   呵呵  给你们些分  别嫌少哦 
  app2001,说明一点  我是boy!!!  
  
 
多人接受答案了。
 

Similar threads

I
回复
0
查看
770
import
I
S
回复
0
查看
3K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
2K
SUNSTONE的Delphi笔记
S
I
回复
0
查看
612
import
I
后退
顶部