Beruflich Dokumente
Kultur Dokumente
Progam no. 5
#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:\\turboc3\\bgi");
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();
scanf("%d",&c);
switch(c)
case 1:
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:
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:
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:
closegraph();
}
Program no 7
#include <iostream.h>
code |= RIGHT;
code |= BOTTOM;
code |= TOP;
return code;
int accept = 0;
while (true)
accept = 1;
break;
// in same region
break;
else
// rectangle
int code_out;
double x, y;
if (code1 != 0)
code_out = code1;
else
code_out = code2;
// x = x1 + (1 / slope) * (y - y1)
y = y_min;
x = x_max;
x = x_min;
// by intersection point
if (code_out == code1)
x1 = x;
y1 = y;
else
x2 = x;
y2 = y;
if (accept==1)
<< y1 << " to "<< x2 << ", " << y2 << endl;
else
// Driver code
int main()
cohenSutherlandClip(5, 5, 7, 7);
cohenSutherlandClip(1, 5, 4, 1);
return 0;
}
Program no. 8
#include<stdio.h>
#include<conio.h>
#include<dos.h>
#include<graphics.h>
{ int current;
current=getpixel(x,y);
if((current!=boundary)&&(current!=fill))
setcolor(fill);
putpixel(x,y,fill);
delay(5);
boundaryfill(x+1,y,fill,boundary);
boundaryfill(x-1,y,fill,boundary);
boundaryfill(x,y+1,fill,boundary);
boundaryfill(x,y-1,fill,boundary);
void main()
int gd=DETECT,gm;
initgraph(&gd,&gm,"C:\\Turboc3\\BGI");
setcolor(10);
rectangle(250,200,310,260);
boundaryfill(280,250,12,10);
getch();
}
Program no. 10
#include <stdio.h>
#include <graphics.h>
#include <conio.h>
#include <math.h>
#include <process.h>
#define TRUE 1
#define FALSE 0
BOTTOM = 0x2,
RIGHT = 0x4,
LEFT = 0x8
};
float xmin,xmax,ymin,ymax;
outcode outcode0,outcode1,outcodeOut;
outcode0 = CompOutCode(x0,y0);
outcode1 = CompOutCode(x1,y1);
do
if(!(outcode0|outcode1))
accept = TRUE;
done = TRUE;
}
else
done = TRUE;
else
float x,y;
outcodeOut = outcode0?outcode0:outcode1;
x = x0+(x1-x0)*(ymax-y0)/(y1-y0);
y = ymax;
else
x = x0+(x1-x0)*(ymin-y0)/(y1-y0);
y = ymin;
else
y = y0+(y1-y0)*(xmax-x0)/(x1-x0);
x = xmax;
else
y = y0+(y1-y0)*(xmin-x0)/(x1-x0);
x = xmin;
if(outcodeOut==outcode0)
x0 = x;
y0 = y;
outcode0 = CompOutCode(x0,y0);
else
x1 = x;
y1 = y;
outcode1 = CompOutCode(x1,y1);
}while(done==FALSE);
if(accept)
line(x0,y0,x1,y1);
rectangle(xmin,ymin,xmax,ymax);
outcode code = 0;
if(y>ymax)
code|=TOP;
else
if(y<ymin)
code|=BOTTOM;
if(x>xmax)
code|=RIGHT;
else
if(x<xmin)
code|=LEFT;
return code;
void main( )
float x1,y1,x2,y2;
clrscr( );
scanf("%d",&n);
for(i=0;i<2*n;i++)
scanf("%d",&poly[i]);
poly[2*n]=poly[0];
poly[2*n+1]=poly[1];
scanf("%f%f%f%f",&xmin,&ymin,&xmax,&ymax);
rectangle(xmin,ymin,xmax,ymax);
getch( );
cleardevice( );
for(i=0;i<n;i++)
clip(poly[2*i],poly[(2*i)+1],poly[(2*i)+2],poly[(2*i)+3]);
getch( );
restorecrtmode( );
50
50
200
100
350
350
80
200
40
80
150
150
300
300*/
Program 9
#include<graphics.h>
#include<conio.h>
int main(){
int gd = DETECT,gm;
/* Draw Hut */
setcolor(WHITE);
rectangle(150,180,250,300);
rectangle(250,180,420,300);
rectangle(180,250,220,300);
line(200,100,150,180);
line(200,100,250,180);
line(200,100,370,100);
line(370,100,420,180);
/* Fill colours */
setfillstyle(SOLID_FILL, BROWN);
setfillstyle(SLASH_FILL, BLUE);
setfillstyle(HATCH_FILL, GREEN);
closegraph();
return 0;
}
Program no 12
xi = dx / (float) s;
yi = dy / (float) s;
x = x1;
y = y1;
clrscr();
OUTPUT
PROGRAM NO. 11(a)
/* Program in c for printing a rectangle with the help of DDA aglorithm */
#include <graphics.h>
#include <stdio.h>
#include <conio.h>
#include <math.h>
int dx,dy,m,s;
float xi,yi,x,y;
dx = x2 - x1;
dy = y2 - y1;
s = abs(dx);
else
s = abs(dy);
xi = dx / (float) s;
yi = dy / (float) s;
x = x1;
y = y1;
x += xi;
y += yi;
putpixel(x, y, WHITE);
void main()
clrscr();
drawline(150,450,450,450);
drawline(450,450,450,150);
drawline(450,150,150,150);
drawline(150,150,150,450);
getch();
}
Program 11(b)
/* Program in C for printing a rectangle with the help of Bresenham’s line drawing alglorithm */
#include<stdio.h>
#include<conio.h>
#include<graphics.h>
void lineBres(int,int,int,int);
void setPixel(int,int);
void main()
int x,y,length,breadth;
int driver=DETECT,mode;
clrscr();
scanf("%d %d",&x,&y);
scanf("%d",&length);
scanf("%d",&breadth);
getch();
initgraph(&driver,&mode,"C:\\TURBOC3\\BGI");
lineBres(x,y,x+length,y);
lineBres(x+length,y,x+length,y-breadth);
lineBres(x+length,y-breadth,x,y-breadth);
lineBres(x,y-breadth,x,y);
getch();
closegraph();
float error,m;
int x,y;
x=x1;
y=y1;
if(x1==x2)
while(y!=y2)
if(y2-y1>0)
++y;
else
--y;
putpixel(x,y,2);
else
m=(float)(y2-y1)/(x2-x1);
error=0;
putpixel(x,y,2);
while(x!=x2)
error+=m;
if(error>.5)
{
if(x2-x1>0)
y+=1;
else
y-=1;
--error;
if(x2-x1>0)
++x;
else
--x;
putpixel(x,y,2);