You are here

C smiling face animation

This animation using C draws a smiling face which appears at random positions on the screen.

C programming code

  1. #include<graphics.h>
  2. #include<conio.h>
  3. #include<stdlib.h>
  4.  
  5. main()
  6. {
  7.    int gd = DETECT, gm, area, temp1, temp2, left = 25, top = 75;
  8.    void *p;
  9.  
  10.    initgraph(&gd, &gm, "C:\\TC\\BGI");
  11.  
  12.    setcolor(YELLOW);
  13.    circle(50, 100, 25);
  14.    setfillstyle(SOLID_FILL, YELLOW);
  15.    floodfill(50, 100, YELLOW);
  16.  
  17.    setcolor(BLACK);
  18.    setfillstyle(SOLID_FILL, BLACK);
  19.    fillellipse(44, 85, 2, 6);
  20.    fillellipse(56, 85, 2, 6);
  21.  
  22.    ellipse(50, 100, 205, 335, 20, 9);
  23.    ellipse(50, 100, 205, 335, 20, 10);
  24.    ellipse(50, 100, 205, 335, 20, 11);
  25.  
  26.    area = imagesize(left, top, left + 50, top + 50);
  27.    p = malloc(area);
  28.  
  29.    setcolor(WHITE);
  30.    settextstyle(SANS_SERIF_FONT, HORIZ_DIR, 2);
  31.    outtextxy(155, 451, "Smiling Face Animation");
  32.  
  33.    setcolor(BLUE);
  34.    rectangle(0, 0, 639, 449);
  35.  
  36.    while(!kbhit())
  37.    {
  38.       temp1 = 1 + random (588);
  39.       temp2 = 1 + random (380);
  40.  
  41.       getimage(left, top, left + 50, top + 50, p);
  42.       putimage(left, top, p, XOR_PUT);
  43.       putimage(temp1 , temp2, p, XOR_PUT);
  44.       delay(100);
  45.       left = temp1;
  46.       top = temp2;
  47.    }
  48.  
  49.    getch();
  50.    closegraph();
  51.    return 0;
  52. }