#include <graphics.h>
#include <conio.h>
#include <stdlib.h>
#include <stdio.h>
void carstart(int x, int y, int z);
void drawbus();
void init();
IMAGE img;
void main()
{
init();
int x=0, y=0, z=0;
BeginBatchDraw();
while(!kbhit())
{
x += 2;
y++;
z += 3;
if (x > 600) x = -200;
if (y > 600) y = -200;
if (z > 600) z = -200;
carstart(x, y, z);
FlushBatchDraw();
Sleep(5);
}
EndBatchDraw();
closegraph();
}
void init()
{
initgraph(600, 600);
outtextxy(70, 250, "大家好,新手来报到,希望大家多多指教");
outtextxy(70, 270, "下面你们会看到我程序的效果,程序很简单");
outtextxy(70, 290, "希望以后再跟大家的交流中学到更多,希望自己以后能编出更好的程序");
outtextxy(70, 320, "请按任意键进观看程序执行效果");
getch();
cleardevice();
drawbus();
getimage(&img, 80, 40, 180, 90);
}
void carstart(int x, int y, int z)
{
cleardevice();
putimage(x, 40, &img);
setlinestyle(PS_SOLID, 10);
line(0, 135, 600, 135);
putimage(y, 220, &img);
line(0, 315, 600, 315);
putimage(z, 380, &img);
line(0, 475, 600, 475);
}
void drawbus()
{
setcolor(RED);
setfillstyle(BLUE);
fillcircle(120, 120, 10);
fillcircle(200, 120, 10);
line(80, 120, 110, 120);
line(80, 40, 80, 120);
line(130, 120, 190, 120);
line(210, 120, 250, 120);
line(250, 40, 250, 120);
line(80, 40, 250, 40);
for(int x = 90, y = 100; x < 190 && y < 190; x += 15, y += 15)
{
rectangle(x, 60, y, 70);
}
rectangle(220, 60, 240, 120);
line(230, 60, 230, 120);
circle(230, 90, 5);
}