请各位帮忙生成这样一颗树.(总共就这些分了,不好意思,下次补上)(60分)

  • 主题发起人 主题发起人 jbas
  • 开始时间 开始时间
很久没有看到这样的数据结构问题了,creation-zy老兄出手不凡,看得我神清气爽,佩服佩服!
 
to creation-zy,老大:
小弟现在写出了一个大图形吃小图形的东西,上面的是生长初始图形.如果感兴趣可以看看,挺好看的:)
你上面的那个代码,当我取400个初始点时,就会死机,是否是我的问题.?
核心代码;(不是oop的[:(])
*****************
unit previw;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls, StdCtrls, Buttons,cst, Menus, ExtDlgs,Unttmpfx,Untpict;
type
Tfl=record
ACl:TColor;
ACnt:integer;
end;
TArrfl=array of Tfl;
TRtPoint=record
RtArr:TArrfl;
Rtysds:integer;
end;
TFrmprv = class(TForm)
Image2: TImage;
Image3: TImage;
Image4: TImage;
Image5: TImage;
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
Label4: TLabel;
Label5: TLabel;
Image6: TImage;
Label6: TLabel;
GroupBox1: TGroupBox;
SpeedButton1: TSpeedButton;
SpeedButton2: TSpeedButton;
PaintBox1: TPaintBox;
SpeedButton4: TSpeedButton;
PaintBox3: TPaintBox;
PaintBox4: TPaintBox;
PaintBox5: TPaintBox;
PaintBox6: TPaintBox;
PaintBox2: TPaintBox;
Image1: TImage;
PopupMenu1: TPopupMenu;
N1: TMenuItem;
SavePictureDialog1: TSavePictureDialog;
SpeedButton5: TSpeedButton;
N2: TMenuItem;
SpeedButton3: TSpeedButton;
SpeedButton6: TSpeedButton;
procedure SpeedButton1Click(Sender: TObject);
procedure FormShow(Sender: TObject);
procedure SpeedButton4Click(Sender: TObject);
procedure Image1MouseDown(Sender: TObject;
Button: TMouseButton;
Shift: TShiftState;
X, Y: Integer);
procedure Image2MouseDown(Sender: TObject;
Button: TMouseButton;
Shift: TShiftState;
X, Y: Integer);
procedure Image3MouseDown(Sender: TObject;
Button: TMouseButton;
Shift: TShiftState;
X, Y: Integer);
procedure Label4MouseDown(Sender: TObject;
Button: TMouseButton;
Shift: TShiftState;
X, Y: Integer);
procedure Image5MouseDown(Sender: TObject;
Button: TMouseButton;
Shift: TShiftState;
X, Y: Integer);
procedure Image6MouseDown(Sender: TObject;
Button: TMouseButton;
Shift: TShiftState;
X, Y: Integer);
procedure N1Click(Sender: TObject);
procedure SpeedButton5Click(Sender: TObject);
procedure N2Click(Sender: TObject);
procedure SpeedButton2Click(Sender: TObject);
procedure SpeedButton3Click(Sender: TObject);
procedure SpeedButton6Click(Sender: TObject);
private
{ Private declarations }
ImgIndex:integer;
FArrIge:TArrImage;
FArrimgeValue:TArrImageValue;
function bjPoint(APoint: TPoint;APntbox:TPaintbox): TRtPoint;
procedure szPoint(var Apntbx:TPaintbox;var Aimg:TImage;var Albl:TLabel;ASourceimg:TImage;AMcs:integer);
public
{ Public declarations }
end;

var
Frmprv: TFrmprv;
implementation
uses globunit,Untselfquery,UntAbout;
{$R *.dfm}
procedure TFrmprv.szPoint(var Apntbx:TPaintbox;var Aimg:TImage;var Albl:TLabel;ASourceimg:TImage;AMcs:integer);
var
I,j,K,mq,mt,nt:integer;
temparr,mytt:TRtPoint;
tefl:Tfl;
begin
if Aimg.Visible=true then
Aimg.Visible:=false;
if Apntbx.Visible=false then
Apntbx.Visible:=true;
repaint;
Apntbx.Canvas.CopyRect(Apntbx.Canvas.ClipRect,ASourceimg.Picture.Bitmap.Canvas,ASourceimg.Picture.Bitmap.Canvas.ClipRect);
for mq:=1 to AMcsdo
begin
for i:=2 to Apntbx.Width-2 do
for j:=2 to Apntbx.Height-2do
begin
if (Apntbx.Canvas.Pixels[i+1,j]<>Apntbx.Canvas.Pixels[i,j]) or
(Apntbx.Canvas.Pixels[i,j+1]<>Apntbx.Canvas.Pixels[i,j]) or
(Apntbx.Canvas.Pixels[i-1,j]<>Apntbx.Canvas.Pixels[i,j]) or
(Apntbx.Canvas.Pixels[i,j-1]<>Apntbx.Canvas.Pixels[i,j]) then
begin
temparr:=bjPoint(point(i,j),Apntbx);
tefl.ACl:=clred;
tefl.ACnt:=0;
nt:=high(temparr.rtarr);
if temparr.Rtysds<4 then
begin
for K:=low(temparr.RtArr) to high(temparr.RtArr)do
begin
if temparr.RtArr[K].ACnt>tefl.ACnt then
begin
tefl.ACl:=temparr.RtArr[K].ACl;
//最多的点.
tefl.ACnt:=temparr.RtArr[K].ACnt;
end;
end;
if tefl.ACnt>=temparr.Rtysds then
Apntbx.Canvas.Pixels[i,j]:=tefl.ACl;
end
else
if temparr.Rtysds=4 then
begin
if high(temparr.RtArr)=1 then
Apntbx.Canvas.Pixels[i,j]:=temparr.RtArr[1].ACl;
end;

end;
application.ProcessMessages;
end;
Albl.Caption:=inttostr(mq+Mymcs)+'MCS';
//*****按每3MCS步记录一个图形*******
if ((mq+Mymcs) mod 3)=0 then
begin
Aimg.Canvas.CopyRect(Aimg.Canvas.ClipRect,Apntbx.Canvas,Apntbx.Canvas.ClipRect);
Inc(Myzxcs);
setlength(FArrimgeValue,Myzxcs);
FArrimgeValue[Myzxcs-1].AImage:=Aimg;
FArrimgeValue[Myzxcs-1].ATime:=(mq+Mymcs);
end;
//**************************************
end;
Mymcs:=Mymcs+AMcs;
Aimg.Canvas.CopyRect(Aimg.Canvas.ClipRect,Apntbx.Canvas,Apntbx.Canvas.ClipRect);
Aimg.Visible:=true;
Apntbx.Visible:=false;
repaint;
end;

procedure TFrmprv.SpeedButton1Click(Sender: TObject);
begin
frmcs.ShowModal;
end;

procedure TFrmprv.FormShow(Sender: TObject);
begin
image1.Picture:=mycsbmp.Picture;
end;

procedure TFrmprv.SpeedButton4Click(Sender: TObject);
begin
speedbutton5.Enabled:=false;
speedbutton6.Enabled:=false;
szPoint(paintbox1,image1,label1,Mycsbmp,25);//25
szPoint(paintbox2,image2,label2,image1,20);
//20
szPoint(paintbox3,image3,label3,image2,75);//75
szPoint(paintbox4,image4,label4,image3,30);
//30
szPoint(paintbox5,image5,label5,image4,80);
//80
szPoint(paintbox6,image6,label6,image5,40);
//40
setlength(ArrColorType,0);
setlength(ArrStorPoint,0);
setlength(ArrStorbjPoint,0);
application.MessageBox('完成模拟动作!','提示窗口',0);
SpeedButton3.Enabled:=true;
SpeedButton2.Enabled:=true;
SpeedButton1.Enabled:=true;
end;

function TFrmprv.bjPoint(APoint: TPoint;APntbox:TPaintbox): TRtPoint;
var
I,M,ACountCl:integer;
Cl:Tcolor;
ArrCl:TArrfl;
bl:boolean;
r,g,b:byte;
begin
M:=0;
ACountCl:=0;
Cl:=APntbox.Canvas.Pixels[apoint.x-1,apoint.y-1];
if APntbox.Canvas.Pixels[APoint.X,APoint.Y]<>Cl then
begin
Inc(M);
setlength(ArrCl,M);
ArrCl[0].ACl:=Cl;
ArrCl[0].ACnt:=1;
end
else
Inc(ACountCl);
Cl:=APntbox.Canvas.Pixels[apoint.X,apoint.Y-1];
if Cl<>APntbox.Canvas.Pixels[apoint.x,apoint.Y] then
begin
if M>0 then
begin
if ArrCl[0].ACl=Cl then
Inc(ArrCl[0].ACnt)
else
begin
Inc(M);
setlength(ArrCl,M);
ArrCl[1].ACnt:=1;
ArrCl[1].ACl:=Cl;
end;
end
else
begin
Inc(M);
setlength(ArrCl,M);
ArrCl[0].ACl:=Cl;
ArrCl[0].ACnt:=1;
end;
end
else
Inc(ACountCl);
bl:=false;
Cl:=APntbox.Canvas.Pixels[apoint.X+1,apoint.Y-1];
if Cl<>APntbox.Canvas.Pixels[apoint.X,apoint.Y] then
begin
for I:=0 to M-1do
begin
if ArrCl.ACl=Cl then
begin
Inc(ArrCl.ACnt);
bl:=true;
break;
end;
end;
if bl=false then
begin
Inc(M);
setlength(ArrCl,M);
ArrCl[M-1].ACl:=Cl;
ArrCl[M-1].ACnt:=1;
end;
end
else
Inc(ACountCl);
bl:=false;
Cl:=APntbox.Canvas.Pixels[apoint.X-1,apoint.Y];
if Cl<>APntbox.Canvas.Pixels[apoint.x,apoint.Y] then
begin
for I:=0 to M-1do
begin
if ArrCl.ACl=Cl then
begin
Inc(ArrCl.ACnt);
bl:=true;
break;
end;
end;
if bl=false then
begin
Inc(M);
setlength(ArrCl,M);
ArrCl[M-1].ACl:=Cl;
ArrCl[M-1].ACnt:=1;
end;
end
else
Inc(ACountCl);
bl:=false;
Cl:=APntbox.Canvas.Pixels[apoint.X+1,apoint.Y];
if Cl<>APntbox.Canvas.Pixels[apoint.X,apoint.Y] then
begin
for I:=0 to M-1do
begin
if ArrCl.ACl=Cl then
begin
Inc(ArrCl.ACnt);
bl:=true;
break;
end;
end;
if bl=false then
begin
Inc(M);
setlength(ArrCl,M);
ArrCl[M-1].ACl:=Cl;
ArrCl[M-1].ACnt:=1;
end;
end
else
Inc(ACountCl);
bl:=false;
Cl:=APntbox.Canvas.Pixels[apoint.X-1,apoint.Y+1];
if Cl<>APntbox.Canvas.Pixels[apoint.X,apoint.Y] then
begin
for I:=0 to M-1do
begin
if ArrCl.ACl=Cl then
begin
Inc(ArrCl.ACnt);
bl:=true;
break;
end;
end;
if bl=false then
begin
Inc(M);
setlength(ArrCl,M);
ArrCl[M-1].ACl:=Cl;
ArrCl[M-1].ACnt:=1;
end;
end
else
Inc(ACountCl);
bl:=false;
Cl:=APntbox.Canvas.Pixels[apoint.X,apoint.Y+1];
if Cl<>APntbox.Canvas.Pixels[apoint.X,apoint.Y] then
begin
for I:=0 to M-1do
begin
if ArrCl.ACl=Cl then
begin
Inc(ArrCl.ACnt);
bl:=true;
break;
end;
end;
if bl=false then
begin
Inc(M);
setlength(ArrCl,M);
ArrCl[M-1].ACl:=Cl;
ArrCl[M-1].ACnt:=1;
end;
end
else
Inc(ACountCl);
bl:=false;
Cl:=APntbox.Canvas.Pixels[apoint.X+1,apoint.Y+1];
if Cl<>APntbox.Canvas.Pixels[apoint.X,apoint.Y] then
begin
for I:=0 to M-1do
begin
if ArrCl.ACl=Cl then
begin
Inc(ArrCl.ACnt);
bl:=true;
break;
end;
end;
if bl=false then
begin
Inc(M);
setlength(ArrCl,M);
ArrCl[M-1].ACl:=Cl;
ArrCl[M-1].ACnt:=1;
end;
end
else
Inc(ACountCl);
result.RtArr:=ArrCl;
result.Rtysds:=ACountCl;
end;


procedure TFrmprv.Image1MouseDown(Sender: TObject;
Button: TMouseButton;
Shift: TShiftState;
X, Y: Integer);
begin
if button=mbright then
ImgIndex:=1;
end;

procedure TFrmprv.Image2MouseDown(Sender: TObject;
Button: TMouseButton;
Shift: TShiftState;
X, Y: Integer);
begin
if button=mbright then
ImgIndex:=2;
end;

procedure TFrmprv.Image3MouseDown(Sender: TObject;
Button: TMouseButton;
Shift: TShiftState;
X, Y: Integer);
begin
if button=mbright then
ImgIndex:=3;
end;

procedure TFrmprv.Label4MouseDown(Sender: TObject;
Button: TMouseButton;
Shift: TShiftState;
X, Y: Integer);
begin
if button=mbright then
ImgIndex:=4;
end;

procedure TFrmprv.Image5MouseDown(Sender: TObject;
Button: TMouseButton;
Shift: TShiftState;
X, Y: Integer);
begin
if button=mbright then
ImgIndex:=5;
end;

procedure TFrmprv.Image6MouseDown(Sender: TObject;
Button: TMouseButton;
Shift: TShiftState;
X, Y: Integer);
begin
if button=mbright then
ImgIndex:=6;
end;

procedure TFrmprv.N1Click(Sender: TObject);
begin
if SavePictureDialog1.Execute then
begin
case ImgIndex of
1:image1.Picture.SaveToFile(SavePictureDialog1.FileName);
2:image2.Picture.SaveToFile(SavePictureDialog1.FileName);
3:image3.Picture.SaveToFile(SavePictureDialog1.FileName);
4:image4.Picture.SaveToFile(SavePictureDialog1.FileName);
5:image5.Picture.SaveToFile(SavePictureDialog1.FileName);
6:image6.Picture.SaveToFile(SavePictureDialog1.FileName);
end;
end;
end;

procedure TFrmprv.SpeedButton5Click(Sender: TObject);
begin
speedbutton4.Enabled:=false;
speedbutton6.Enabled:=false;
frmqry.showmodal;
if Myjxbool=true then
begin
szPoint(paintbox1,image1,label1,Mycsbmp,Mymnsj.Acn1);
szPoint(paintbox2,image2,label2,image1,Mymnsj.Acn2);
szPoint(paintbox3,image3,label3,image2,Mymnsj.Acn3);
szPoint(paintbox4,image4,label4,image3,Mymnsj.Acn4);
szPoint(paintbox5,image5,label5,image4,Mymnsj.Acn5);
szPoint(paintbox6,image6,label6,image5,Mymnsj.Acn6);
end;
SpeedButton3.Enabled:=true;
SpeedButton2.Enabled:=true;
SpeedButton1.Enabled:=true;
end;

procedure TFrmprv.N2Click(Sender: TObject);
var
myrec:trect;
myimage:timage;
begin
myimage:=timage.Create(self);
myimage.Width:=image1.Width*3;
myimage.Height:=image1.Height*2;
myimage.Transparent:=true;
myrec:=rect(0,0,image1.Picture.Width,image1.Picture.Height);
myimage.Canvas.CopyRect(myrec,image1.Canvas,image1.ClientRect);
myrec:=rect(image1.Width+5,0,image1.Width+image2.Width,image2.Height);
myimage.Canvas.CopyRect(myrec,image2.Canvas,image2.ClientRect);
myrec:=rect(image1.Picture.Width+5+image2.Picture.Width,0,image1.Width+image2.Width+image3.Width,image3.Height);
myimage.Canvas.CopyRect(myrec,image3.Canvas,image3.ClientRect);
myrec:=rect(0,image1.Height+5,image4.Width,image1.picture.Height+image1.Picture.Height);
myimage.Canvas.CopyRect(myrec,image4.Canvas,image4.ClientRect);
myrec:=rect(image4.Width+5,image4.Height+5,image3.Width+image4.Width,image3.Height*2);
myimage.Canvas.CopyRect(myrec,image5.Canvas,image5.ClientRect);
myrec:=rect(image4.Width+image5.Width+5,image5.Height+5,image3.Width+image4.Width+image5.width,image3.Height*2);
myimage.Canvas.CopyRect(myrec,image6.Canvas,image5.ClientRect);
if SavePictureDialog1.Execute then
myimage.Picture.SaveToFile(SavePictureDialog1.FileName);
end;

procedure TFrmprv.SpeedButton2Click(Sender: TObject);
begin
with TFrmtpfx.Create(application,FArrimgeValue)do
begin
showmodal;
free;
end;
end;

procedure TFrmprv.SpeedButton3Click(Sender: TObject);
begin
FArrIge[1]:=image1;
FArrIge[2]:=image2;
FArrIge[3]:=image3;
FArrIge[4]:=image4;
FArrIge[5]:=image5;
FArrIge[6]:=image6;
with TFrmpic.Create(self,FArrIge)do
begin
showmodal;
free;
end;
end;

procedure TFrmprv.SpeedButton6Click(Sender: TObject);
begin
with TFrmAbout.Create(self)do
begin
showmodal;
free;
end;
end;

end.
.
 

Similar threads

S
回复
0
查看
3K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
2K
SUNSTONE的Delphi笔记
S
D
回复
0
查看
2K
DelphiTeacher的专栏
D
D
回复
0
查看
2K
DelphiTeacher的专栏
D
后退
顶部