Showing posts with label COMPUTER GRAPHICS C PROGRAM. Show all posts
Showing posts with label COMPUTER GRAPHICS C PROGRAM. Show all posts

Saturday, 8 March 2014

FLOOD FILL ALGORITHM


/*CSEMATTER.BLOGSPOT.IN
PROGRAM-TO IMPLEMENT FLOOD FILL ALGORITHM*/

#include<conio.h>
#include<stdio.h>
#include<graphics.h>
void fill_right(int x,int y)
{
if(getpixel(x,y) == 0)
{
putpixel(x,y,RED);
fill_right(++x,y);
x = x - 1 ;
fill_right(x,y-1);
fill_right(x,y+1);
}
}
void fill_left(int x,int y)
{
if(getpixel(x,y) == 0)
{
putpixel(x,y,RED);
fill_left(--x,y);
x = x + 1 ;
fill_left(x,y-1);
fill_left(x,y+1);
}
}
int main()
{
int x , y ,a[10][10];
int gd=DETECT, gm ,n,i;
initgraph(&gd,&gm,"c:\tc\bgi");
printf("Enter the no. of edges of polygon : ");
scanf("%d",&n);
printf("\nEnter the cordinates of polygon :\n\n ");
for(i=0;i<n;i++)
{
printf("\tX%d Y%d : ",i,i);
scanf("%d %d",&a[i][0],&a[i][1]);
}
a[n][0]=a[0][0];
a[n][1]=a[0][1];
printf("\n\nEnter the seed pt. : ");
scanf("%d %d",&x,&y);
for(i=0;i<n;i++)
{
line(a[i][0],a[i][1],a[i+1][0],a[i+1][1]);
}
fill_right(x,y);
fill_left(x-1,y);
getch();
}

BOUNDARY FILL ALGORITHM


/*CSEMATTER.BLOGSPOT.IN
PROGRAM-TO IMPLELMENT BOUNDARY FILL ALGORITHM*/

#include<stdio.h>
#include<conio.h>
#include<graphics.h>
void colouring(int,int,int,int,int);
int main()
{
    int gd=DETECT,gm,x,y,a=0,b=0,c,tempx,tempy,left,right,top,bottom;
    initgraph(&gd,&gm,"C:\TC\BGI");
    printf("Enter the left, top, right & bottom coordinates of rectangle: ");
    scanf("%d %d %d %d",&left,&top,&right,&bottom);
    rectangle(left,top,right,bottom);
    printf("Enter the corresponding code of color to be filled");
    scanf("%d",&c);
    tempx=(right-left)/2;
    tempy=(bottom-top)/2;
    x=tempx+left;
    y=tempy+top;
    printf("%d %d",x,y);
    while(a!=tempx | b!=tempy)
    {printf("%d %d\n",a,b);
        colouring(x,y,a,b,c);
        if(a<=tempx)
        a++;
        if(b<=tempy)
        b++;
    }
    getch();
    closegraph();
}

void colouring(int x,int y,int a,int b,int c)
{
    int i,j;
    for(i=0; i<=a; i++)
    {
        for(j=0; j<=b; j++)
        {
            putpixel(x,y,c);
            putpixel(x-i,y,c);
            putpixel(x+i,y,c);
            putpixel(x,y-j,c);
            putpixel(x,y+j,c);
            putpixel(x-i,y-j,c);
            putpixel(x-i,y+j,c);
            putpixel(x+i,y-j,c);
            putpixel(x+i,y+j,c);
        }
    }
}

3D TRANSFORMATION AND ROTATION

/*CSEMATTER.BLOGSPOT.IN
PROGRAM-3D TRANSFORMATION AND ROTATION*/



#include<stdio.h>

#include<conio.h>

#include<math.h>

#include<process.h>

#include<graphics.h>




void draw();

void rotate();

int x12,x22,y12,y22,mx,my,depth;

int main()

{


    int gd=DETECT,gm,c;

    initgraph(&gd,&gm,"C:\tc\bgi");

    printf("\n3D Transformation Rotating\n\n");

    printf("\nEnter 1st top value(x12,y12):");

    scanf("%d%d",&x12,&y12);

    printf("Enter right bottom value(x2,y2):");

    scanf("%d%d",&x22,&y22);

    depth=(x22-x12)/4;

    mx=(x12+x22)/2;

    my=(y12+y22)/2;

    draw();

    getch();

    cleardevice();

    rotate();

    getch();

}



void draw()

{

    bar3d(x12,y12,x22,y22,depth,1);

}



void rotate()

{

    float t;

    int a1,b1,a2,b2,dep;

    printf("Enter the angle to rotate=");

    scanf("%f",&t);

    t=t*(3.14/180);

    a1=mx+(x12-mx)*cos(t)-(y12-my)*sin(t);

    a2=mx+(x22-mx)*cos(t)-(y22-my)*sin(t);

    b1=my+(x12-mx)*sin(t)-(y12-my)*cos(t);

    b2=my+(x22-mx)*sin(t)-(y22-my)*cos(t);

    if(a2>a1)

       dep=(a2-a1)/4;

    else

      dep=(a1-a2)/4;

    bar3d(a1,b1,a2,b2,dep,1);

    setcolor(5);

    //draw();

}


COHEN SUTHERLAND LINE CLIPING


/*CSEMATTER.BLOGSPOT.IN
PROGRAM NAME-PROGRAM TO IMPLEMENT COHEN SUTHERLAND LINE CLIPING*/

#include<stdio.h>
#include<conio.h>
#include<graphics.h>
struct p
{
int x,y;
}p1,p2;
void main()
{
int gd=DETECT,gm;
int i,q=0,x1,y1,x2,y2,l,b,t,r,code1[4],code2[4];
int k=0,counter1=0,counter2=0,temp[5];
clrscr();
initgraph(&gd,&gm,"");
printf("enter the value of left, right ,bottom & top value");
scanf("%d%d%d%d",&l,&r,&b,&t);
rectangle(l,t,r,b);
printf("enter the first point of line");
scanf("%d%d",&p1.x,&p1.y);
printf("enter the end point of line");
scanf("%d%d",&p2.x,&p2.y);
if(p1.x<l)
{
code1[0]=1;
}
else
code1[0]=0;
if(p1.x<r)
code1[1]=0;
else
code1[1]=1;
if(p1.y>b)
code1[2]=1;
else
code1[2]=0;
if(p1.y<t)
code1[3]=1;
else
code1[3]=0;

if(p2.x<l)
{
code2[0]=1;
}
else
code2[0]=0;
if(p2.x<r)
code2[1]=0;
else
code2[1]=1;
if(p2.y>b)
code2[2]=1;
else
code2[2]=0;
if(p2.y<t)
code2[3]=1;
else
code2[3]=0;
for(i=0;i<=3;i++)
{
if(code1[i]==0)
counter1++;
}
for(i=0;i<=3;i++)
{
if(code2[i]==0)
counter2++;
}
if((counter1==4)&&(counter2==4))
{
printf("line is completly visible");
line(p1.x,p1.y,p2.x,p2.y);
}
else
{
for(i=0;i<4;i++)
{
temp[i]=code1[i]&code2[i];
if(temp[i]==1)
{q=0;
printf("line completely invisible");
break;}
else
{
q=1;
}}
if(q==1)
{
if(p1.x<l|| p2.x<l)
{if(p1.x<l)
p1.x=l;
else
p2.x=l;}
if(p1.x>r || p2.x>r)
{if(p1.x>r)
p1.x=r;
else
p2.x=r;}
if(p1.y>b|| p2.y>b)
{if(p1.y>b)
p1.y=b;
else
p2.y=b;}
if(p1.y<t|| p2.y<t)
{if(p1.y<t)
p1.y=t;
else
p2.y=t;}
line(p1.x,p1.y,p2.x,p2.y);
}
}
 getch();
closegraph();}

REFLECTION IN GRPAHICS


/*CSEMATTER.BLOGSPOT.IN
PROGRAM-REFLECTION IN GRAPHICS*/

#include<stdio.h>
#include<conio.h>
#include<math.h>
#include<graphics.h>
void display(float [3][3]);
void xreflection(float [3][3],float [3][3]);
void yreflection(float [3][3],float [3][3]);
void linereflection(float [3][3],float [3][3]);
void multiply(float [3][3],float [3][3],float [3][3]);
void multiply1(float [3][3],float [3][3],float [3][3],float [3][3],float [3][3],float [3][3],float [3][3]);
int main()
{
    int gd=DETECT,gm,i,j,k,choice;
    float arr2[3][3],arr[3][3],arr_c[3][3];


    initgraph(&gd,&gm,"C:\TC\bgi");
    printf("Enter the values of x & y coordinates for 1st, 2nd, 3rd vertex");
    for(i=0; i<3; i++)
    {
        for(j=0; j<3; j++)
        {
            if(j==0)
                scanf("%f",&arr2[i][0]);
            if(j==1)
                scanf("%f",&arr2[i][1]);
            else if(j==2)
                arr2[i][2]=1;
        }

    }
    display(arr2);
    printf("enter the choice\n");
    printf("enter the 1 for x-reflection\n");
    printf("enter the 2 for y-reflection\n");
    printf("enter the 3 for y=mx+c reflection \n");
    scanf("%d",&choice);
    switch(choice)
    {
    case 1:
        xreflection(arr2,arr);
        display(arr);
        getch();
        closegraph();
        break;
    case 2:
        yreflection(arr2,arr);
        display(arr);
        getch();
        closegraph();
        break;
    case 3:
        linereflection(arr2,arr_c);
        display(arr_c);
        getch();
        closegraph();
        break;
    }
}
void display(float arr2[3][3])

{
    line(320+arr2[0][0],240-arr2[0][1],320+arr2[1][0],240-arr2[1][1]);
    line(320+arr2[1][0],240-arr2[1][1],320+arr2[2][0],240-arr2[2][1]);
    line(320+arr2[2][0],240-arr2[2][1],320+arr2[0][0],240-arr2[0][1]);
}


void xreflection(float arr2[3][3],float arr[3][3])
{
    int i,j;
    float arr3[3][3];
    for(i=0; i<3; i++)
    {
        for(j=0; j<3; j++)
        {
            if(i!=j)
                arr3[i][j]=0;
        }
    }
    arr3[0][0]=1;
    arr3[1][1]=-1;
    arr3[2][2]=1;
    multiply(arr3,arr2,arr);
}




void yreflection(float arr2[3][3],float arr[3][3])
{
    int i,j;
    float arr3[3][3];
    for(i=0; i<3; i++)
    {
        for(j=0; j<3; j++)
        {
            if(i!=j)
                arr3[i][j]=0;
        }
    }
    arr3[0][0]=-1;
    arr3[1][1]=1;
    arr3[2][2]=1;
    multiply(arr3,arr2,arr);
}


void linereflection(float arr2[3][3],float arr_c[3][3])
{
    int i,j,k;
    float m,c,arr_t[3][3],arr_r[3][3],arr_it[3][3],arr_ir[3][3],arr_ref[3][3];
    float theta1;
    printf("enter the values of m & c");
    scanf("%f %f",&m,&c);
    theta1=atan(m);
    for(i=0; i<3; i++)
    {
        for(j=0; j<3; j++)
        {
            if(i==j)
                arr_t[i][j]=1;
            else
                arr_t[i][j]=0;
            arr_t[2][0]=0;
            arr_t[2][1]=-c;
        }
    }

    arr_r[0][0]=cos(theta1);
    arr_r[0][1]=-sin(theta1);
    arr_r[0][2]=0;
    arr_r[1][0]=sin(theta1);
    arr_r[1][1]=cos(theta1);
    arr_r[1][2]=0;
    arr_r[2][0]=0;
    arr_r[2][1]=0;
    arr_r[2][2]=1;

    for(i=0; i<3; i++)
    {
        for(j=0; j<3; j++)
        {
            if(i!=j)
                arr_ref[i][j]=0;
        }
    }
    arr_ref[0][0]=1;
    arr_ref[1][1]=-1;
    arr_ref[2][2]=1;

    arr_ir[0][0]=cos(theta1);
    arr_ir[0][1]=sin(theta1);
    arr_ir[0][2]=0;
    arr_ir[1][0]=-sin(theta1);
    arr_ir[1][1]=cos(theta1);
    arr_ir[1][2]=0;
    arr_ir[2][0]=0;
    arr_ir[2][1]=0;
    arr_ir[2][2]=1;

    for(i=0; i<3; i++)
    {
        for(j=0; j<3; j++)
        {
            if(i==j)
                arr_it[i][j]=1;
            else
                arr_it[i][j]=0;
            arr_it[2][0]=0;
            arr_it[2][1]=c;
        }
    }

    multiply1(arr2, arr_t, arr_r, arr_ref, arr_ir, arr_it, arr_c);

}

void multiply(float arr3[3][3],float arr2[3][3],float arr[3][3])
{
    int i,j,k;
    for(i=0; i<3; i++)
    {
        for(j=0; j<3; j++)
        {
            arr[i][j]=0.0;
        }
    }
    for(i=0; i<3; i++)
    {
        for(j=0; j<3; j++)
        {
            for(k=0; k<3; k++)
            {
                arr[i][j]=arr[i][j]+arr2[i][k]*arr3[k][j];
            }
        }
    }
}

void multiply1(float arr2[3][3],float arr_t[3][3],float arr_r[3][3],float arr_ref[3][3],float arr_ir[3][3],float arr_it[3][3],float arr_c[3][3])
{
    int i,j,k;
    float arr_a[3][3],arr_b[3][3],arr_d[3][3],arr_e[3][3];
    for(i=0; i<3; i++)
    {
        for(j=0; j<3; j++)
        {
                arr_a[i][j]=0;
                arr_b[i][j]=0;
                arr_d[i][j]=0;
                arr_e[i][j]=0;
                arr_c[i][j]=0;
        }
    }
    for(i=0; i<3; i++)
    {
        for(j=0; j<3; j++)
        {
            for(k=0; k<3; k++)
            {
                arr_a[i][j]=arr_a[i][j]+(arr2[i][k]*arr_t[k][j]);
                arr_b[i][j]=arr_b[i][j]+(arr_r[i][k]*arr_ref[k][j]);
                arr_d[i][j]=arr_d[i][j]+(arr_ir[i][k]*arr_it[k][j]);
            }
        }
    }

    for(i=0; i<3; i++)
    {
        for(j=0; j<3; j++)
        {
            for(k=0; k<3; k++)
            {
                arr_e[i][j]=arr_e[i][j]+(arr_a[i][k]*arr_b[k][j]);
            }
        }
    }
    for(i=0; i<3; i++)
    {
        for(j=0; j<3; j++)
        {
            for(k=0; k<3; k++)
            {
                arr_c[i][j]=arr_c[i][j]+(arr_e[i][k]*arr_d[k][j]);
            }
        }
    }

}

SCALING SHEARING ROTATION TRANSLATION IN GRAPHICS

/*CSEMATTER.BLOGSPOT.IN

PROGRAM-TO PERFORM SCALING,SHEARING,ROTATION,TRANSLATION*/


#include<stdio.h>
#include<conio.h>
#include<math.h>
#include<graphics.h>
void translation(float [3][3]);
void scaling(float [3][3]);
void display(float [3][3]);
void rotation(float [3][3]);
void shearingx(float [3][3]);
void shearingy(float [3][3]);
void multiply(float [3][3],float [3][3]);
int main()
{
int gd=DETECT,gm,i,j,k,choice;
float arr2[3][3];

initgraph(&gd,&gm,"C:\TC\bgi");
printf("Enter the values of x & y coordinates for 1st, 2nd, 3rd vertex");
for(i=0;i<3;i++)
{
    for(j=0;j<3;j++)
    {
        if(j==0)
        scanf("%f",&arr2[i][0]);
        if(j==1)
        scanf("%f",&arr2[i][1]);
        else
        if(j==2)
        arr2[i][2]=1;
    }

}
display(arr2);
printf("enter the choice\n");
printf("enter the 1 for x-shearing\n");
printf("enter the 2 for y-shearing\n");
printf("enter the 3 for rotation\n");
printf("enter the 4 for translation\n");
printf("enter the 5 for scaling\n");
scanf("%d",&choice);
switch(choice)
{
    case 1:
    shearingx(arr2);
    getch();
closegraph();
    break;
    case 2:
    shearingy(arr2);
    getch();
closegraph();
    break;
    case 3:
    rotation(arr2);
    getch();
closegraph();
    break;
    case 4:
    translation(arr2);
    getch();
closegraph();
    break;
    case 5:
    scaling(arr2);
    getch();
closegraph();
    break;
}

}
void display(float arr2[3][3])

{
line(arr2[0][0],arr2[0][1],arr2[1][0],arr2[1][1]);
line(arr2[1][0],arr2[1][1],arr2[2][0],arr2[2][1]);
line(arr2[2][0],arr2[2][1],arr2[0][0],arr2[0][1]);
}

//SHEARING -X
void shearingx(float arr2[3][3])
{
    int i,j,shx;
float arr3[3][3];
printf("Enter the value of x shearing");
scanf("%d",&shx);
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
if(i==j)
arr3[i][j]=1;
if(i!=j)
arr3[i][j]=0;
}
}
arr3[1][0]=shx;
multiply(arr3,arr2);
}


//SHEARING -Y
void shearingy(float arr2[3][3])
{
    int i,j,shy;
float arr3[3][3];
printf("Enter the value of y shearing");
scanf("%d",&shy);
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
if(i==j)
arr3[i][j]=1;
if(i!=j)
arr3[i][j]=0;
}
}
arr3[0][1]=shy;
multiply(arr3,arr2);
}




void rotation(float arr2[3][3])
{float theta,arr3[3][3];
float theta1;
printf("Enter the value of theta");
scanf("%f",&theta);
theta1=(3.141592/180)*theta;
arr3[0][0]=cos(theta1);
arr3[0][1]=sin(theta1);
arr3[0][2]=0;
arr3[1][0]=-sin(theta1);
arr3[1][1]=cos(theta1);
arr3[1][2]=0;
arr3[2][0]=0;
arr3[2][1]=0;
arr3[2][2]=1;
multiply(arr3,arr2);
}


void scaling(float arr2[3][3])
{int sx,sy,i,j,k;
float arr3[3][3];
printf("Enter the value of x & y scaling");
scanf("%d %d ",&sx,&sy);
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
if(i==0 && j==0)
arr3[i][j]=sx;
if(i==1 && j==1)
arr3[i][j]=sy;
if (i==2 && j==2)
arr3[i][j]=1;
if(i!=j)
arr3[i][j]=0;
}
}
multiply(arr3,arr2);
}
void translation(float arr2[3][3])
{int tx,ty,i,j,k;
float arr3[3][3];
printf("Enter the value of x & y-translation");
scanf("%d %d ",&tx,&ty);
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
if(i==j)
arr3[i][j]=1;
else
arr3[i][j]=0;
arr3[2][0]=tx;
arr3[2][1]=ty;
}
}
multiply(arr3,arr2);
}
void multiply(float arr3[3][3],float arr2[3][3])
{int i,j,k;
float arr[3][3];
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
arr[i][j]=0;
} }
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
for(k=0;k<3;k++)
{arr[i][j]=arr[i][j]+arr2[i][k]*arr3[k][j];
} }}
display(arr);}

PROGRAM FOR CIRCLE


/*CSEMATTER.BLOSPOT.IN
PROGRAM-PROGRAM TO DRAW A CIRCLE IN GRAPHICS*/


#include<stdio.h>
#include<conio.h>
#include<graphics.h>
int main()
{    void plotpoint(int,int,int,int);
 int x,y,xc,yc,r,gm,gd=DETECT,p=0;
    initgraph(&gd,&gm,"C:\TC\BGI");
      printf("enter the value of centre coordinates");
      scanf("%d %d",&xc,&yc);
      printf("enter the value of x and radius");
      scanf("%d %d",&x,&r);
    p=1-r;
    y=r;
    plotpoint(xc,yc,x,y);
    while(x<=y)
    {
        x++;
        if(p<0)
        {
            p+=2*x+3;
        }
        else
        {
            y--;
            p+=2*(x-y)+5;

        }
        plotpoint(xc,yc,x,y);
    }
    getch();
    closegraph();

}
void plotpoint(int xc,int yc,int x,int y)
{
    putpixel(xc+x,yc+y,15);
    putpixel(xc-x,yc+y,15);
    putpixel(xc+x,yc-y,15);
    putpixel(xc-x,yc-y,15);
    putpixel(xc+y,yc+x,15);
    putpixel(xc-y,yc+x,15);
    putpixel(xc+y,yc-x,15);
    putpixel(xc-y,yc-x,15);
}


Friday, 7 March 2014

LINE USING BRESENHAM


/*CSEMATTER.BLOGSPOT.IN
PROGRAM NAME-PROGRAM TO DRAW A LINE USING BRESENHAM ALGORITHM*/

#include<stdio.h>
#include<conio.h>
#include<graphics.h>
int main()
{
      int gd = DETECT, gm;
      int dx, dy, p, end;
      float x1, x2, y1, y2, x, y;
      printf("Enter Value of X1: ");
      scanf("%f", &x1);
      printf("Enter Value of Y1: ");
      scanf("%f", &y1);
      printf("Enter Value of X2: ");
      scanf("%f", &x2);
      printf("Enter Value of Y2: ");
      scanf("%f", &y2);
 if ( x1 > x2 )
   {x = x2;
    y = y2;
    end= x1;}
   else
   { x = x1;
y = y1;
end = x2;}
      dx = abs(x1 - x2);
      dy = abs(y1 - y2);
      p = 2 * dy - dx;
    initgraph(&gd, &gm, "c:\tc\bgi");
      putpixel(x, y, 10);
      while(x < end)
      { x = x + 1;
            if(p < 0)
           p = p + 2 * dy;
            else
                {  y = y + 1;
                  p = p + 2 * (dy - dx);}
            putpixel(x, y, 10);}
      getch();
      closegraph();}

LINE IN A SHIFTED ORIGIN

/
*CSEMATTER.BLOGSPOT.IN
PROGRAM NAME-PROGRAM TO DRAW A LINE IN A SHIFTED ORIGIN*/

#include<stdio.h>
#include<conio.h>
#include<graphics.h>
int main()
{int gd=DETECT,gm;
float x1,x2,y1,y2;
float m,c,x,y,i;
printf("enter the first coordinatse");
scanf("%f %f",&x1,&y1);
x1=x1+320;
y1=240-y1;
printf("enter the second coordinatse");
scanf("%f %f",&x2,&y2);
x2=x2+320;
y2=240-y2;
m=(y2-y1)/(x2-x1);
c=y1-(m*x1);
initgraph(&gd,&gm,"C:\tc\bgi");
line(320,0,320,480);
line(0,240,640,240);
  if(x2!=x1)
   { x=x1;
     y=y1;
       while(x<=x2)
       { y=(m*x)+c;
        putpixel(x,y,15);
        x++;}
   }
else
printf("ERROR!!!!!!");
   getch();
closegraph();
}

LINE USING SLOPE METHOD


/*CSEMATTER.BLOGSPOT.IN
PROGRAM NAME-PROGRAM TO DRAW A LINE USING SLOPE*/

#include<stdio.h>
#include<conio.h>
#include<graphics.h>
int main()
{int gd=DETECT,gm;
float x1,x2,y1,y2;
float m,c,x,y,i;
printf("enter the first coordinatse");
scanf("%f %f",&x1,&y1);
printf("enter the second coordinatse");
scanf("%f %f",&x2,&y2);
m=(y2-y1)/(x2-x1);
c=y1-(m*x1);
initgraph(&gd,&gm,"C:\tc\bgi");
  if(x2!=x1)
   { x=x1;
     y=y1;
       while(x<=x2)
       {y=(m*x)+c;
        putpixel(x,y,15);
        x++;}
    }
else
   printf("ERROR!!!!!!");
   getch();
closegraph();}

LINE USING DDA ALGORITHM

/*CSEMATTER.BLOGSPOT.IN

PROGRAM NAME-PROGRAM TO DRAW A LINE USING DDA ALGORITHM*/

#include<stdio.h>
#include<conio.h>
#include<graphics.h>
#include<math.h>
int main()
{int gd=DETECT,gm;
float x1,x2,y1,y2,dx,dy,steps;
float m,c,y,x,i,deltax,deltay;
printf("enter the first coordinatse");
scanf("%f %f",&x1,&y1);
printf("enter the second coordinatse");
scanf("%f %f",&x2,&y2);
dx=x2-x1;
dy=y2-y1;
initgraph(&gd,&gm,"C:\tc\bgi");
  if(abs(dx)>abs(dy))
   steps=dx;
   else
   steps=dy;
deltax=dx/steps;
deltay=dy/steps;
x=x1;
y=y1;
putpixel((int)(x+0.5),(int)(y+0.5),15);
for(i=0;i<steps;i++)
{ x=x+deltax;
 y=y+deltay;
 putpixel((int)(x+0.5),(int)(y+0.5),15);}
getch();
closegraph();}

Thursday, 6 March 2014

SMILING FACE




/* CSEMATTER.BLOGSPOT.IN

PROGRAM TO DRAW A SMILING FACE*/

#include<stdio.h>
#include<conio.h>
#include<graphics.h>
int main()
{int gd=DETECT,gm;
initgraph(&gd,&gm,"C:\tc\bgi");
circle(250,250,200);
circle(130,150,30);
circle(370,150,30);
line(250,220,250,270);
ellipse(250,320,180,0,75,45);
getch();
closegraph();}

CAR IN COMPUTER GRAPHICS


/* CSEMATTER.BLOGSPOT.IN

PROGRAM TO DRAW A MOVING CAR*/

#include<stdio.h>
#include<conio.h>
#include<graphics.h>
int  main()
{int gd=DETECT,gm,i;
initgraph(&gd,&gm,"C:\tc\bgi");
for(i=-100;i<100;i++)
{line(150+i,100,300+i,100);
line(150+i,100,130+i,130);
line(130+i,130,100+i,145);
line(100+i,145,100+i,170);
line(100+i,170,130+i,170);
ellipse(150+i,170,0,180,20,20);
circle(152+i,172,13);
line(170+i,170,260+i,170);
ellipse(280+i,170,0,180,20,20);
circle(282+i,172,13);
line(300+i,100,340+i,140);
line(340+i,140,370+i,140);
line(370+i,140,370+i,170);
line(300+i,170,370+i,170);
delay(100);
cleardevice();}
getch();
closegraph();}