下面給出3D效果制作子程序:
1、 背景制作子程序
本段程序是用來畫背景,只要給出不同的顏色RGB值就能畫出不同的背景。下面的子程序都是利用對象的畫布Canvas並按一定的算法來生成效果。
procedure draw_bk(Sender:TForm;R,G,B:integer);
var i,j,k:integer;
begin
with Sender do
begin
canvas.pen.style:=psSolid;
canvas.pen.width:=1;
k:=(B div 3)*2;
for i:=0 to 480 do
begin
if i<k then j:=0 else j:=j+1;
if j>B then j:=B;
Canvas.pen.color:=rgb(R,G,B-j);
canvas.moveTo(0,i);
canvas.lineTo(640,i);
end;
end;
end;
2、 邊框周圍銅柱子程序
本段程序是用來畫窗口周圍的銅柱,只要給出不同的顏色RGB值就能畫出不同顏色的柱子。
procedure draw_roll(Sender:TForm;X0,Y0,W,H,R,G,B,lw:integer);
var i,J,j1,J2,J3,m,X,Y:integer;
begin
J1:=R div lw-2;
J2:=G div lw;
J3:=B div lw+2;
m:=lw div 3;
with Sender do
begin
for i:=0 to lw do
begin
if i<m then j:=m-i else j:=i-m;
Canvas.pen.color:=rgb(R-J1*J,G-J2*J,B-J3*J);
canvas.moveTo(i+X0,i+Y0);
canvas.lineTo(i+X0,H-i+Y0);
Canvas.pen.color:=rgb(R-J1*J,G-J2*J,B-J3*J);
canvas.moveTo(W-i-1+X0,i+Y0);
canvas.lineTo(W-i-1+X0,H-i+Y0);
Canvas.pen.color:=rgb(R-J1*J,G-J2*J,B-J3*J);
canvas.moveTo(i+X0,i+Y0);
canvas.lineTo(W-i+X0,i+Y0);
Canvas.pen.color:=rgb(R-J1*J,G-J2*J,B-J3*J);
canvas.moveTo(i+X0,H-i+Y0);
canvas.lineTo(W-i+X0,H-i+Y0);
end;
end;
end;