Friday, 22 February 2013


To perform 2D transformations such as translation, scaling, and  rotation  on 2D object

ALGORITHM:
1.      Start
2.      Initialize the graphics mode.
3.      Construct a 2D object  (use Drawpoly()) e.g. (x,y)
4.      A) Translation
a.       Get the translation value tx, ty
b.      Move the 2d object with tx, ty (x’=x+tx,y’=y+ty)
c.       Plot (x’,y’)
5.      B)  Scaling
a.       Get the scaling value Sx,Sy
b.       Resize the object with Sx,Sy  (x’=x*Sx,y’=y*Sy)
c.       Plot (x’,y’)
6.      C) Rotation
a.       Get the Rotation angle
b.      Rotate the object by the angle ф
                    x’=x cos ф -  y sin ф
                                      y’=x sin ф  - y cosф  
c.       Plot (x’,y’)

PROGRAM:


#include <graphics.h>
#include <stdlib.h>
#include <stdio.h>
#include <conio.h>
#include<math.h>
void main()
{
            int gm;
            int gd=DETECT;
            int x1,x2,x3,y1,y2,y3,nx1,nx2,nx3,ny1,ny2,ny3,c;
            int sx,sy,xt,yt,r;
            float t;
            initgraph(&gd,&gm,"c:\tc\bg:");
            printf("\t Program for basic transactions");
            printf("\n\t Enter the points of triangle");
            setcolor(1);
            scanf("%d%d%d%d%d%d",&x1,&y1,&x2,&y2,&x3,&y3);
            line(x1,y1,x2,y2);
            line(x2,y2,x3,y3);
            line(x3,y3,x1,y1);
            getch();
            printf("\n 1.Transaction\n 2.Rotation\n 3.Scalling\n 4.exit");
            printf("Enter your choice:");
            scanf("%d",&c);
            switch(c)
            {
                        case 1:
                                    printf("\n Enter the translation factor");
                                    scanf("%d%d",&xt,&yt);
                                    nx1=x1+xt;
                                    ny1=y1+yt;
                                    nx2=x2+xt;
                                    ny2=y2+yt;
                                    nx3=x3+xt;
                                    ny3=y3+yt;
                                    line(nx1,ny1,nx2,ny2);
                                    line(nx2,ny2,nx3,ny3);
                                    line(nx3,ny3,nx1,ny1);
                                    getch();

                        case 2:
                                    printf("\n Enter the angle of rotation");
                                    scanf("%d",&r);
                                    t=3.14*r/180;
                                    nx1=abs(x1*cos(t)-y1*sin(t));
                                    ny1=abs(x1*sin(t)+y1*cos(t));
                                    nx2=abs(x2*cos(t)-y2*sin(t));
                                    ny2=abs(x2*sin(t)+y2*cos(t));
                                    nx3=abs(x3*cos(t)-y3*sin(t));
                                    ny3=abs(x3*sin(t)+y3*cos(t));
                                    line(nx1,ny1,nx2,ny2);
                                    line(nx2,ny2,nx3,ny3);
                                    line(nx3,ny3,nx1,ny1);
                                    getch();

                        case 3:
                                    printf("\n Enter the scalling factor");
                                    scanf("%d%d",&sx,&sy);
                                    nx1=x1*sx;
                                    ny1=y2*sy;
                                    nx2=x2*sx;
                                    ny2=y2*sy;
                                    nx3=x3*sx;
                                    ny3=y3*sy;
                                    line(nx1,ny1,nx2,ny2);
                                    line(nx2,ny2,nx3,ny3);
                                    line(nx3,ny3,nx1,ny1);
                                    getch();

                        case 4:
                                    break;
                        default:
                                    printf("Enter the correct choice");
                                    }
                                    closegraph();
                                    }

BOUNDARY FILL PROGRAM IN C


#include<stdio.h>
#include<conio.h>
#include<graphics.h>

void boundaryfill(int,int,int,int);
int main()
{
  int xc,yc,r,fc,bc;
  int gd=DETECT,gm;
  initgraph(&gd,&gm," ");
  printf("\n\n Enter xc:");
  scanf("%d",&xc);
  printf("\n\n Enter yc:");
  scanf("%d",&yc);
  printf("\n\n Enter r:");
  scanf("%d",&r);
  setcolor(8);
  circle(xc,yc,r);
  printf("\n\n Enter fill color:");
  scanf("%d",&fc);
  printf("\n\n Enter Boundary Color");
  scanf("%d",&bc);
 
  boundaryfill(xc,yc,fc,bc);
  getch();
  closegraph();
  return 0;
}



void boundaryfill(int x1,int y1,int fc1,int bc1)
{
  int current;
  current=getpixel(x1,y1);
  printf("\n\n %d",current);
  if((current !=bc1) && (current != fc1))
  {
     setcolor(fc1);
     putpixel(x1,y1,9);
     boundaryfill(x1+1,y1,fc1,bc1);
     boundaryfill(x1-1,y1,fc1,bc1);
     boundaryfill(x1,y1+1,fc1,bc1);
     boundaryfill(x1,y1-1,fc1,bc1);
   }
}
FLOODFILL PROGRAM IN C



#include<conio.h>
#include<stdio.h>
#include<graphics.h>
#include<dos.h>

void fill_right(x,y)
int x , 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(x,y)
int x , 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);

}
}


void main()
{
int x , y ,a[10][10];
int gd, gm ,n,i;

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

printf("\n\n\tEnter the no. of edges of polygon : ");
scanf("%d",&n);
printf("\n\n\tEnter the cordinates of polygon :\n\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\n\tEnter the seed pt. : ");
scanf("%d%d",&x,&y);


cleardevice();
setcolor(WHITE);

for(i=0;i<n;i++) /*- draw poly -*/
{
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();
}

/*SAMPLE INPUT*/
/*Enter the number of edges of polygon 4

X0 Y0 = 50 50
X1 Y1 = 200 50
X2 Y2 = 200 300
X3 Y3 = 50 300

Enter the seed point 100 100*/

Tuesday, 5 February 2013


Mid-Point Ellipse Drawing Program in C

#include <graphics.h>
#include <stdlib.h>
#include <stdio.h>
#include <conio.h>
#include <time.h>
#include <dos.h>

int main(void)
{
int gd=DETECT,gm;
int cenx,ceny;
float Pk,a,b,x,y;
clrscr();

printf("\n\n Enter 'a' and 'b': ");
scanf("%f%f",&a,&b);

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


cenx=getmaxx()/2;
ceny=getmaxy()/2;

Pk=b*b-b*a*a+0.25*a*a;
x=0;
y=b;
putpixel(cenx+x,ceny+y,WHITE);
putpixel(cenx+x,ceny-y,WHITE);
putpixel(cenx-x,ceny+y,WHITE);
putpixel(cenx-x,ceny-y,WHITE);

while (2*x*b*b <= 2*y*a*a)
{
if (Pk<0)
{
x=x+1;
y=y;
Pk=Pk+2*x*b*b+3*b*b;
}
else
{
x=x+1;
y=y-1;
Pk=Pk+2*x*b*b+3*b*b-2*y*a*a+2*a*a;
}
putpixel(cenx+x,ceny+y,WHITE);
putpixel(cenx+x,ceny-y,WHITE);
putpixel(cenx-x,ceny+y,WHITE);
putpixel(cenx-x,ceny-y,WHITE);
delay(40);
}


Pk=(x+0.5)*(x+0.5)*b*b+(y-1)*(y-1)*a*a-a*a*b*b;
putpixel(cenx+x,ceny+y,WHITE);
putpixel(cenx+x,ceny-y,WHITE);
putpixel(cenx-x,ceny+y,WHITE);
putpixel(cenx-x,ceny-y,WHITE);
while (y>0)
{
if (Pk>0)
{
x=x;
y=y-1;
Pk=Pk-2*y*a*a+3*a*a;
}
else
{
x=x+1;
y=y-1;
Pk=Pk-2*y*a*a+3*a*a+2*x*b*b+2*b*b;
}
putpixel(cenx+x,ceny+y,WHITE);
putpixel(cenx+x,ceny-y,WHITE);
putpixel(cenx-x,ceny+y,WHITE);
putpixel(cenx-x,ceny-y,WHITE);
delay(40);
}
gotoxy(1,25);
printf ("\npress any key to exit.");
getch();
closegraph();
return 0;
}
/*SAMPLE INPUT*/

/*Enter 'a' and 'b' 120 80*/

Midpoint Circle Drawing Program in C

#include<stdio.h>
#include<graphics.h>
#include<math.h>

void midptcircle(int xcen,int ycen,int radius)
{
int x=0;
int y=radius;
int p=1-radius;
void plotpoints(int,int,int,int);
plotpoints(xcen,ycen,x,y);
while(x<y)
{
x++;
if(p<0)
p+=2*x+1;
else
{
y--;
p+=2*(x-y)+1;
}
plotpoints(xcen,ycen,x,y);
}
}

void plotpoints(int xcen,int ycen,int x,int y)
{
putpixel(xcen+x,ycen+y,RED);
putpixel(xcen-x,ycen+y,RED);
putpixel(xcen+x,ycen-y,RED);
putpixel(xcen-x,ycen-y,RED);
putpixel(xcen+y,ycen+x,RED);
putpixel(xcen-y,ycen+x,RED);
putpixel(xcen+y,ycen-x,RED);
putpixel(xcen-y,ycen-x,RED);
}

int main()
{
int xcen,ycen,radius;
int gd=DETECT,gm;
clrscr();

printf("Enter centre of circle: ");
scanf("%d%d",&xcen,&ycen);
printf("\nEnter radius: ");
scanf("%d",&radius);
initgraph(&gd,&gm,"");
midptcircle(xcen,ycen,radius);
getch();
return 0;
}

Friday, 1 February 2013

BRESENHAMS CIRCLE DRAWING USING C

# include<stdio.h>
# include<conio.h>
# include<graphics.h>
# include<math.h>

void main()
{
int gd=DETECT,gm;
int r,x,y,p,xc=320,yc=240;

initgraph(&gd,&gm,"C:\\TC\\BGI");
cleardevice();


printf("Enter the radius ");
scanf("%d",&r);


x=0;
y=r;
putpixel(xc+x,yc-y,1);

p=3-(2*r);

for(x=0;x<=y;x++)
{
if (p<0)
{
y=y;
p=(p+(4*x)+6);
}
else
{
y=y-1;

p=p+((4*(x-y)+10));
}

putpixel(xc+x,yc-y,1);
putpixel(xc-x,yc-y,2);
putpixel(xc+x,yc+y,3);
putpixel(xc-x,yc+y,4);
putpixel(xc+y,yc-x,5);
putpixel(xc-y,yc-x,6);
putpixel(xc+y,yc+x,7);
putpixel(xc-y,yc+x,8);

}
getch();
closegraph();
}
BRESENHAMS LINE DRAWING USING C

# include <stdio.h>
# include <conio.h>
# include <graphics.h>

void main()
{
int dx,dy,x,y,p,x1,y1,x2,y2;
int gd,gm;

clrscr();

printf("\n\n\tEnter the co-ordinates of first point : ");
scanf("%d %d",&x1,&y1);
printf("\n\n\tEnter the co-ordinates of second point : ");
scanf("%d %d",&x2,&y2);

dx = (x2 - x1);
dy = (y2 - y1);

p = 2 * (dy) - (dx);

x = x1;
y = y1;

detectgraph(&gd,&gm);
initgraph(&gd,&gm,"e:\\tc\\bgi");
putpixel(x,y,WHITE);

while(x <= x2)
{
if(p < 0)
{
x=x+1;
y=y;
p = p + 2 * (dy);
}
else
{
x=x+1;
y=y+1;
p = p + 2 * (dy - dx);
}
putpixel(x,y,WHITE);
}
getch();
closegraph();

}
DDA LINE DRAWING USING C

#include<stdio.h>
#include<conio.h>
#include<graphics.h>
void DDA(int x1,int y1,int x2,int y2,int col,int del);
void main()
{
int gd=DETECT,gm,x1,x2,y1,y2;
initgraph(&gd,&gm,"");
printf("Enter (x1,y1) and (x2,y2) : ");
scanf("%d%d%d%d",&x1,&y1,&x2,&y2);
DDA(x1,y1,x2,y2,14,20);
getch();
closegraph();
}
void DDA(int x1,int y1,int x2,int y2,int col,int del)
{
int dx,dy,s,i,xi,yi,x,y;
x=x1,y=y1;
dx=x2-x1;
dy=y2-y1;
if(dx>dy)
s=dx;
else
s=dy;
xi=dx/s;
yi=dy/s;
putpixel(x,y,col);
for(i=0;i<s;i++)

{
x+=xi;
y+=yi;

putpixel(x,y,col);
delay(del);

}
}

Activate Office 365 - 2019 Version

                        Link to install office 365 https://windowsedition.com/download-office-365-offline-installer-iso/ Follow the bel...