用計(jì)算機(jī)程序制作三維立體畫
該程序寄生在Windows 3.1中的Pbrush軟件上。借助于它來構(gòu)筑立體形體(即立體形體水平剖面高低坐標(biāo)數(shù)據(jù)文件圖8),設(shè)計(jì)原始圖案(圖9)。程序運(yùn)行后,逐行輸入并處理以上兩個文件中的圖形,然后輸出立體畫結(jié)果文件(圖10)。最后,用Pbrush來觀賞立體畫result.bmp。當(dāng)然,要設(shè)計(jì)出令人賞心悅目的立體畫,必須在立體形體和圖案素材的選擇和搭配上做到天衣無縫,獨(dú)具匠心。
@@09A04007.GIF;圖8@@
@@09A04008.GIF;圖9@@
@@09A04009.GIF;圖10程序清單@@
/*--from 1995.4.19--to 1995.5.18----*/includestdio.h>
#define COMPRESSION 0
#define SIZE-OF-BITMAPFILEHEADER 14
#define SIZE-OF-BITMAPINFOHEADER 40
#define SIZE-OF-RGBQUAD 4
#define PIXEL-DATE-OFFSET 14+40+4*16
/*SIZE-OF-BITMAPFILEHEADER+SIZE-OF-BITMAPINFOHEADER+BITS-PER-PIXEL
*NUM-COLOR*/
#define NUM-COLOR 16
#define NUM-LINE 400
#define WIDTH 640
#define BITS-PER-PIXEL 4
#define PIXEL-PER-BYTE 2 /*8/BITS-PER-PIXEL*/
#define BYTE-PER-LINE 320 /*((WIDTH*BITS-PER-PIXEL-1)/32+1)*4 */
#define NO-DOT WIDTH+1
#define EYE-SPACE 128
struct{
unsignde char color ;
unsigned int pri-x ;
unsigned int nxt-x ;
}dot[WIDTH];
main()
{
struct tagBITMAPFILEHEADER{
unsigned char bfType1,bfType2; /* always equal to#39;BM#39;*/
unsigned long int bfSize; /*size of file */
unsigned int bfReserved1,bfReserved2; /* set to zero */
unsiged long int bfoffits; /*byte offset from BITMAPFILEHEADER to bitmap p
ixel
data in the file */
}BITMAPFILEHEADER;
struct tagBITMAPINFOHEADER{
unsigned long int biSize,/* size of BITMAPINFOHEADER */
biWidth;/* width in pixels biHeight;/* height in pixels */
unsigned int biPlanes, /* always 1 */
biBitCount; /* color bits per pixel must be 1,4,8 or 24 */
unsigned long int biCompression, /*BI-RGB,BI-RLE 8 or 4*/
biSizeImage, /*total bytes in image */
biXPelsPerMeter,/* 0,or opt,h res. */
biYPelsPerMeter,/* 0,or opt,h res. */
biClrUsed, /* normally 0,can set a lower no. colors than biBitCount */
biClrImportant; /* normally 0 */
}BITMAPINFOHEADER;
struct tagRGBQUAD{
unsigned char rgbBlue, /* blue intensity,0-255 */
rgbGreen, /* green intensity,0-255 */
rgbRed, /* red intensity,0-255 */
rgbReserved; /* reserved,set to Zero */
}RGBQUAD[NUM-COLOR];
char *fn-layer=layer.bmp;
char *fn-org=origin.bmp;
char *fn-result=result.bmp;
FILE *flayer,*fOrigin, *fResult;
unsigned char tmp-byte1,tmp-byte2;
unsigned int line,i-byte,i-pixel,x;
unsigned int layer;
int left-x,right-x;tmp-x;
unsigned long int cur-offset;
unsigned char h[WIDTH],org-color[WIDTH];
puts(---WINTRICK---);
puts(---by Li Jisong ---);
if( (fLayer=fopen(fn-layer,rb) )!=NULL) {
fread(BITMAPFILEHEADER,SIZE-OF-BITMAPFILEHADER,1,fLayer);
fread(BITMAPINFOHEADER,SIZE-OF-BITMAPINFOHEADER,1,fLayer);
if( BITMAPFILEHEADER.bfType1==#39;B#39; BITMAPFILEHEADER.bfType2==#39;M#39;
BITMAPINFOHEADER.biWidth==WIDTH BITMAPINFOHEADER.biHeight==NUM-
LINE
BITMAPINFOHEADER.biBitCount==BITS-PER-PIXEL
BITMAPINFOHEADER.biCompression==COMPRESSION)
fread(RGBQUAD,SIZE-OF-RGBQUAD,NUM-COLOR,fLayer);
else{
fclose(fLayer);
printf(File %s is not fit for this program! ,fn-layer);
getch();
exit(1);
}
}
else{
printf(File %s does not exist! ,fn-layer);
getch();
exit(2);
}
if( (fOrigin=fopen(fn-org,rb))!=NULL) {
fread( BITMAPFILEHEADER,SIZE-OF-BITMAPFILEHEADER,1,fOrigin);
fread( BITMAPINFOHEADER,SIZE-OF-BITMAPINFOHEADER,1,fOrigin);
if( BITMAPFILEHEADER.bfType1==#39;B#39; BITMAPFILEHEADER.bfType2==#39;M#39;
BITMAPINFOHEADER.biWidth==WIDTH BITMAPINFOHDADER.biHeight==NUM-LINE
BITMAPINFOHEADER.biBitCount==BITS-PER-PIXEL
BITMAPINFOHEADER.biCompression==COMPRESSION)
fread(RGBQUAD,SIZE-OF-RGBQUAD,NUM-COLOR,fOrigin);
else {
fclose(fOrigin);
printf(File %s is not fit for this program! ,fn-org);
getch();
exit(3);
}
}
else {
printf(File %s does not exist! ,fn-org);
getch();
exit(4);
}
if( (fResult=fopen(fn-result,wb))!=NULL){
fwrite(BITMAPFILEHEADER,SIZE-OF-BITMAPFILEHEADER,1,fResult);
fwrite( BITMAPINFOHIADER,SIZE-OF-BITMAPINFOHEADER,1,fResult);
fwrite(RGBQUAD,SIZE-OF-RGBQUAD,NUM-COLOR,fResult);
c語言相關(guān)文章:c語言教程
評論