您的位置:

用c语言运行时钟的动画,用c语言编写一个时钟程序

本文目录一览:

同学,怎么用C语言制作简单的动画啊?

因为C的图形处理功能太一般,不便于创作大型动画。制作动画用flash。

flash制作动画:

打开Flash,点击【文件】→【新建】,在打开的“新建”窗口中选择“Flash文件(ActiveScript 3.0)“,然后点击”确定“创建空白文档。

点击【插入】→【新建元件】,在打开的”新建元件“窗口中,将名称设置为”运动的小人“,勾选”影片剪辑“,然后点击”确定“按钮。

点击【文件】→【导入】→【导入到库】,然后在打开的”导入到库“窗口中,选择事先准备好的小人走动姿势图片,全部选择并点击”打开“按钮,导入到库。

在图层1 的第一帧,把库中的“Result0”拖动到场景中。

点击“时间轴”上的“新建图层”按钮,创建图层2,然后在图层2的第5帧处,点击【插入】→【关键帧】,把库中的“Result1”拖动到场景中。

利用同样的原理,将”Result2“、 ”Result3“和”Result4“分别到图层3、图层4和图层5中,对应的帧分别为10、15和20处。

最后调整各个图层图像的延续时间。至此,运动的小人影片剪辑制作完成。

切换至主场景中,使主场景处于活动状态,点击”属性“面板中的”大小“按钮,将场景的大小设置为”800*300“,同时将背景色设置为”黑色“点击”确定“按钮。

从库中将”运动的小人“影片剪辑拖动到场景左边外边。

然后在”时间轴“第30帧处,点击【插入】→【时间轴】→【关键帧】,在30帧处插入关键帧,然后将小人从场景的左侧外面拖动到场景右侧外面。至此,整个动画设置完成。

在1到30帧之间鼠标右击,选择”创建补间动画“。

最后按下键盘组合键”CTRL+Enter“进行测试。如果感觉小人运动不规律,可适当将1至30帧的距离调整的稍微大一些,直到满意为止。

C语言程序设计题:模拟时钟转动的程序,怎么做?

/*开发环境:turbo c 2.0模拟时钟转动程序代码*/ #include"graphics.h" #include"math.h" #include"dos.h" #define pi 3.1415926 #define X(a,b,c) x=a*cos(b*c*pi/180-pi/2)+300 #define Y(a,b,c) y=a*sin(b*c*pi/180-pi/2)+240 #define d(a,b,c) X(a,b,c);Y(a,b,c);line(300,240,x,y) void init() /*划时钟边框函数*/ { int i,l,x1,x2,y1,y2; setbkcolor(1); circle(300,240,200); circle(300,240,205); circle(300,240,5); for(i=0;i60;i++) /*划钟点上的短线*/ { if(i%5==0) l=15; else l=5; x1=200*sin(i*6*pi/180)+300; y1=200*cos(i*6*pi/180)+240; x2=(200-l)*sin(i*6*pi/180)+300; y2=(200-l)*cos(i*6*pi/180)+240; line(x1,y1,x2,y2); } } main() { int x,y,i,k=1; int gdriver=9,gmode=2; unsigned char h,m,s; int o,p,q; float n; struct time t[1]; struct date d[1]; initgraph(gdriver,gmode,"c:\\tc"); initgraph(gdriver,gmode,"c:\\tc"); for(i=0;i=6;i++) { settextstyle(TRIPLEX_FONT,HORIZ_DIR,i); /*控制输出字符的字体,方向,大小*/ cleardevice(); settextjustify(1,1); /*在指定坐标上输出字符串*/ outtextxy(300,80,"12") ; outtextxy(300,390,"6"); outtextxy(140,230,"9"); outtextxy(460,230,"3"); outtextxy(380,100,"1"); outtextxy(220,100,"11"); outtextxy(430,160,"2"); outtextxy(430,310,"4"); outtextxy(380,370,"5"); outtextxy(220,370,"7"); outtextxy(160,160,"10"); outtextxy(160,310,"8"); } init(); setwritemode(1); /*设置画线的输出模式*/ if(k!=0) { getdate(d); /*获得系统日期函数*/ o=d[0].da_year; p=d[0].da_mon; q=d[0].da_day; gettime(t); /*获得系统时间函数*/ h=t[0].ti_hour; m=t[0].ti_min; s=t[0].ti_sec; } setcolor(7); /*设置时针颜色*/ n=(float)h+(float)m/60; d(150,n,30); /*画出时针*/ setcolor(14); /*设置分针颜色*/ d(170,m,6); /*画出分针*/ setcolor(4); /*设置秒针颜色*/ d(190,s,6); /*画出秒针*/ while(!kbhit()) /*控制程序按下任意键退出*/ { while(t[0].ti_sec==s) gettime(t); gotoxy(44,18); /*使光标移动到指定坐标*/ printf("\b\b\b\b\b\b\b\b\b"); /*退格,使表示时间的字符串不断变化*/ sound(400); /*按给定的频率打开PC扬声器*/ delay(70); /*中断程序的执行,时间为70毫秒*/ sound(200); delay(30); nosound(); /*按给定的频率关闭PC扬声器*/ setcolor(4); d(190,s,6); s=t[0].ti_sec; d(190,s,6); if(t[0].ti_min!=m) { setcolor(14); d(170,m,6); m=t[0].ti_min; d(170,m,6); } if(t[0].ti_hour!=h) { setcolor(7); d(150,h,30); h=t[0].ti_hour; d(150,h,30); sound(1000); delay(240); nosound(); delay(140); sound(2000); delay(240); nosound(); } if(s10) /*用字符的形式输出时间*/ { if(m10) printf("%u:0%u:0%u",h,m,s); else printf("%u:%u:0%u",h,m,s); } else { if(m10) printf("%u:0%u:%u",h,m,s); else printf("%u:%u:%u",h,m,s); } gotoxy(34,19); /*在指定坐标上输出日期*/ printf("%d年%d月%d日",o,p,q); printf("\b\b\b\b\b\b\b\b\b"); } getch(); closegraph(); }

用C语言编写模拟石英钟程序

TurboC - 八角形指针式罗马表

#include dos.h

#include math.h

#include conio.h

#include stdio.h

#include stdlib.h

#include graphics.h

void drawhourbrick(int x, int y, int color, float arg);

void drawminutebrick(int x, int y, int color, float arg);

void drawsecondbrick(int x, int y, int color, float arg);

void polygon(int n, int x, int y, int r, int color, float arg, int fillstyle);

int main()

{

int GraphDriver;

int GraphMode;

float arg = 292.5;

float hourarg = 0;

float minuterarg = 0;

float secondrarg = 0;

char buffer[10];

int a, b;

int x, y, r;

int h;

int xmo[12] = {1, 2, -6, -1, -1, -2, -2, -1, 0, -4, -4, -5};

int ymo[12] = {-1, -2, -1, -1, -1, -5, 2, 1, -2, -4, -4, 0};

long delay;

float degree;

struct time time, time1;

GraphDriver = DETECT;

initgraph(GraphDriver, GraphMode, "");

x = 300;

y = 220;

r = 200;

degree = atan(1) / 45;

polygon(8, x, y, r, 12, arg, 0);

polygon(8, x, y, r - 2, 11, arg, 0);

polygon(8, x, y, r - 4, 14, arg, 0);

setcolor(12);

for (a = 0; a 12; a++)

{

sprintf(buffer, "%d", a + 1);

outtextxy(x + (r - 22) * cos((a - 2) * 30 * degree) + xmo[a], y + (r - 22) * sin((a - 2) * 30 * degree) + ymo[a], buffer);

}

drawhourbrick(x, y, 14, hourarg);

drawminutebrick(x, y, 9, minuterarg);

drawsecondbrick(x, y, 13, secondrarg);

while(1)

{

gettime(time);

if (time.ti_hour != time1.ti_hour || time.ti_min != time1.ti_min || time.ti_sec != time1.ti_sec)

{

h = time.ti_hour;

if (h 12)

h -= 12;

drawhourbrick(x, y, 0, hourarg);

drawminutebrick(x, y, 0, minuterarg);

drawsecondbrick(x, y, 0, secondrarg);

hourarg = (h % 12) * 30 + time.ti_min * 0.5 + time.ti_sec * 0.1 / 60;

minuterarg = time.ti_min * 6 + time.ti_sec * 0.1;

secondrarg = time.ti_sec * 6;

setcolor(8);

outtextxy(x - 15, y + 120, "Roma");

drawhourbrick(x, y, 14, hourarg);

drawminutebrick(x, y, 9, minuterarg);

drawsecondbrick(x, y, 13, secondrarg);

time1 = time;

}

while(kbhit())

{

a = getch();

if (a == 27)

{

closegraph();

return 0;

}

}

}

}

void polygon(int n, int x, int y, int r, int color, float arg, int fillstyle)

{

double pi;

int i;

float x1[9], y1[9];

setcolor(color);

pi = atan(1) * 4;

arg = atan(1) / 45 * arg;

x1[1] = x + r * cos(2 * pi / n + arg);

y1[1] = y + r * sin(2 * pi / n + arg);

moveto(x1[1], y1[1]);

for (i = 2; i = n; i++)

{

x1[i] = x + r * cos(2 * pi * i / n + arg);

y1[i] = y + r * sin(2 * pi * i / n + arg);

lineto(x1[i], y1[i]);

}

lineto(x1[1], y1[1]);

if (fillstyle != 0)

{

setfillstyle(SOLID_FILL, color);

floodfill(x, y, color);

}

}

void drawhourbrick(int x, int y, int color, float arg)

{

double pi;

int i;

float x1[4], y1[4];

setcolor(color);

pi = atan(1) / 45;

x1[0] = x;

y1[0] = y;

x1[1] = x + 20 * cos(pi * (arg - 90 - 23));

y1[1] = y + 20 * sin(pi * (arg - 90 - 23));

x1[2] = x + 25 * cos(pi * (arg - 90 + 23));

y1[2] = y + 25 * sin(pi * (arg - 90 + 23));

x1[3] = x + 120 * cos(pi * (arg - 90 + 0));

y1[3] = y + 120 * sin(pi * (arg - 90 + 0));

moveto(x1[1], y1[1]);

lineto(x1[0], y1[0]);

lineto(x1[2], y1[2]);

lineto(x1[3], y1[3]);

lineto(x1[1], y1[1]);

setfillstyle(SOLID_FILL, color);

/*

floodfill((x1[0] + x1[3]) / 2, (y1[0] + y1[3]) / 2, color);

*/

}

void drawminutebrick(int x, int y, int color, float arg)

{

double pi;

int i;

float x1[4], y1[4];

setcolor(color);

pi = atan(1) / 45;

x1[0] = x;

y1[0] = y;

x1[1] = x + 20 * cos(pi * (arg - 90 - 23));

y1[1] = y + 20 * sin(pi * (arg - 90 - 23));

x1[2] = x + 25 * cos(pi * (arg - 90 + 23));

y1[2] = y + 25 * sin(pi * (arg - 90 + 23));

x1[3] = x + 160 * cos(pi * (arg - 90 + 0));

y1[3] = y + 160 * sin(pi * (arg - 90 + 0));

moveto(x1[1], y1[1]);

lineto(x1[0], y1[0]);

lineto(x1[2], y1[2]);

lineto(x1[3], y1[3]);

lineto(x1[1], y1[1]);

setfillstyle(SOLID_FILL, color);

/*

floodfill((x1[0] + x1[3]) / 2, (y1[0] + y1[3]) / 2, color);

*/

}

void drawsecondbrick(int x, int y, int color, float arg)

{

double pi;

int i;

float x1[4], y1[4];

setcolor(color);

pi = atan(1) / 45;

x1[0] = x;

y1[0] = y;

x1[1] = x + 20 * cos(pi * (arg - 90 - 6));

y1[1] = y + 20 * sin(pi * (arg - 90 - 6));

x1[2] = x + 25 * cos(pi * (arg - 90 + 6));

y1[2] = y + 25 * sin(pi * (arg - 90 + 6));

x1[3] = x + 160 * cos(pi * (arg - 90 + 0));

y1[3] = y + 160 * sin(pi * (arg - 90 + 0));

moveto(x1[1], y1[1]);

lineto(x1[0], y1[0]);

lineto(x1[2], y1[2]);

lineto(x1[3], y1[3]);

lineto(x1[1], y1[1]);

setfillstyle(SOLID_FILL, color);

/*

floodfill((x1[0] + x1[3]) / 2, (y1[0] + y1[3]) / 2, color);

*/

}