非常急!!!十万火急!!

Logitechxp 2002-11-05 07:35:33
加精
谢谢哪位高人能帮帮忙,如何用c语言来实现动画效果啊?
...全文
64 15 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
15 条回复
切换为时间正序
请发表友善的回复…
发表回复
Logitechxp 2002-11-12
  • 打赏
  • 举报
回复
找不到啊!
X路人甲X 2002-11-10
  • 打赏
  • 举报
回复
我这里已经运行通过了
WaterWalker 2002-11-10
  • 打赏
  • 举报
回复
你去华军下载个tc。里面带有动画演示程序
www.newhua.com
vampireonline 2002-11-10
  • 打赏
  • 举报
回复
到www.tc256.com这个网上面去找吧,里面挺多的
snoopycy 2002-11-08
  • 打赏
  • 举报
回复
还没弄到吗?上面那位dangerous贴的那个程序行不?
X路人甲X 2002-11-07
  • 打赏
  • 举报
回复
接上面:
void localheader(FILE *fp)
{
struct localhead {
unsigned char label;
unsigned int left;
unsigned int top;
unsigned int width;
unsigned int height;
unsigned char flag;
}image;
image.label=0x2c;
image.left=0;
image.top=0;
image.width=right-left;
image.height=bottom-top;
image.flag=colorbits-1;
if(mode)
image.flag|=0x40;
fwrite(&image,1,10,fp);
}

void cleartable( )
{
int count;
encode=eofcode+1;
runbits=initbits+1;
maxcodesize=1<<runbits;
for(count=0;count<TABLESIZES;count++)
encodetable[count]=0;
}

void savecode(FILE *fp)
{
blockbuf[0]=bytecount;
bytecount++;
fwrite(blockbuf,1,bytecount,fp);
bytecount=0;
}

void fillblockbuf(FILE *fp,int code)
{
tempcode|=(unsigned long)code<<shiftbits;
shiftbits+=runbits;
while(shiftbits>=8) {
blockbuf[++bytecount]=tempcode&0x00FF;
if(bytecount==255)
savecode(fp);
tempcode>>=8;
shiftbits-=8;
}
}

void lzwimage(FILE *fp)
{
unsigned char suffixtable[TABLESIZES],
bytebuf[640],now;
int i,prefixtable[TABLESIZES],
prefixcode,suffixcode,index,off;
unsigned int width,height,row,dot,online;
width=right-left;
height=bottom-top;
initbits=colorbits;
if(initbits>8)
exit(1);
fputc(initbits,fp);
clearcode=1<<initbits;
eofcode=clearcode+1;
bytecount=shiftbits=0;
tempcode=0;
cleartable( );
fillblockbuf(fp,clearcode);
for(row=0,online=0,now=0;row<height;row++) {
for(i=0;i<width;i++)
bytebuf[i]=getpixel(left+i,top+online);
if(mode) {
online+=rowcount[now];
if(online>=height) {
now++;
online=linestart[now];
}
}
else
online++;
if(row==0) {
prefixcode=bytebuf[0];
dot=1;
}
else
dot=0;
while(dot<width) {
suffixcode=bytebuf[dot++];
index=prefixcode^(suffixcode<<4);
if(index==0)
off=1;
else
off=TABLESIZES-index;
while(1) {
if(encodetable[index]==0) {
fillblockbuf(fp,prefixcode);
if(encode==MAXCODES) {
fillblockbuf(fp,clearcode);
cleartable( );
}
else {
if(encode==maxcodesize) {
maxcodesize<<=1;
runbits++;
}
prefixtable[index]=prefixcode;
suffixtable[index]=suffixcode;
encodetable[index]=encode++;
}
prefixcode=suffixcode;
break;
}
if(prefixtable[index]==prefixcode &&
suffixtable[index]==suffixcode) {
prefixcode=encodetable[index];
break;
}
else {
index-=off;
if(index<0)
index+=TABLESIZES;
}
}
}
}
fillblockbuf(fp,prefixcode);
fillblockbuf(fp,eofcode);
if(shiftbits>0||bytecount>0) {
blockbuf[++bytecount]=tempcode&0x00FF;
savecode(fp);
}
fputc(0,fp);
}

void applyblock(FILE *fp)
{
struct {
unsigned char extension;
unsigned char label;
unsigned char size;
char identifier[8];
char code[3];
char data[4];
unsigned char terminator;
}application;
application.extension=0x21;
application.label=0xff;
application.size=11;
memcpy(application.identifier,"NETSCAPE",8);
memcpy(application.code,"2.0",3);
application.data[0]=3;
application.data[1]=1;
application.data[2]=0xe8;
application.data[3]=3;
application.terminator=0;
fwrite(&application,1,19,fp);
}

void controlblock(FILE *fp,int delaytime)
{
struct {
unsigned char extension;
unsigned char label;
unsigned char size;
unsigned char field;
unsigned int delaytime;
unsigned char colorindex;
unsigned char terminator;
}control;
control.extension=0x21;
control.label=0xf9;
control.size=4;
control.field=0;
control.delaytime=delaytime;
control.colorindex=0;
control.terminator=0;
fwrite(&control,1,8,fp);
}

void makegif( )
{
int i,k;
unsigned char color=0;
FILE *fp;
left=220;top=200;right=420;bottom=280;
type=3,mode=0;
byteperpixel=1;width=640;height=480;
if((fp=fopen("256.gif","wb"))==NULL) {
printf("Can not create Gif File!\n");
exit(1);
}
for(i=0;i<64;i++) {
pal[3*i]=4*i;
pal[3*i+1]=0;
pal[3*i+2]=0;
}
for(i=64;i<128;i++) {
pal[3*i]=0;
pal[3*i+1]=4*(i-64);
pal[3*i+2]=0;
}
for(i=128;i<192;i++) {
pal[3*i]=0;
pal[3*i+1]=0;
pal[3*i+2]=4*(i-128);
}
for(i=192;i<256;i++) {
pal[3*i]=4*(i-192);
pal[3*i+1]=4*(i-192);
pal[3*i+2]=4*(i-192);
}
setpalette(pal);
globalheader(fp);
applyblock(fp);
for(k=0;k<4;k++) {
for(i=top;i<bottom;i=i+4) {
level(left,right,i+k,color);
if(color==255)
color=0;
else
color=color+3;
}
controlblock(fp,20);
localheader(fp);
lzwimage(fp);
for(i=top;i<bottom;i=i+4)
level(left,right,i+k,0);
}
fputc(';', fp);
fclose(fp);
}

main( )
{
struct SREGS sregs;
union REGS inregs,outregs;
inregs.x.ax=0x4f00;
sregs.es=FP_SEG(&vgainfo);
inregs.x.di=FP_OFF(&vgainfo);
int86x(0x10,&inregs,&outregs,&sregs);
if(outregs.x.ax!=0x004f||strncmp(
vgainfo.signature,"VESA",4)!=0) {
printf("Sorry! This video Not support VESA...\n");
exit(1);
}
if(setmode(0x101)==0)
makegif( );
else {
textmode(3);
printf("This video NOT support mode 0x%x!\n",0x101);
getch( );
}
textmode(3);
}
X路人甲X 2002-11-07
  • 打赏
  • 举报
回复
以下是生成GIF动画文件的C代码:
#include<stdio.h>
#include<dos.h>
#include<math.h>
#include<alloc.h>
#include<mem.h>
#include<conio.h>
#include<stdlib.h>
#define MAXCODES 4096
#define TABLESIZES 4999

unsigned char pal[768];
int left,top,right,bottom,type,mode;
unsigned char blockbuf[256],colorbits;
int encodetable[TABLESIZES];
int initbits,runbits,shiftbits;
int clearcode,eofcode,encode;
int maxcodesize,bytecount;
unsigned long tempcode;
int linestart[]={0,4,2,1};
int rowcount[]={8,8,4,2};

struct svgainfo
{
unsigned char signature[4];
unsigned int version;
unsigned long far *OEMstringptr;
unsigned char capabilities[4];
unsigned long far *videomodeptr;
unsigned int videomemory;
unsigned char reserved[];
}vgainfo;
struct vesamodeinfo {
unsigned int modeattr;
unsigned char winaattr,winbattr;
unsigned int wingrain,winsize,
winaseg,winbseg;
unsigned long far *winfuncptr;
unsigned int bytesperscanline,width,height;
unsigned char charwidth,charheight,
numberofmemory;
unsigned char bitperpixel,
numberofbanks,memorymodel;
unsigned char banksize,
numberofimagepages;
unsigned char x[];
}modeinfo;
int byteperpixel,width,height;
unsigned char tlib[72];

int setmode(int mode)
{
union REGS in,out;
in.x.ax=0x4f02;
in.x.bx=mode;
int86(0x10,&in,&out);
return(out.h.ah);
}

void setpalette(unsigned char pal[])
{
union REGS in,out;
struct SREGS s;
in.x.ax=0x1012;
in.x.bx=0;
in.x.cx=256;
s.es=FP_SEG(pal);
in.x.dx=FP_OFF(pal);
int86x(0x10,&in,&out,&s);
}

void setpage(int page)
{
union REGS r;
r.x.ax=0x4f05;
r.x.bx=0;
r.x.dx=page;
int86(0x10,&r,&r);
}

void putpixel(long x,long y,unsigned char color)
{
int page;
unsigned long offset;
unsigned char far *ptr=(char far*)(0xa0000000);
offset=byteperpixel*(x+y*width);
page=offset>>16;
ptr=ptr+offset;
setpage(page);
*ptr=color;
}

unsigned char getpixel(long x,long y)
{
int page;
unsigned char color;
unsigned long offset;
unsigned char far *ptr=(char far*)(0xa0000000);
offset=byteperpixel*(x+y*width);
page=offset>>16;
ptr=ptr+offset;
setpage(page);
color=*ptr;
return(color);
}

void line(int x1,int y1,int x2,int y2,unsigned char color)
{
int e,i,x,y,dx,dy,incx,incy;
x=x1;y=y1;
dx=abs(x2-x1);dy=abs(y2-y1);
if(x1<=x2) incx=1;
else incx=-1;
if(y1<=y2) incy=1;
else incy=-1;
if(dx>dy) {
e=2*dy-dx;
for(i=0;i<=dx;i++) {
putpixel(x,y,color);
x=x+incx;
if(e>=0) e=e+2*dy-2*dx;
else e=e+2*dy;
if(e>=0) y=y+incy;
}
}
else {
e=2*dx-dy;
for(i=0;i<=dy;i++) {
putpixel(x,y,color);
y=y+incy;
if(e>=0) e=e+2*dx-2*dy;
else e=e+2*dx;
if(e>=0) x=x+incx;
}
}
}

void level(long x1,long x2,long y,unsigned char color)
{
long x;
unsigned int startseg,endseg;
unsigned long startaddr,endaddr;
unsigned char far *ptr=(char far*)(0xa0000000);
startaddr=byteperpixel*(x1+width*y);
endaddr=startaddr+byteperpixel*width;
ptr+=startaddr;
startseg=startaddr>>16;
endseg=endaddr>>16;
if(startseg==endseg) {
setpage(startseg);
for(x=x1;x<=x2;x++)
*ptr++=color;
}
else
for(x=x1;x<=x2;x++)
putpixel(x,y,color);
}

void rectangle(int left,int top,int right,int bottom,
unsigned char color)
{
level(left,right,top,color);
line(right,top,right,bottom,color);
level(left,right,bottom,color);
line(left,bottom,left,top,color);
}

void bar(int left,int top,int right,int bottom,
unsigned char color)
{
int y;
for(y=top;y<=bottom;y++)
level(left,right,y,color);
}

void cleardevice(unsigned char color)
{
bar(0,0,width-1,height-1,color);
}

void circle(int x0,int y0,int radius,unsigned char color)
{
int i,x,y,distance;
distance=3-2*radius;
x=0;y=radius;
for(i=0;i<=0.707*radius;i++) {
putpixel(x0+x,y0-y,color);
putpixel(x0-x,y0-y,color);
putpixel(x0-y,y0+x,color);
putpixel(x0-y,y0-x,color);
putpixel(x0+x,y0+y,color);
putpixel(x0-x,y0+y,color);
putpixel(x0+y,y0+x,color);
putpixel(x0+y,y0-x,color);
if(distance>=0) {
distance=distance+4*(x-y)+10;
y=y-1;
}
else distance=distance+4*x+6;
x++;
}
}

void globalheader(FILE *fp)
{
int i,colornum;
struct globalhead {
unsigned char signature[6];
unsigned int width;
unsigned int height;
unsigned char flag;
unsigned char color;
unsigned char ratio;
}gif;
memcpy(gif.signature,"GIF89a",6);
gif.width=right-left;
gif.height=bottom-top;
colorbits=8;
gif.flag=(colorbits-1<<4)|(colorbits-1);
if(type!=1)
gif.flag|=0x80;
gif.color=0;gif.ratio=0;
fwrite(&gif,1,13,fp);
if(gif.flag&0x80) {
colornum=3*(1<<colorbits);
fwrite(pal,1,colornum,fp);
}
}
下面还有:
Logitechxp 2002-11-06
  • 打赏
  • 举报
回复
我的avi这个程序不能运行,你可不可以给一个用于示范的avi文件我?我的信箱是:iamzyf@msn.com
snoopycy 2002-11-06
  • 打赏
  • 举报
回复
原来这个办法不行……
Logitechxp 2002-11-05
  • 打赏
  • 举报
回复
程序运行的结果是“can not open avi file”
X路人甲X 2002-11-05
  • 打赏
  • 举报
回复
以上实现的动画可保存为AVI格式
Logitechxp 2002-11-05
  • 打赏
  • 举报
回复
或者是用c实现图形图象,在下实在是等着急用,要实例!希望各位大哥不吝赐教!!!!
X路人甲X 2002-11-05
  • 打赏
  • 举报
回复
#include<stdio.h>
#include<dos.h>
#include<math.h>
#include<alloc.h>
#include<mem.h>
#include<conio.h>
#include<stdlib.h>
#define widthbytes(i) ((i+31)/32*4)

int byteperpixel=1,width=640,height=480;

struct svgainfo {
unsigned char signature[4];
unsigned int version;
unsigned long far *OEMstringptr;
unsigned char capabilities[4];
unsigned long far *videomodeptr;
unsigned int videomemory;
unsigned char reserved[];
}vgainfo;
struct vesamodeinfo {
unsigned int modeattr;
unsigned char winaattr,winbattr;
unsigned int wingrain,winsize,
winaseg,winbseg;
unsigned long far *winfuncptr;
unsigned int bytesperscanline,width,height;
unsigned char charwidth,charheight,
numberofmemory;
unsigned char bitperpixel,
numberofbanks,memorymodel;
unsigned char banksize,
numberofimagepages;
unsigned char x[];
}modeinfo;

struct chunkhead {
unsigned char type[4];
unsigned long size;
}riff,list,block,subblock;

struct aviheader {
unsigned long microsecperframe,
maxbytespersec,reserved1;
unsigned long flags,
totalframes,initialframes,streams;
unsigned long suggestedbuffersize,
width,height,reserved[4];
}avih;

struct avistreamheader {
unsigned char type[4];
unsigned long compression,
reserved1,reserved2,reserved3;
unsigned long streams,quality,
initialframes,totalframes;
unsigned long suggestedbuffersize,
samplesize,reserved[2];
unsigned int width,height;
}strh;

struct bitmapinfo {
unsigned long size,width,height;
unsigned int plane,bitsperpixel;
unsigned long compression,
imagesize,xpels,ypels;
unsigned long colorused,colorimportant;
}bmp;

int setmode(int mode)
{
union REGS in,out;
in.x.ax=0x4f02; in.x.bx=mode;
int86(0x10,&in,&out);
return(out.h.ah);
}

void setpalette(unsigned char pal[])
{
union REGS in,out;
struct SREGS s;
in.x.ax=0x1012; in.x.bx=0; in.x.cx=256;
s.es=FP_SEG(pal);
in.x.dx=FP_OFF(pal);
int86x(0x10,&in,&out,&s);
}

void setpage(int page)
{
union REGS r;
r.x.ax=0x4f05; r.x.bx=0; r.x.dx=page;
int86(0x10,&r,&r);
}

void putpixel(long x,long y,unsigned char color)
{
int page;
unsigned long offset;
unsigned char far *ptr=(char far*)(0xa0000000);
offset=byteperpixel*(x+y*width);
page=offset>>16; ptr=ptr+offset;
setpage(page); *ptr=color;
}

void error(unsigned char *s)
{
textmode(3);
printf("\n%s",s);
exit(1);
}

void showimage(FILE *fp,long bmpwidth,long bmpheight)
{
int x,y,linebytes;
unsigned char color;
linebytes=widthbytes(8*bmpwidth);
for(y=0;y<bmpheight;y++)
for(x=0;x<linebytes;x++) {
color=fgetc(fp);
if(x<bmpwidth)
putpixel(x,bmp.height-1-y,color);
}
}

void playavi( )
{
int i;
unsigned char pal[768],acolor[4],
type[4]=" ";
unsigned long count,subcount,firstframe;
FILE *fp;
if((fp=fopen("color8.avi","rb"))==NULL)
error("Can not open avi file!\n");
fread(&riff,sizeof(riff),1,fp);
if(strncmp(riff.type,"RIFF",4)!=0)
error("Open file error!\n");
fread(type,4,1,fp);
if(strncmp(type,"AVI ",4)!=0)
error("Avi identifier error!\n");
fread(&list,sizeof(list),1,fp);
if(strncmp(list.type,"LIST",4)!=0)
error("List identifier error!\n");
fread(type,4,1,fp);count=4;
if(strncmp(type,"hdrl",4)!=0)
error("Hrdl identifier error!\n");
do {
fread(&block,sizeof(block),1,fp);
if((strncmp(block.type,"avih",4)==0)&&
(block.size==sizeof(avih)))
fread(&avih,sizeof(avih),1,fp);
else
if(strncmp(block.type,"LIST",4)==0) {
fread(type,4,1,fp);subcount=4;
if(strncmp(type,"strl",4)!=0)
error("Strl identifier error!\n");
do {
fread(&subblock,sizeof(subblock),1,fp);
if(strncmp(subblock.type,"strh",4)==0)
fread(&strh,subblock.size,1,fp);
else
if((strncmp(subblock.type,"strf",4)==0)&&
(subblock.size>=sizeof(bmp))) {
fread(&bmp,sizeof(bmp),1,fp);
for(i=0;i<(subblock.size-sizeof(bmp))/4;i++) {
fread(acolor,4,1,fp);
pal[3*i]=acolor[2]>>2;
pal[3*i+1]=acolor[1]>>2;
pal[3*i+2]=acolor[0]>>2;
}
}
else {
subblock.size++;
fseek(fp,subblock.size,1);
}
}while((subcount+=subblock.size+8)<
block.size);
}
else
fseek(fp,block.size,1);
}while((count+=block.size+8)<list.size);
fread(&list,sizeof(list),1,fp);
if(strncmp(list.type,"JUNK",4)==0) {
fseek(fp,list.size,1);
fread(&list,sizeof(list),1,fp);
}
fread(type,4,1,fp);
if(strncmp(type,"movi",4)!=0)
error("Movi identifier error!\n");
firstframe=ftell(fp);
if((bmp.bitsperpixel!=8)||
(bmp.compression!=0))
error("Can not play this format file!\n");
if(setmode(0x101)!=0)
error("This video NOT support mode 0x101!\n");
setpalette(pal);
do {
count=4;
do {
fread(&block,sizeof(block),1,fp);
if((strncmp(block.type,"00dc",4)==0)||
(strncmp(block.type,"00db",4)==0))
showimage(fp,bmp.width,bmp.height);
delay(300);
}while((count+=(block.size+1)/2*2+8)<
list.size);
fseek(fp,firstframe,0);
sleep(1);
}while(!bioskey(1));
fclose(fp);
}

main( )
{
struct SREGS sregs;
union REGS inregs,outregs;
inregs.x.ax=0x4f00;
sregs.es=FP_SEG(&vgainfo);
inregs.x.di=FP_OFF(&vgainfo);
int86x(0x10,&inregs,&outregs,&sregs);
if(outregs.x.ax!=0x004f||strncmp(
vgainfo.signature,"VESA",4)!=0) {
printf("Sorry! This video Not support VESA...\n"); exit(1);
}
playavi( ); getch( ); textmode(3);
}
Logitechxp 2002-11-05
  • 打赏
  • 举报
回复
大哥,我要的实例,不是函数啊!
fengyunjian 2002-11-05
  • 打赏
  • 举报
回复
clear();
line()
lineto()

clear();
line()
lineto()

clear();
line()
lineto()

clear();

65,199

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧