0% found this document useful (0 votes)
11 views13 pages

Graphics

The document contains multiple assignments related to Computer Aided Graphics from S.S.V.P. Sanstha’s L.K.Dr.P.R.Ghogrey Science College. It includes code examples for drawing block diagrams, flowchart symbols, and implementing various algorithms such as Bresenham’s Line and Circle Drawing, DDA Line Drawing, and Cohen-Sutherland line clipping. Each assignment is accompanied by relevant C code using a graphics library to illustrate the concepts.

Uploaded by

laita nikam
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views13 pages

Graphics

The document contains multiple assignments related to Computer Aided Graphics from S.S.V.P. Sanstha’s L.K.Dr.P.R.Ghogrey Science College. It includes code examples for drawing block diagrams, flowchart symbols, and implementing various algorithms such as Bresenham’s Line and Circle Drawing, DDA Line Drawing, and Cohen-Sutherland line clipping. Each assignment is accompanied by relevant C code using a graphics library to illustrate the concepts.

Uploaded by

laita nikam
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 13

S.S.V.P. Sanstha’s L.K.Dr.P.R.

Ghogrey Science College, Dhule


Department of Computer Science
Sub:- Computer Aided Graphics
Roll No :- Date:
Name : -
Assignment No- 1a) Draw the Block Diagram of Computer using standard Graphics
Library

#include<graphics.h>
main()
{
int gd=DETECT,gm;
initgraph(&gd,&gm,"c:\\tc\\bgi");
setfillstyle(SOLID_FILL,12);
bar(100,50,300,100);
setfillstyle(SOLID_FILL,15);
bar(100,100,300,150);
setfillstyle(SOLID_FILL,2);
bar(100,150,300,200);
setfillstyle(SOLID_FILL,5);
bar(100,50,100,400);
setcolor(1);
circle(200,126,24);
line(200,100,200,150);
line(175,125,225,125);
line(210,102,190,148);
line(216,105,180,141);
line(223,113,177,136);
line(190,102,210,148);
line(182,107,218,143);
line(177,116,223,134);
}
S.S.V.P. Sanstha’s
L.K.Dr.P.R.Ghogrey Science College, Dhule
Department of Computer Science
Sub:- Computer Aided Graphics
Roll No :- Date:
Name : -
Assignment No- 1a) Draw the Block Diagram of Computer using standard Graphics
Library

#include<graphics.h>
main()
{
int gd=DETECT,gm;
initgraph(&gd,&gm,"c:\\TC\\bgi");
rectangle(200,100,400,330);
rectangle(230,120,370,150);
rectangle(230,200,370,230);
rectangle(230,280,370,310);
rectangle(82,202,180,230);
rectangle(430,202,535,230);
line(180,215,200,215);
outtextxy(195,212,">");
line(400,215,430,215);
outtextxy(425,212,">");
outtextxy(250,130,"Control Unit");
outtextxy(270,210,"A.L.U.");
outtextxy(270,290,"Memory");
outtextxy(110,215,"Input");
outtextxy(460,215,"Output");
line(250,150,250,200);
settextstyle(1,1,1);
outtextxy(237,188,"<");
line(285,150,285,200);
outtextxy(272,148,">");
line(250,230,250,280);
outtextxy(237,269,"<");
line(285,230,285,280);
outtextxy(272,228,">");
settextstyle(0,0,0);
outtextxy(200,350,"Block diagram of computer.");
}

S.S.V.P. Sanstha’s
L.K.Dr.P.R.Ghogrey Science College, Dhule
Department of Computer Science
Sub:- Computer Aided Graphics
Roll No : Date:
Name :-
Assignment No- 1c) Draw the various flowchart symbols using standard Graphics Library

#include<graphics.h>
void main()
{
int gd=DETECT,gm;
initgraph(&gd,&gm,"c:\\tc\\bgi");
line(100,50,200,50);
line(100,100,200,100);
arc(100,75,90,270,25);
arc(200,75,270,450,25);
outtextxy(110,30,"START");
line(500,50,600,50);
line(500,100,600,100);
arc(500,75,90,270,25);
arc(600,75,270,450,25);
outtextxy(510,30,"STOP");
rectangle(75,200,225,250);
outtextxy(100,170,"PROCESS");
line(475,200,600,200);
line(475,250,600,250);
line(475,200,450,225);
line(450,225,475,250);
line(600,200,625,225);
line(625,225,600,250);
outtextxy(525,170,"LOOP");
line(150,350,200,400);
line(200,400,150,450);
line(150,450,100,400);
line(100,400,150,350);
outtextxy(125,320,"CONDITIONAL");
line(350,10,350,470);
line(10,150,630,150);
line(10,300,630,300);
line(630,10,630,470);
line(10,470,630,470);
line(10,10,10,470);
line(10,10,630,10);
line(400,350,600,350);
line(600,350,575,400);
line(575,400,375,400);
line(375,400,400,350);
outtextxy(400,325,"INPUT\OUTPUT");
S.S.V.P. Sanstha’s
getch(); }
L.K.Dr.P.R.Ghogrey Science College, Dhule
Department of Computer Science
Sub:- Computer Aided Graphics
Roll No : Date:
Name :-
Assignment No- 2)Bresenham’s Line Drawing Algorithm

#include<graphics.h>
#include<math.h>
#include<stdio.h>
void main()
{
int gd=DETECT,gm;
int x1,y1,x2,y2;
int dx,dy,i,e;
float x,y;
char s[80];
clrscr();
initgraph(&gd,&gm,"c:\\tc\\bgi");
printf("\n enter starting point x1=");
scanf("\n%d",&x1);
printf("\n enter starting point y1=");
scanf("\n%d",&y1);
printf("\n enter ending point x2=");
scanf("\n%d",&x2);
printf("\n enter ending point y2=");
scanf("\n%d",&y2);
dx=x2-x1;
dy=y2-y1;
x=x1;
y=y1;
e=2*(dy-dx);
i=1;
cleardevice();
a:putpixel(ceil(x),ceil(y),WHITE);
while(e>=0)
{
y=y++;
e=e-2*dx;
}
x++;
e=e+2*dy;
i++;
if(i<=dx)
goto a;
getch();
}
S.S.V.P. Sanstha’s
L.K.Dr.P.R.Ghogrey Science College, Dhule
Department of Computer Science
Sub:- Computer Aided Graphics
Roll No : Date:
Name :-
Assignment No- 4)DDA Line Drawing Algorithm

#include<graphics.h>
void main()
{
int gd=DETECT,gm;
float x,y,x1,y1,x2,y2,x3,y3,dx,dy;
initgraph(&gd,&gm,"c:\\tc\\bgi");
printf("\n Enter the value of x1&y1=");
scanf("%f%f",&x1,&y1);
printf("\n Enter the value of x2&y2=");
scanf("%f%f",&x2,&y2);
dx=x2-x1;
dy=y2-y1;
if(dy>dx)
{
y=dy/dy;
x=dx/dy;
}
else
{
y=dy/dx;
x=dx/dx;
}
cleardevice();
do
{
x3=x1+x;
y3=y1+y;
putpixel(x3,y3,10);
delay(20);
x1=x3;
y1=y3;
}
while(x1<=x2);
getch();
S.S.V.P. Sanstha’s
}
L.K.Dr.P.R.Ghogrey Science College, Dhule
Department of Computer Science
Sub:- Computer Aided Graphics
Roll No : Date:
Name :-
Assignment No-3)Bresenham’s Circle Drawing Algorithm
#include<graphics.h>
#include<math.h>
#include<stdio.h>
void bres(int x1,int y,int r);
void main()
{
int gd=DETECT, gm;
int x1, y1, r;
initgraph(&gd,&gm,"c:\\tc\\bgi");
printf("\n enter point x=");
scanf("\n %d",&x1);
printf("\n enter point y=");
scanf("\n%d",&y1);
printf("\n enter radious of circle=");
scanf("\n%d", &r);
bres(x1,y1,r);
getch();
}
void bres(int x1,int y1,int r)
{
int i,d,x,y;
x=0;
y=r;
d=3-(2*r);
else
do
{
{
d=d+(4*(x-y))+10;
putpixel(x1+x,y1+y,15);
y=y-1;
putpixel(x1+y,y1+x,15);
}
putpixel(x1+y,y1-x,15);
x++;
putpixel(x1+x,y1-y,15);
delay(10);
}while(x<=y);
};
putpixel(x1-x,y1-y,15);
putpixel(x1-y,y1-x,15);
putpixel(x1-y,y1+x,15);
putpixel(x1-x,y1+y,15); x[i]=x[i]+tx;
if(d<=0) y[i]=y[i]+ty;
{ }
d=d+(4*x)+6; }
void ST()
{
int sx,sy;
S.S.V.P. Sanstha’s
printf("\n Enter sx&sy=");
L.K.Dr.P.R.Ghogrey Science College, Dhule
scanf("%d%d",&sx,&sy);
Department of Computer Science
cleardevice();
Sub:- Computer Aided Graphics
Showline();
Roll No : draw(); Date:
Name :- for(i=0;i<n;i++)
{
Assignment No- 5)Implimentation of Translation,Scaling & Rotation .Transformation of polygons
with respective any points x[i]=x[i]*sx;
y[i]=y[i]*sy;
}
#include<stdio.h>
}
#include<conio.h>
void RT()
#include<graphics.h>
{
#include<math.h>
int x1[30],y1[30];
int n,x[30],y[30],i;
float Q;
void Transformation();
printf("\n Enter angle of rotation=");
void Scaling();
scanf("%f",&Q);
void Rotation();
Q=Q*(3.142/180);
void Showline()
cleardevice();
{
Showline();
line(320,0,320,480);
draw();
line(0,240,640,240);
for(i=0;i<n;i++)
}
{
void info()
x1[i]=x[i]*cos(Q)+y[i]*sin(Q);
{
y1[i]=-(x[i]*sin(Q))+y[i]*cos(Q);
printf("\n Enter number of vertices=");
}
scanf("%d",&n);
for(i=0;i<n;i++)
printf("\nEnter%d cordinates=",n*2);
{
for(i=0;i<n;i++)
x[i]=x1[i];
{
y[i]=y1[i];
scanf("%d%d",&x[i],&y[i]);
}
}
}
}
void draw()
{
for(i=0;i<n-1;i++)
line(320+x[i],240-y[i],320+x[i+1],240-y[i+1]);
line(320+x[0],240-y[0],320+x[n-1],240-y[n-1]);
}
void TT()
{
int tx,ty;
printf("\n Enter tx&ty=");
scanf("%d%d",&tx,&ty);
cleardevice();
Showline();
draw();
for(i=0;i<n;i++)
{
void main()
{
RT();
int gd=DETECT,gm;
setcolor(14);
int ch;
draw();
char ans;
getch();
clrscr();
cleardevice();
initgraph(&gd,&gm,"c:\\tc\\bgi");
break;
do
case 4:exit();
{
default:printf("\n Wrong choice,Try again");
printf("\n 1:For Translation");
}
printf("\n 2:For scaling");
printf("\n Do you want to continue=");
printf("\n 3:For Rotation");
scanf("%s",&ans);
printf("\n 4:For Exit");
cleardevice();
printf("\n Enter your choice=");
}
scanf("%d",&ch);
while(ans=='y'||ans=='Y');
switch(ch)
getch();
{
closegraph();
case 1:setcolor(15);
}
info();
cleardevice();
Showline();
draw();
getch();
cleardevice();
TT();
setcolor(14);
draw();
getch();
cleardevice();
break;
case 2:setcolor(15);
info();
cleardevice();
Showline();
draw();
getch();
cleardevice();
ST();
setcolor(14);
draw();
getch();
cleardevice();
break;
case 3:setcolor(15);
info();
cleardevice();
Showline();
draw();
getch();
cleardevice();

S.S.V.P. Sanstha’s
L.K.Dr.P.R.Ghogrey Science College, Dhule
Department of Computer Science
Sub:- Computer Aided Graphics
Roll No : Date:
Name :-
Assignment No-6)Implement Cohen-Sutherland line clipping algorithm

#include<graphics.h>
main()
{
int xmin,ymin,xmax,ymax;
int gd=DETECT,gm;
int x1,y1,x2,y2;
float m,i,count=0;
int code1[4],code2[4];
clrscr();
initgraph(&gd,&gm,"c:\\tc\\bgi");
printf("Enter clipping boundry");
scanf("%d%d%d%d",&xmin,&ymin,&xmax,&ymax);
printf("Enter end points");
scanf("%d%d%d%d",&x1,&y1,&x2,&y2);
cleardevice();
printf("line boundry clipping");
rectangle(xmin,ymin,xmax,ymax);
line(x1,y1,x2,y2);
getch();
for(i=0;i<4;i++)
{
code1[i]=0;
code2[i]=0;
}
if(y1<ymin)
{
code1[0]=1;
}
if(y1>ymax)
{
code1[1]=1;
}
if(x1<xmin)
{
code1[3]=1;
}
if(x1>xmax)
{
code1[2]=1;
}
if(y2<ymin)
{
code2[0]=1;
}
if(y2>ymax)
{
code2[1]=1;
}
if(x2<xmin)
{ }

code2[3]=1; if(code1[3]==1)

} {

if(x2>xmax) y1=y1+(xmin-x1)*m;

{ x1=xmin;

code2[2]=1; }

} if(code1[2]==1)

printf("Before clipping"); {

rectangle(xmin,ymin,xmax,ymax); y1=y1+(xmax-x1)*m;

line(x1,y1,x2,y2); x1=xmax;

count =0; }

for(i=0;i<4;i++) if(code2[0]==1)

{ {

if(code1[i]==0) x2=x2+(ymin-y2)/m;

count ++; y2=ymin;

} }

if(count==8) if(code2[1]==1)

{ {

getch(); x2=x2+(ymax-y2)/m;

cleardevice(); y2=ymax;

rectangle(xmin,ymin,xmax,ymax); }

line(x1,y1,x2,y2); if(code2[2]==1)

} {

for(i=0;i<=3;i++) y2=y2+(xmax-x2)*m;

if(code1[1]&code2[1]) x2=xmax;

{ }

getch(); if(code2[3]==1)

rectangle(xmin,ymin,xmax,ymax); {

exit(0); y2=y2+(xmin-x2)*m;

} x2=xmin;

m=((y2-y1)/(x2-x1)*1.0); }

if(code1[0]==1) getch();

{ cleardevice();

x1=x1+(ymin-y1)/m; printf("After clipping");

y1=ymin; rectangle(xmin,ymin,xmax,ymax);

} line(x1,y1,x2,y2);
}
if(code1[1]==1)
{
x1=x1+(ymax-y1)/m;
y1=ymax;

You might also like