C Smiling Face Animation :

This animation using c draws a smiling face which appears at random position on screen. See output below the code, it will help you in understanding the code easily.

  • The graphics.h library is used to create graphics in C program. Let us create the smiling face.
  • Now set the color as YELLOW for smiling face. And create circle using circle( ) function by giving radius parameter.
  • Using setfillstyle( ) and floodfill( )  fill the yellow color in the circle.
  • Create 4 ellipse using ellipse( ) function and fill color BLACK using setfillstyle( ) and fillellipse( ).

C programming code

[pastacode lang=”c” manual=”%23include%3Cgraphics.h%3E%0A%23include%3Cconio.h%3E%0A%23include%3Cstdlib.h%3E%0A%20%0Amain()%0A%7B%0A%20%20%20int%20gd%20%3D%20DETECT%2C%20gm%2C%20area%2C%20temp1%2C%20temp2%2C%20left%20%3D%2025%2C%20top%20%3D%2075%3B%0A%20%20%20void%20*p%3B%0A%20%0A%20%20%20initgraph(%26gd%2C%26gm%2C%22C%3A%5C%5CTC%5C%5CBGI%22)%3B%0A%20%0A%20%20%20setcolor(YELLOW)%3B%0A%20%20%20circle(50%2C100%2C25)%3B%0A%20%20%20setfillstyle(SOLID_FILL%2CYELLOW)%3B%0A%20%20%20floodfill(50%2C100%2CYELLOW)%3B%0A%20%0A%20%20%20setcolor(BLACK)%3B%0A%20%20%20setfillstyle(SOLID_FILL%2CBLACK)%3B%0A%20%20%20fillellipse(44%2C85%2C2%2C6)%3B%0A%20%20%20fillellipse(56%2C85%2C2%2C6)%3B%0A%20%0A%20%20%20ellipse(50%2C100%2C205%2C335%2C20%2C9)%3B%0A%20%20%20ellipse(50%2C100%2C205%2C335%2C20%2C10)%3B%0A%20%20%20ellipse(50%2C100%2C205%2C335%2C20%2C11)%3B%0A%20%0A%20%20%20area%20%3D%20imagesize(left%2C%20top%2C%20left%20%2B%2050%2C%20top%20%2B%2050)%3B%0A%20%20%20p%20%3D%20malloc(area)%3B%0A%20%0A%20%20%20setcolor(WHITE)%3B%0A%20%20%20settextstyle(SANS_SERIF_FONT%2CHORIZ_DIR%2C2)%3B%0A%20%20%20outtextxy(155%2C451%2C%22Smiling%20Face%20Animation%22)%3B%0A%20%0A%20%20%20setcolor(BLUE)%3B%0A%20%20%20rectangle(0%2C0%2C639%2C449)%3B%0A%20%0A%20%20%20while(!kbhit())%0A%20%20%20%7B%0A%20%20%20%20%20%20temp1%20%3D%201%20%2B%20random%20(%20588%20)%3B%0A%20%20%20%20%20%20temp2%20%3D%201%20%2B%20random%20(%20380%20)%3B%0A%20%0A%20%20%20%20%20%20getimage(left%2C%20top%2C%20left%20%2B%2050%2C%20top%20%2B%2050%2C%20p)%3B%0A%20%20%20%20%20%20putimage(left%2C%20top%2C%20p%2C%20XOR_PUT)%3B%0A%20%20%20%20%20%20putimage(temp1%20%2C%20temp2%2C%20p%2C%20XOR_PUT)%3B%0A%20%20%20%20%20%20delay(100)%3B%0A%20%20%20%20%20%20left%20%3D%20temp1%3B%0A%20%20%20%20%20%20top%20%3D%20temp2%3B%0A%20%20%20%7D%0A%20%0A%20%20%20getch()%3B%0A%20%20%20closegraph()%3B%0A%20%20%20return%200%3B%0A%7D” message=”” highlight=”” provider=”manual”/] [ad type=”banner”]

Output :

smiling-face-animation

smiling-face-animation

Categorized in: