Sunday, February 12, 2017

C CODE for drawing flag and animation

#include<graphics.h>
#include<stdio.h>
#include<conio.h>
void main()
{

    int gdriver = DETECT, gmode, errorcode,r1,r2,x1,y1,x;
    int left=150, top=150, right=500, bottom=100,i,y;
    float j;

    initgraph(&gdriver, &gmode, "");

    for(i=0;i<3;i++)
    {
        rectangle(left,top,right,bottom);
        top=bottom;
        bottom=bottom-50;
        setcolor(0);
    }
    for(y=150;y>=0;y--)
    {
        line(150,y,500,y);
        if(y<=150 && y>=100)
            setcolor(2);
        if(y<=100 && y>=50)
            setcolor(15);
        if(y<=50 && y>=0)
            setcolor(4);
    }
    setcolor(1);
    circle(325,75,25);
    for(j=0;j<=6.28;j=j+0.26167)
    {
        r1=25*cos(j);
        r2=25*sin(j);
        line(325,75,r1+325,-r2+75);
    }
    setcolor(6);

    line(150,150,150,600);
    y=0;
    for(x1=500;x1>=400;x1--)
    {
        setcolor(0);
        line(x1,0,x1,150);
        delay(50);
    }
    y1=0;
    for(x=400;x<=500;x++)
    {
        if(y1>=0 && y1<=50)
        {
            setcolor(4);
            line(x,0,x,50);
        }
        delay(50);
        y1++;
    }
    y1=50;
    for(x=400;x<=500;x++)
    {
        if(y1>=50 && y1<=100)
        {
            setcolor(15);
            line(x,50,x,100);
        }
        delay(50);
        y1++;
    }
    y1=100;
    for(x=400;x<=500;x++)
    {
        if(y1>=100 && y1<=150)
        {
            setcolor(2);
            line(x,100,x,150);
        }
        delay(50);
        y1++;
    }



    setcolor(4);
    getch();
    closegraph();
}

No comments:

Post a Comment