📄 unit1.pas
字号:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
ExtCtrls, Buttons, jpeg;
type
TForm1 = class(TForm)
Panel1: TPanel;
Image1: TImage;
Panel2: TPanel;
SpeedButton1: TSpeedButton;
SpeedButton2: TSpeedButton;
SpeedButton3: TSpeedButton;
SpeedButton4: TSpeedButton;
SpeedButton6: TSpeedButton;
SpeedButton7: TSpeedButton;
Image2: TImage;
Bevel1: TBevel;
procedure SpeedButton1Click(Sender: TObject);
procedure SpeedButton2Click(Sender: TObject);
procedure SpeedButton3Click(Sender: TObject);
procedure SpeedButton4Click(Sender: TObject);
procedure SpeedButton6Click(Sender: TObject);
procedure SpeedButton7Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
//基本图形1
procedure jianbian(var x0,y0,r1,r2:integer);
//x0:=200,y0:=50,r1:=180,r2:=120;
var
x1,y1,x2,y2:array[1..120] of real;
n,i,k:integer;
a,t,x,y:real;
begin
randomize;
form1.image1.canvas.pen.color:=rgb(random(255),random(255),random(255));
n:=50;
a:=0;
for i:=1 to 120 do
begin
x1[i]:=r1*cos(a);
y1[i]:=(-1)*r1*sin(a)/2;
a:=a+pi/60;
end;
a:=0;
for i:=1 to 120 do
begin
t:=(r2*(1+1/2*sin(12*a)))*(1/2+1/2*sin(4*a));
x2[i]:=t*cos(a);
y2[i]:=(-1)*t*sin(a)/2;
a:=a+60/pi;
end;
for k:=0 to n do
for i:=1 to 120 do
begin
x:=(x2[i]-x1[i])/n*k+x1[i];
y:=(y2[i]-y1[i])/n*k+y1[i];
x:=x+x0;
y:=y+y0;
if i=1 then form1.image1.canvas.moveto(trunc(x*1.1/2),trunc(y));
form1.image1.canvas.lineto(trunc(x*1.1/2),trunc(y));
end;
end;
//基本图形2
procedure jingangshi(var x0,y0,r:integer; n:integer);
//分段数n:=25,半径r:=130,中心点x0:=180,y0:=150;
var
t:real;
i,j:integer;
x,y:array of real;
begin
randomize;
form1.Image1.Canvas.Pen.Color:=rgb(random(255),random(255),random(255));
setlength(x,n+1);
setlength(y,n+1);
t:=2*pi/n;
for i:=0 to n do
begin
x[i]:=r*cos(i*t)+x0;
y[i]:=r*sin(i*t)+y0;
end;//通过循环求出图案坐标点
for i:=0 to n-2 do
for j:=i+1 to n-1 do
begin
form1.Image1.Canvas.MoveTo(trunc(x[i]),trunc(y[i]));
form1.Image1.Canvas.LineTo(trunc(x[j]),trunc(y[j]));
end;
end;
//基本图形3
procedure jianmt(var x0,y0,r1,r2:integer);
var
x1:array[1..120]of real;
Y1:array[1..120]of real;
X2:array[1..120]of real;
Y2:array[1..120]of real;
a,t,x,y:real;
n,i,k:integer;
begin
n:=50;
a:=0;
for i:=1 to 120 do
begin
x1[i]:=r1*cos(a);
y1[i]:=(-1)*r1*sin(a)/2;
a:=a+pi/60;
end;
a:=0;
for i:=1 to 120 do
begin
t:=(r2*(1+1/2*sin(12*a)))*(1/2+1/2*sin(4*a));
x2[i]:=t*cos(a);
y2[i]:=(-1)*t*sin(a)/2;
a:=a+pi/60;
end;
for k:=0 to n do
for i:=1 to 120 do
begin
randomize;
form1.image1.canvas.Pen.color:=rgb(random(255),random(255),random(255));
x:=(x2[i]-x1[i])/n*k+x1[i];
y:=(y2[i]-y1[i])/n*k+y1[i];
x:=x+x0;
y:=y+y0;
if i=1 then
form1.image1.canvas.moveto(trunc(x*1.1/2),trunc(y));
form1.image1.canvas.lineto(trunc(x*1.1/2),trunc(y));
end;
end;
//基本图形4
procedure flower(var x,y,d:integer);
var
mycolor:tcolor;
begin
randomize;
with form1.image1.canvas do
begin
pen.Color:=rgb(random(255),random(255),random(255));
pen.Width:=1;
brush.Color:=rgb(random(255),random(255),random(255));
brush.Style:=bssolid;
ellipse(trunc(x-d/4),trunc(y-d/2),trunc(x+d/4),trunc(y));
end;
with form1.image1.canvas do
begin
pen.Color:=rgb(random(255),random(255),random(255));
pen.Width:=1;
brush.Color:=rgb(random(255),random(255),random(255));
brush.Style:=bssolid;
ellipse(trunc(x-d/8),trunc(y-3*d/8),trunc(x+d/8),trunc(y-d/8));
end;
with form1.image1.canvas do
begin
mycolor:=rgb(random(255),random(255),random(255));
pen.Color:=mycolor;
pen.Width:=4;
brush.Color:=mycolor;
brush.Style:=bssolid;
moveto(x,y);
lineto(x,trunc(y+d/2));
arc(trunc(x-d),trunc(y),trunc(x),trunc(y+d),trunc(x),trunc(y+d/2),trunc(x-d/2),trunc(y));
arc(trunc(x),trunc(y),trunc(x+d),trunc(y+d),trunc(x+d/2),trunc(y),trunc(x),trunc(y+d/2));
arc(trunc(x-d/2),trunc(y-d/2),trunc(x+d/2),trunc(y+d/2),trunc(x-d/2),trunc(y),trunc(x+d/2),trunc(y));
floodfill(trunc(x-d/4),trunc(y+d/4),mycolor,fsborder);
floodfill(trunc(x+d/4),trunc(y+d/4),mycolor,fsborder);
pen.Width:=1;
end;
end;
//基本图形5
procedure fengche(var x,y,d:integer);
var
mycolor:tcolor;
begin
mycolor:=rgb(random(255),random(255),random(255));
with form1.Image1.Canvas do
begin
pen.Color:=mycolor;
pen.Width:=1;
brush.Color:=mycolor;
brush.Style:=bssolid;
moveto(trunc(x-d/2),trunc(y-d/2));
lineto(trunc(x+d/2),trunc(y+d/2));
moveto(trunc(x-d/2),trunc(y+d/2));
lineto(trunc(x+d/2),trunc(y-d/2));
arc(trunc(x-d),trunc(y-d/2),trunc(x),trunc(y+d/2),trunc(x),trunc(y),trunc(x-d/2),trunc(y-d/2));
arc(trunc(x-d/2),y-d,trunc(x+d/2),trunc(y),trunc(x),trunc(y),trunc(x+d/2),trunc(y-d/2));
arc(trunc(x),trunc(y-d/2),trunc(x+d),trunc(y+d/2),trunc(x),trunc(y),trunc(x+d/2),trunc(y+d/2));
arc(trunc(x-d/2),y,trunc(x+d/2),trunc(y+d),trunc(x),trunc(y),trunc(x-d/2),trunc(y+d/2));
floodfill(trunc(x-d/4+1),trunc(y-d/4-1),mycolor,fsborder);
floodfill(trunc(x+d/4+1),trunc(y-d/4+1),mycolor,fsborder);
floodfill(trunc(x-d/4-1),trunc(y+d/4-1),mycolor,fsborder);
floodfill(trunc(x+d/4-1),trunc(y+d/4+1),mycolor,fsborder);
end;
end;
//基本图形6
procedure quxian(var x,y,d:integer);
begin
with form1.image1.canvas do
begin
pen.Color:=rgb(random(255),random(255),random(255));
pen.Width:=3;
brush.Color:=rgb(random(255),random(255),random(255));
brush.Style:=bssolid;
arc(trunc(x),trunc(y-d/2),trunc(x+d),trunc(y+d/2),trunc(x+d/2),trunc(y-d/2),trunc(x),trunc(y));
arc(trunc(x-d),trunc(y-d/2),trunc(x),trunc(y+d/2),trunc(x-d/2),trunc(y+d/2),trunc(x),trunc(y));
arc(trunc(x-d/2),trunc(y-d),trunc(x+d/2),trunc(y),trunc(x-d/2),trunc(y-d/2),trunc(x),trunc(y));
arc(trunc(x-d/2),trunc(y),trunc(x+d/2),trunc(y+d),trunc(x+d/2),trunc(y+d/2),trunc(x),trunc(y));
pen.Width:=1;
end;
end;
//基本图形7
procedure leaf(var x,y:integer;length,fai:real);
var //保证length大于十
x1,y1:integer;
nx,ny,p,q:integer;
re1,re2:real;
begin
x1:=round(x+length*cos(fai*pi/180));
y1:=round(y-length*sin(fai*pi/180));
re1:=0.618;
q:=100;
form1.image1.Canvas.moveto(x,y);
form1.image1.Canvas.LineTo(x1,y1);
if length>=10 then
begin
re2:=length;
nx:=x;
ny:=y;
for p:=0 to 8 do
begin
nx:=nx+round(re2*(1-re1)*cos(fai*pi/180));
ny:=round(ny-re2*(1-re1)*sin(fai*pi/180));
leaf(nx,ny,re2*(1-re1),(fai+q));
leaf(nx,ny,re2*(1-re1),(fai-q));
re2:=re2*re1;
end;
end;
end;
procedure TForm1.SpeedButton1Click(Sender: TObject);
var
x0,y0,r1,r2:integer;
begin
image1.Canvas.Brush.Color:=rgb(random(255),random(255),random(255));
image1.Canvas.Rectangle(0,0,image1.width,image1.height);
randomize;
image1.Canvas.Brush.Color:=rgb(random(255),random(255),random(255));
x0:=450;
y0:=180;
r1:=100;
r2:=300;
jianmt(x0,y0,r1,r2);
end;
procedure TForm1.SpeedButton2Click(Sender: TObject);
var
x0,y0,r1,r2:integer;
begin
image1.Canvas.Brush.Color:=rgb(random(255),random(255),random(255));
image1.Canvas.Rectangle(0,0,image1.width,image1.height);
randomize;
image1.Canvas.Brush.Color:=rgb(random(255),random(255),random(255));
x0:=450;
y0:=180;
r1:=280;
r2:=100;
jianbian(x0,y0,r1,r2);
end;
procedure TForm1.SpeedButton3Click(Sender: TObject);
var
x0,y0,r,n:integer;
begin
image1.Canvas.Brush.Color:=rgb(random(255),random(255),random(255));
image1.Canvas.Rectangle(0,0,image1.width,image1.height);
randomize;
image1.Canvas.Brush.Color:=rgb(random(255),random(255),random(255));
x0:=250;
y0:=180;
r:=150;
n:=25;
jingangshi(x0,y0,r,n);
end;
procedure TForm1.SpeedButton4Click(Sender: TObject);
var
x0,y0,r1,r2,n:integer;
i,j:integer;
begin
image1.Canvas.Brush.Color:=rgb(random(255),random(255),random(255));
image1.Canvas.Rectangle(0,0,image1.width,image1.height);
randomize;
image1.Canvas.Brush.Color:=rgb(random(255),random(255),random(255));
x0:=120;
y0:=60;
r1:=50;
r2:=100;
n:=15;
case random(3) of
0: for i:=1 to 3 do
begin
for j:=1 to 3 do
begin
jianmt(x0,y0,r1,r2);
y0:=y0+130;
end;
x0:=x0+340;
y0:=60;
end;
1: for i:=1 to 3 do
begin
for j:=1 to 3 do
begin
jianbian(x0,y0,r2,r1);
y0:=y0+130;
end;
x0:=x0+340;
y0:=60;
end;
2: for i:=1 to 3 do
begin
for j:=1 to 3 do
begin
jingangshi(r2,y0,r1,n);
y0:=y0+130;
end;
r2:=r2+170;
y0:=60;
end;
end;
end;
procedure TForm1.SpeedButton6Click(Sender: TObject);
var
x0,y0,r1,r2,n,i:integer;
begin
image1.Canvas.Brush.Color:=rgb(random(255),random(255),random(255));
image1.Canvas.Rectangle(0,0,image1.width,image1.height);
randomize;
//基本图形1
x0:=random(300);
y0:=random(200);
r1:=random(280)+1;
r2:=random(100)+1;
jianbian(x0,y0,r1,r2);
//基本图形2
x0:=random(300)+150;
y0:=random(200)+100;
r1:=random(150)+1;
n:=random(30)+1;
jingangshi(x0,y0,r1,n);
//基本图形3
x0:=random(300)+200;
y0:=random(300)+100;
r1:=random(100)+1;
r2:=random(300)+1;
jianmt(x0,y0,r1,r2);
//基本图形4
x0:=random(300)+100;
y0:=random(360)+100;
n:=random(100)+50;
flower(x0,y0,n);
//基本图形5
x0:=random(200)+100;
y0:=random(200)+100;
n:=random(100)+50;
fengche(x0,y0,n);
//基本图形6
x0:=random(300)+100;
y0:=random(200)+100;
n:=random(100)+50;
quxian(x0,y0,n);
//基本图形7
x0:=random(300)+100;
y0:=random(300)+100;
r1:=random(200)+150;
r2:=random(200)+100;
leaf(x0,y0,r1,r2);
//基本图形8
for i:=0 to random(200)+100 do
image1.Canvas.Pixels[i+160,i+100]:=rgb(random(255),random(255),random(255));
//基本图形9
image1.Canvas.Brush.Color:=rgb(random(255),random(255),random(255));
image1.Canvas.Rectangle(random(250),random(250),random(250),random(250));
//基本图形10
image1.Canvas.Brush.Color:=rgb(random(255),random(255),random(255));
image1.Canvas.Ellipse(random(150),random(150),random(150),random(150));
end;
procedure TForm1.SpeedButton7Click(Sender: TObject);
begin
close;
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -