是这样的:
输入一个数字(1--256),然后根据所得的数字(n个)动态添加n个shape组件,关键就是要这n个shape在窗体中的摆放成一个矩形或者是菱形。(菱形和矩形的算法都有就更好)
谢谢,
输入一个数字(1--256),然后根据所得的数字(n个)动态添加n个shape组件,关键就是要这n个shape在窗体中的摆放成一个矩形或者是菱形。(菱形和矩形的算法都有就更好)
谢谢,
解决方案 »
- (delphi)如何返回update语句影响的行数,以及显示更新的数据。
- tidhttp控件提示找不到属性maxlineaction和readtimeout
- grid 问题,高手快来啊!!!!!!!!!!!!!!!!!!!!
- 漢字換行的問題
- 我要送分,快来!
- 通过什么方法能将richedit里的内容加到listbox里面!
- 我用delphi打开工程文件时,总出现这样的错误:invalid resource file: cannot open file :工程名.Res
- 大家帮忙提个醒,这个第三方控件来叫什么来的?
- 如何关闭代码编辑框的 “自动显示代码hint” 的功能??
- ???一个让我痛苦已久的问题,望各路高手鼎立相助!!![关于close,请写源代码,举例说明,否则不给分;其实很简单,但我是菜鸟]
- 我作毕设,要用delphi7.0实现调度,就是对各个车间的生产工序进行调度,谁能指导一二
- 谁能帮我给个算法,急
可否反过来理解:把一个矩形或是菱形切割成N个shape?这样应该就好做了。
应该清楚了吧。
菱形和矩形的算法都有更好!!
上次你给我的是一个生成圆的算法,现在和原来的一样。只是形状换成了菱形和矩形而以。
谢谢。
那100分铁定给你啦。
//////////圆
var
ab,r,X,Y,iCnt,i,j:integer;
shapes:array of TShape;
alpha:real;
begin
iCnt:=StrToInt(Edit1.Text);
X:=300;
Y:=200;
r:=100;
ab:=50;
alpha:=(PI*2)/iCnt;
SetLength(shapes,iCnt);
for i:=0 to iCnt-1 do
begin
shapes[i]:=TShape.Create(Owner);
shapes[i].Parent:=self;
shapes[i].Height:=ab;
shapes[i].Width:=ab;
shapes[i].Left:=round(X+r*cos(alpha*i)-ab/2);
shapes[i].Top:=round(Y-r*sin(alpha*i)-ab/2);
end;
end;procedure TForm1.Button2Click(Sender: TObject);
/////////矩形
var
pts:Array of TPoint;
iPos,iPosPix,iPerShapeLinePix,ab,r,X,Y,iCnt,i,j:integer;
shapes:array of TShape;
begin
iCnt:=StrToInt(Edit1.Text);
X:=300;
Y:=200;
r:=100;
ab:=50;
SetLength(shapes,iCnt);
SetLength(pts,8*r);
for i:=0 to 2*r-1 do
begin
pts[i].Y:=Y-r;
pts[i].X:=X-r+i; pts[4*r+i].Y:=Y+r;
pts[4*r+i].X:=X+r-i; pts[2*r+i].X:=X+r;
pts[2*r+i].Y:=Y-r+i; pts[6*r+i].X:=X-r;
pts[6*r+i].Y:=Y+r-i;
end;
iPerShapeLinePix:=(8*r div iCnt); iPosPix:=0;
iPos:=0;
for i:=0 to 8*r-1 do
begin
inc(iPosPix);
if (i=0) or (iPosPix>=iPerShapeLinePix) then
begin
if iPos>=iCnt then
break;
shapes[iPos]:=TShape.Create(Owner);
shapes[iPos].Parent:=self;
shapes[iPos].Height:=ab;
shapes[iPos].Width:=ab;
shapes[iPos].Left:=pts[i].X-round(ab/2);
shapes[iPos].Top:=pts[i].Y-round(ab/2);
iPosPix:=0;
inc(iPos);
end;
end;
end;procedure TForm1.Button3Click(Sender: TObject);
//////////菱形
type
PointArray=Array of TPoint;
var
ptsTemp,pts:Array of TPoint;
iPos,iPosPix,iPerShapeLinePix,ab,r,X,Y,iCnt,iLen,i,j:integer;
shapes:array of TShape; function GetLinePoints(x1,y1,x2,y2:integer;var pts:array of TPoint):integer;
Var
iCnt,CtrlCode,Len,I,StepValue,_Posi:Integer;
SlopeRate,_SlopePosi:Real;
Begin
If ABS(x2-x1)>ABS(y2-y1) Then
Begin
Len:=ABS(x2-x1);
If x2>x1 Then
StepValue:=1
Else
StepValue:=-1;
CtrlCode:=1;
if Len<>0 then
SlopeRate:=(y2-y1)/Len
else
SlopeRate:=0;
End Else
Begin
Len:=ABS(y2-y1);
If y2>y1 Then
StepValue:=1
Else
StepValue:=-1;
CtrlCode:=0;
if Len<>0 then
SlopeRate:=(x2-x1)/Len
else
SlopeRate:=0;
End;
Inc(Len);_Posi:=0;_SlopePosi:=0;
Case CtrlCode of
0:Begin
iCnt:=Len;
For I:=0 To Len-1 Do
Begin
pts[I].y:=round(y1+_Posi);
pts[I].x:=round(x1+Int(_SlopePosi));
_Posi:=_Posi+StepValue;
_SlopePosi:=_SlopePosi+SlopeRate;
End;
End;
1:Begin
iCnt:=Len;
For I:=0 To Len-1 Do
Begin
pts[I].x:=round(x1+_Posi);
pts[I].y:=round(y1+Int(_SlopePosi));
_Posi:=_Posi+StepValue;
_SlopePosi:=_SlopePosi+SlopeRate;
End;
End;
End;
Result:=iCnt;
End;
begin
iCnt:=StrToInt(Edit1.Text);
X:=300;
Y:=200;
r:=100;
ab:=50;
SetLength(shapes,iCnt);
SetLength(ptsTemp,2*r);
SetLength(pts,4*round(sqrt(r*r+r*r)));
iLen:=0;
iLen:=iLen+GetLinePoints(X-r,Y,X,Y-r,pts[0]);
iLen:=iLen+GetLinePoints(X,Y-r,X+r,Y,pts[iLen]);
iLen:=iLen+GetLinePoints(X+r,Y,X,Y+r,pts[iLen]);
iLen:=iLen+GetLinePoints(X,Y+r,X-r,Y,pts[iLen]); iPerShapeLinePix:=(iLen div iCnt); iPosPix:=0;
iPos:=0;
for i:=0 to 8*r-1 do
begin
inc(iPosPix);
if (i=0) or (iPosPix>=iPerShapeLinePix) then
begin
if iPos>=iCnt then
break;
shapes[iPos]:=TShape.Create(Owner);
shapes[iPos].Parent:=self;
shapes[iPos].Height:=ab;
shapes[iPos].Width:=ab;
shapes[iPos].Left:=pts[i].X-round(ab/2);
shapes[iPos].Top:=pts[i].Y-round(ab/2);
iPosPix:=0;
inc(iPos);
end;
end;
end;
for i:=0 to 8*r-1 do
begin
inc(iPosPix);
-------------->>>>>>>>>>>>>>>>
for i:=0 to iLen-1 do
begin
inc(iPosPix);
至于排列的问题,我觉得最简单的方法就是画一个圆,然后根据个数把圆平均分成n部分,将每个shape的left和top设成平分的那几个点的坐标就成了