滚动的小车

来源:互联网 发布:制作二维码生成器软件 编辑:程序博客网 时间:2024/04/30 06:19

滚动的小车

动画技术作为计算机图形学的一部分,已广泛应用。产生动画所采用的方法,有
以下几种:
(1)BITBLT动画,关键在于画面存储和重放。主要用于处理屏幕的一部分,动画速
度受到显示分辨率、显示模式及图形大小等限制。
(2)线框动画,关键在于图形页面的互换,处理对象是分别存放在不同图形页面上
的一系列全屏图像,通过一个子程序以适当的顺序扫描有关页面,得到动画的效果。
(3)实时动画,在动画开始时绘制图像,需要分时处理图像生成和动画实现。
(4)彩色循环动画,利用调色板设置指令,来改变图像颜色,让可见图像消失为背景,
同时又立即使用第二条调色板设置指令恢复另一副图像的正确颜色。两幅图像交替出
现,不断重复,便获得实时动画效果。
动画程序清单:

#define PI 3.1415926
#define step 10
#define R 10
#include<time.h>
#include<stdlib.h>
#include<graphics.h>
#include<conio.h>
#include<dos.h>
main()
{
int gdriver=DETECT,gmode;
static int startx=5;
static int starty=100;
int maxx,l=1,n=1;
double dalta=20,angle;
int size;
void *image;
initgraph(&gdriver,&gmode,"");
cleardevice();
setbkcolor(BLUE);
size=imagesize(startx,starty,startx+60,starty+60);
image=(unsigned char *)malloc(size);
maxx=getmaxx();
while(!kbhit())
{
if(l==1)
{
n++;
angle=-1*(n*step)/PI*180/R;
if((int)(-1*angle)%360<dalta)
angle-=dalta;
if(n>(maxx-70)/step)
l=0;
}
if(l==0)
{
--n;
angle=-1*(n*step)/R/PI*180;
if((int)(-1*angle)%360<dalta)
angle-=dalta;
if(n==1)l=1;
}
rectangle(startx+n*step,starty,startx+n*step+60,starty+40);
pieslice(startx+n*step+15,starty+50,angle,angle-dalta,10);
pieslice(startx+n*step+45,starty+50,angle,angle-dalta,10);
setcolor(GREEN);
setfillstyle(SOLID_FILL,GREEN);
circle(startx+n*step+15,starty+50,10);
circle(startx+n*step+45,starty+50,10);
circle(startx+n*step+15,starty+50,3);
circle(startx+n*step+45,starty+50,3);
getimage(startx+n*step,starty,startx+n*step+60,starty+60,image);
delay(100);
putimage(startx+n*step,starty,image,XOR_PUT);
}
free(image);
closegraph();
}

原创粉丝点击