xelua.c

来自「Many C samples. It is a good sample for 」· C语言 代码 · 共 50 行

C
50
字号
/* Ve banh xe lua */
#include <conio.h>
#include <graphics.h>
#include <math.h>
#include <dos.h>

/* 1 / sqrt(2) */
#define FCT 0.7071067
/* he so doi tu do sang radian */
#define RADS 0.017453293
#define RADIUS 21

void banhxelua()
{
  double angle = 45, xc = 100, yc, xl, yl;
  yc = 448 - RADIUS;
  while (!kbhit())
  {
     setcolor(YELLOW);
     xl = RADIUS * cos(angle * RADS);
     yl = RADIUS * sin(angle * RADS);
     circle(xc, yc, RADIUS);
     circle(xc + 100, yc, RADIUS);
     setcolor(RED);
     line(xc + xl, yc + yl, xc + xl + 100, yc + yl);
     line(xc - xl, yc - yl, xc - xl + 100, yc - yl);
     delay(10);
     setcolor(BLACK);
     circle(xc, yc, RADIUS);
     circle(xc + 100, yc, RADIUS);
     line(xc + xl, yc + yl, xc + xl + 100, yc + yl);
     line(xc - xl, yc - yl, xc - xl + 100, yc - yl);
     angle += 1;
     xc += 2 * M_PI * RADIUS / 360;
     if (xc-RADIUS >getmaxx())
      xc = - RADIUS - 100;
  }
}

void main()
{
  int gr_drive = DETECT, gr_mode;

  initgraph(&gr_drive, &gr_mode, "");
  line(0, 450, getmaxx(), 450);
  line(0, 451, getmaxx(), 451);
  banhxelua();
  getch();
  closegraph();
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?