0% found this document useful (0 votes)
115 views32 pages

Computer Graphics: Lab Manual

This document contains a lab manual index and syllabus for a Computer Graphics course. The index lists topics like line, circle, and ellipse drawing algorithms and 2D and 3D transformations. The syllabus outlines 15 topics covered in the course including Bresenham's algorithm, transformations, and clipping. Equipment for the course includes C and C++ compilers and 3D animation software.

Uploaded by

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

Computer Graphics: Lab Manual

This document contains a lab manual index and syllabus for a Computer Graphics course. The index lists topics like line, circle, and ellipse drawing algorithms and 2D and 3D transformations. The syllabus outlines 15 topics covered in the course including Bresenham's algorithm, transformations, and clipping. Equipment for the course includes C and C++ compilers and 3D animation software.

Uploaded by

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

1

COMPUTER GRAPHICS
CS2405
LAB MANUAL
INDEX
2
SN TITLE PAGE
1A
Line Drawing Using Bresenham Algorithm
1B
Circle Drawing Using Bresenham Algorithm
1C
Ellipse Drawing Using Bresenham Algorithm
3
Two Dimensional Transformations
4
5 Cohen Sutherland 2D line clipping and Windowing
6
7
. Three dimensional transformations
8
9
10
2 Implementation of Line, Circle and ellipse Attributes
3
SYLLABUS
COMPUTER GRAPHICS LABORATORY
CS2405
1. Implementation of Bresenhams Algorithm Line, Circle, Ellipse.
2. Implementation of Line, Circle and ellipse Attributes
3. !o "imensional transformations # ranslation, $otation, %caling, $eflection,
%hear.
&. Composite 2" ransformations
'. Cohen %utherland 2" line clipping and (indo!ing
). %utherland *odgeman +ol,gon clipping Algorithm
-. hree dimensional transformations # ranslation, $otation, %caling
.. Composite 3" transformations
/. "ra!ing three dimensional ob0ects and %cenes
11. 2enerating 3ractal images TOTAL: 45 PERIODS
LIST OF EQUIPMENTS:
14 urbo C
24 5isual C66 !ith 7+E82L
34 An, 3" animation soft!are li9e 3"%:A;, :a,a, Blender
LINE DRAWING USING BRESENHAM ALGORITHM
EX.NO: 1A
4
DATE:
AIM:
To write a C program for Line Drawing Using Bresenham Algorithm.
ALGORITHM:
Step 1 : Start the program.
Step 2 : Declare the necessar !aria"les.
Step 3 : #nitiali$e the graph using d%& d& gd& gm.
Step 4 : Assign the !alues of %'& ' to %& respecti!el.
Step 5 : Similarl& a"solute !alues to d%& d.
Step 6 : put pi%el and set '( to pi%el position.
Step 7 : Using do)while loop& put e&%&&# !alues.
Step 8 * Stop the program.
ROGRAM:
+include,stdio.h-
+include,conio.h-
5
+include,dos.h-
+include,math.h-
+include,graphics.h-
!oid main./
0
float %&&%'&'&%2&2&d%&d&e1
int i&gd2DETECT&gm1
clrscr./1
printf.34n E5TE6 T7E 8ALUE 9: ;'*3/1
scanf.3<f3&=%'/1
printf.34n E5TE6 T7E 8ALUES 9: >'*3/1
scanf.3<f3&='/1
printf.34n E5TE6 T7E 8ALUES 9: ;2 A5D >2*3/1
scanf.3<f<f3&=%2&=2/1
initgraph.=gd&=gm&3 3/1
d%2a"s.%2)%'/1
d2a"s.2)'/1
%2%'1
)'1
e22?.d)d%/1
i2'1
do
0
putpi%el.%&&'(/1
while.e-2@/
0
2A'1
e2e).2?d%/1
B
%2%A'1
e2eA.2?d/1
i2iA'1
dela.'@@/1
Bwhile.i,2d%/1
closegraph./1
6
getch./1
B

OUTUT:
E5TE6 T7E 8ALUE 9: ;' * C@@
E5TE6 T7E 8ALUE 9: >' * D@@
E5TE6 T7E 8ALUE 9: ;2 A5D >2 * E@@ D@@
!IR!LE DRAWING USING BRESENHAM ALGORITHM
E". N# : 1B
D$te :
AIM:
7
To write a C program for Circle Drawing Using Bresenham Algorithm.
ALGORITHM:
Step 1 : Start the program.
Step 2 : Declare the necessar !aria"les.
Step 3 : Create the function for Circle.
Step 4 : Enter the radius and center !alues.
Step 5 : #nitiali$e the graph with gd& gm and assign ,)radius.
Step 6 : Start the circle function and p,) ') radius.
Step 7 : ChecF the while loop until the condition is satisfied.
Step 8 : ChecF the if Gelse condition until the condition is satisfied.
Step % : Assign all operation for circle function and the !alues.
Step 1& : Stop the Hrogram.
ROGRAM:
+include,stdio.h-
+include,conio.h-
+include,graphics.h-
!oid circlefun.int %center& int center&int %&int /1
!oid main./
0
int %2@&radius&%center&center1
int &p&gd2DETECT&gm1
clrscr./1
initgraph.=gd&=gm&3 3/1
printf.34n E5TE6 T7E ;CE5TE6 =>CE5TE6*3/1
scanf.3<d<d3&=%center&=center/1
printf.34n E5TE6 T7E 6AD#US*3/1
scanf.3<d3&=radius/1
2radius1
circlefun.%center&center&%&/1
p2')radius1
8
while.%,/
0
if.p,@/
%2%A'1
else
0
%2%A'1
2)'1
B
if.p,@/
p2pA2?%A'1
else
p2pA2?.%)/A'1
circlefun.%center&center&%&/1
B
getch./1
B
!oid circlefun.int %center&int center&int %&int /
0
putpi%el.%centerA%&centerA&'/1
putpi%el.%center)%&centerA&'/1
putpi%el.%centerA%&center)&'/1
putpi%el.%center)%&center)&'/1
putpi%el.%centerA&centerA%&'/1
putpi%el.%center)&centerA%&'/1
putpi%el.%centerA&center)%&'/1
putpi%el.%center)&center)%&'/1
B
OUTUT:
E5TE6 T7E ; CE5TE6 A5D > CE5TE6 * (@@ 2(@
9
E5TE6 T7E 6AD#US * I@
RESULT:
Thus the a"o!e program JC#6CLE D6AW#5K US#5K B6EASE57ALM is e%ecuted
successfull.
ELLISE DRAWING USING BRESENHAM ALGORITHM
E". N# : 1!
D$te :
AIM:
To write a C program for Circle Drawing Using Bresenham Algorithm.
10
ALGORITHM:
Step '* Start the program.
Step 2* #nitiali$e the !aria"les.
Step E* Call the initgraph./ function.
Step D* Ket the initiali$e points H'&H2.
Step (* Ket the !alues of Co)9rdinates of the ellipse .%&/.
Step C* Enter the coordinates a&" of the ellipse .
Step I* Displa the output.
Step N* Stop the program
ROGRAM
+include,stdio.h-
+include,conio.h-
+include,graphics.h-
+include,math.h-
!oid disp./1
float %&1
int %c&c1
!oid main./
0
int gd2DETECT&gm1
int a&"1
float p'&p21
clrscr./1
initgraph.=gd&=gm&33/1
scanf.3<d<d3&=%c&=c/1
scanf.3<d<d3&=a&="/1
%2@12"1
disp./1
p'2."?"/).a?a?"/A.a?a/OD1
while..2.@?"?"?%/,2.2.@?a?a?//
0
%AA1
11
if.p',2@/
p'2p'A.2.@?"?"?%/A."?"/1
else
0
))1
p'2p'A.2.@?"?"?%/A."?"/).2.@?a?a?/1
B
disp./1
%2)%1
disp./1
%2)%1
B
%2a1
2@1
disp./1
p22.a?a/A2.@?."?"?a/A."?"/OD1
while..2.@?"?"?%/-.2.@?a?a?//
0
AA1
if.p2-@/
p22p2A.a?a/).2.@?a?a?/1
else
0
%))1
p22p2A.2.@?"?"?%/).2.@?a?a?/A.a?a/1
B
disp./1
2)1
disp./1
2)1
B
getch./1
closegraph./1
B
!oid disp./
12
0
putpi%el.%cA%&cA&'@/1
putpi%el.%c)%&cA&'@/1
putpi%el.%cA%&c)&'@/1
putpi%el.%cA%&c)&'@/1
B
INUT
Ellipse Drawing Algorithm
E'te( t)e *#+#(,-'$te.
;c 2 2@@
>c 2 2@@
A 2 '@@
B 2 I@
OUTUT
Re./0t:
13
Thus using CAA program implementation of BresenhamPs algorithm for line& circle and
ellipse drawing is done.
TWO DIMENSIONAL TRANS1ORMATIONS
Ex. No. : 3 Date :
14
AIM:
To write a C program for Two Dimensional Transformations.
ALGORITHM:
Step 1: Start the program.
Step 2: Declare the necessar !aria"les and initiali$e the graph& gd& gm.
Step 3: Use do)while loop and declare the function clear de!ice.
Step 4: Create four cases translation& scaling & rotation and e%it.
Step 5: #n case ' enter the translation !alues and print the translation
o"Qect.
Step 6* #n case 2 enter the scaling !alues and print the scaling o"Qect.
Step 7: #n case E enter the rotaion !alues and print rotation o"Qect.
Step 8: ClocFwise rotation and counter clocFwise rotation use the same
eRuation.
Step %: Stop the program.
ROGRAM:
+include,stdio.h-
+include,conio.h-
+include,graphics.h-
+include,math.h-
+include,stdli".h-
!oid main./
0
15
int %&&c1
float a1
int gd2DETECT&gm1
initgraph.=gd&=gm&3 3/1
do
0
clearde!ice./1
printf.3'.T6A5SLAT#95 2.SCAL#5K E.69TAT#95
D.E;#T3/1
printf.34n E5TE6 >6 C79#CE*3/1
scanf.3<d3&=c/1
switch.c/
0
case '*
rectangle.'@@&2@@&E@@&E@@/1
printf.34nE5TE6 T7E T; A5D T> 8ALUE*3/1
scanf.3<d<d3&=%&=/1
outte%t%.'E@&'N@&3 96#K#5AL 9BSECT3/1
rectangle.'@@A%&2@@A&E@@A%&E@@A/1
outte%t%.'E@A%&'N@&3 T6A5SLAT#95
9BSECT3/1
"reaF1
case 2*
rectangle.(@&'@@&'(@&'(@/1
printf.34n E5TE6 T7E S; A5D S>
8ALUE*3/1
scanf.3<d<d3&=%&=/1
outte%t%.EN&N(&396#K#5AL 9BSECT3/1
rectangle.(@?%&'@@?&'(@?%&'(@?/1
outte%t%.2(@&2(@&3SCAL#5K 9BSECT3/1
"reaF1
case E*
printf.34n E5TE6 T7E ; A5D > 8ALUE*3/1
scanf.3<d<d3&=%&=/1
16
printf.34n E5TE6 T7E A5KLE13/1
scanf.3<d3&=c/1
a2.E.'D?c/O'N@1
clearde!ice./1
line.'@@&'@@&2@@&'@@/1
outte%t%.2'@&'@@&396#K#5AL 9BSECT3/1
line.'@@?cos.a/)'@@?sin.a/A%?.')cos.a//
A?sin.a/&'@@?sin.a/A'@@?cos.a/A?.')cos.a//
)%?sin.a/&2@@?cos.a/)'@@?sin.a/A%?.')cos.a//
A?sin.a/&2@@?sin.a/A'@@?cos.a/A?.')cos.a//
)%?sin.a//1
outte%t%.''@&I(&3C9U5TE6 CL9CTW#SE
69TAT#953/1
line.'@@?cos.a/A'@@?sin.a/A%?.')cos.a//
)?sin.a/&)'@@?sin.a/A'@@?cos.a/A?.')cos.a//
A%?sin.a/&2@@?cos.a/A'@@?sin.a/A%?.')cos.a//
)?sin.a/&)2@@?sin.a/A'@@?cos.a/A?.')cos.a//
A%?sin.a//1
outte%t%.''@&'(@&3CL9CTW#SE 69TAT#953/1
getch./1
"reaF1
case D*
e%it.@/1
B
getch./1
Bwhile.cU2D/1
B
17
OUTUT:
'.T6A5SLAT#95 2. SCAL#5K E. 69TAT#95 D. E;#T
E5TE6 >9U6 9HT#95 * '
E5TE6 T7E T; A5D T> 8ALUE * '(@ '(@
96#K#5AL 9BSECT T6A5SLAT#95 9BSECT
'. T6A5SLAT#95 2.SCAL#5K E. 69TAT#95 D. E;#T
E5TE6 >9U6 9HT#95 * 2
E5TE6 >9U6 S; A5D S> 8ALUE * 2 2
'. T6A5SLAT#95 2.SCAL#5K E. 69TAT#95 D. E;#T
E5TE6 >9U6 9HT#95 * E
E5TE6 T7E ; A5D > 8ALUE *'@@ '@@
E5TE6 T7E A5KLE *V@
C9U5TE6 CL9CTW#SE
69TAT#95

96#K#5AL 9BSECT CL9CTW#SE 69TAT#95
18
RESULT:
Thus the a"o!e programMTW9 D#LE5S#95AL
T6A5S:96LAT#95SM #s e%ecuted successfull.
!OHEN SUTHERLAND 2D LINE !LIING AND WINDOWING
E". N# : 5
19
D$te :
AIM:
To implement cohen-sutherland 2d clippin and !indo!-"ie! port
mappin
!OHEN+SUTHERLAND 2D LINE !LIING
+include,stdio.h-
+include,conio.h-
+include,graphics.h-
+include,math.h-
float c%l&c%r&ct&c"1
code.float &float/1
!oid clip.float &float&float&float/1
!oid rect.float &float&float&float/1
main./
0
float %'&'&%2&21
int g2@&d1
initgraph.=g&=d&3c*44tc44"in3/1
sette%tstle.'&@&'/1
outte%t%.D@&'(&3BE:96E CL#HH#5K3/1
printf.34n Hlease Enter Left&Bottom&6ight&Top 9f Clip Window3/1
scanf.3<f<f<f<f3&=c%l&=c"&=c%r&=ct/1
rect.c%l&c"&c%r&ct/1
getch./1
printf.34n Enter The Line Coordinate3/1
scanf.3<f<f<f<f3&=%'&='&=%2&=2/1
line.%'&'&%2&2/1
getch./1
clearde!ice./1
20
sette%tstle.'&@&'/1
outte%t%.D@&'(&3A:TE6 CL#HH#5K3/1
clip.%'&'&%2&2/1
getch./1
closegraph./1
B
!oid clip.float %'&float '&float %2&float 2/
0
int c&c'&c21
float %&1
c'2code.%'&'/1
c22code.%2&2/1
getch./1
while..c'U2@/WW.c2U2@//
0
if..c'=c2/U2@/
goto out1
c2c'1
if.c22@/
c2c21
if..c='/22'/
0
2'A.2)'/?.c%l)%'/1
%2c%l1
B
else
if..c=2/222/
0
2'A.2)'/?.c%l)%'/O.%2)%'/1
%2c%r1
B
21
else
if..c=N/22N/
0
%2%'A.%2)%'/?.c")'/O.2)'/1
2c"1
B
else
if..c=D/22D/
0
%2%'A.%2)%'/?.ct)'/O.2)'/1
2ct1
B
if.c22c'/
0
%'2%1
'21
c'2code.%&/1
B
else
0
%22%1
221
c22code.%&/1
B
B
out*
rect.c%l&c"&c%r&ct/1
line.%'&'&%2&2/1
B
code.float % &float /
0
int c2@1
if.%,c%l/ c2'1
22
else
if.%-c%r/ c221
else
if.,c"/ c2cWN1
else
if.-ct/ c2cWD1
return c1
B
!oid rect.float %l&float "&float %r&float t/
0
line.%l&"&%r&"/1
line.%r&"&%r&t/1
line.%r&t&%l&t/1
line.%l&t&%l&"/1
B
OUTUT
SAMLE INUT:
Hlease Enter Left & Bottom & 6ight & Top 9f The Clip window
2@@
2@@
D@@
D@@
Hlease Enter The Line Coordinates .;'& >'& ;2& >2/
'(@
E@@
D@@
23
D(@
SAMLE OUTUT:
BE:96E CL#HH#5K
A#T$% C&'((')*+
W-',#2-'3 T# 4-e2p#(t M$pp-'3
24
+include,stdio.h-
+include,conio.h-
+include,graphics.h-
+include,math.h-
main./
0
float s%&s1
int w'&w2&wE&wD&%'&%2&%E&%D&'&2&E&D&!'&!2&!E&!D1
int gd2DETECT&gm1
initgraph.=gd&=gm&3c*44tc44"gi3/1
printf.3Enter The Coordinate %'&'&%2&2&%E&E4n3/1
scanf.3<d<d<d<d<d<d3&=%'&='&=%2&=2&=%E&=E/1
clearde!ice./1
w'2(1
w22(1
wE2CE(1
wD2DC(1
rectangle.w'&w2&wE&wD/1
line.%'&'&%2&2/1
line.%2&2&%E&E/1
line.%E&E&%'&'/1
getch./1
!'2D2(1
!22I(1
!E2((@1
!D22(@1
s%2.float/.!E)!'/O.wE)w'/1
s2.float/.!D)!2/O.wD)w2/1
rectangle.!'&!2&!E&!D/1
%'2!'Afloor...float/.%')w'/?s%/A.(/1
%22!'Afloor...float/.%2)w'/?s%/A.(/1
%E2!'Afloor...float/.%E)w'/?s%/A.(/1
'2!2Afloor...float/.')w2/?s/A.(/1
22!2Afloor...float/.2)w2/?s/A.(/1
25
E2!2Afloor...float/.E)w2/?s/A.(/1
line.%'&'&%2&2/1
line.%2&2&%E&E/1
line.%E&E&%'&'/1
getch./1
return @1
B
SAMLE INUT:
Enter The Coordinate %'&'&%2&2&%E&E
'@@
2@@
E@@
D@@
(@@
E(@
SAMLE OUTUT:
26


%esult +
Ex. No. : 07 Date :
27
TRANSLATION AND S!ALING USING 3D
AIM:
To write a C program for Translation and Scaling Using ED Lethod.
ALGORITHM:
Step 1: Start the program.
Step 2: Declare the necessar !aria"les& with mem"er functions.
Step 3: Create the main function& in that function to initiali$e graph using
do)while statement.
Step 4: Using Switch statement for translation& scaling& e%it.
Step 5: Using get function for getting the !alues.
Step 6: Similarl& get the draw function for draw the lines.
Step 7: Stop the program.
28
ROGRAM:
+include,stdio.h-
+include,conio.h-
+include,graphics.h-
+include,math.h-
int n&dep1
float %X'@Y&X'@Y&n%X'@Y&nX'@Y1
!oid translation./1
!oid scaling./1
!oid rotation./1
!oid draw.float %XY&float XY/1
!oid get./1
!oid main./
0
int gd2DETECT&gm&i&ch1
initgraph.=gd&=gm&3 3/1
get./1
do
0
clearde!ice./1
draw.%&/1
printf.34n '.T6A5SLAT#95 2.SCAL#5K E.E;#T3/1
printf.34n E5TE6 U6 C79#CE*3/1
scanf.3<d3&=ch/1
switch.ch/
0
case '*
translation./1
"reaF1
29
case 2*
scaling./1
"reaF1
case E*
closegraph./1
e%it.@/1
B
getch./1
Bwhile.chU2E/1
B
!oid get./
0
int i1
printf.34n E5TE6 T7E 59.9: S#DES= DEHT7 9: T7E
H9L>K95*3/1
scanf.3<d<d3&=n&=dep/1
printf.3n E5TE6 T7E C9 96D#5ATES4n3/1
for.i2@1i,n1iAA/
0
printf.34n E5TE6 T7E ;<d=><d 8ALUE*3/1
scanf.3<f<f3&=%XiY&=XiY/1
B
B
!oid draw.float %XY&float XY/
0
int i1
for.i2@1i,n)'1iAA/
line.%XiY&XiY&%XiA'Y&XiA'Y/1
line.%XiY&XiY&%X@Y&X@Y/1
for.i2@1i,n)'1iAA/
line.%XiYAdep&XiY)dep&%XiA'YAdep&XiA'Y)dep/1
line.%XiYAdep&XiY)dep&%X@YAdep&X@Y)dep/1
for.i2@1i,n1iAA/
line.%XiY&XiY&%XiYAdep&XiY)dep/1
30
B
!oid translation./
0
int i&ch1
float t%&t1
draw.%&/1
printf.3E5TE6 T7E T6A5SLAT#95:ACT96 T; =T>
8ALUE*3/1
scanf.3<f<f3&=t%&=t/1
for.i2@1 i,n1iAA/
0
n%XiY2%XiYAt%1
nXiY2XiYAt1
B
draw.n%&n/1
B
!oid scaling./
0
int i&ch1
float s%&s1
draw.%&/1
printf.3E5TE6 T7E SCAL#5K :ACT96 S; =S>
8ALUE*3/1
scanf.3<f<f3&=s%&=s/1
for.i2@1i,n1iAA/
0
n%XiY2%XiY?s%1
nXiY2XiY?s1
B
draw.n%&n/1
B
31
OUTUT:
E5TE6 T7E 59 9: S#DES = DEHT7 9: T7E H9L>K95 * D '@
E5TE6 T7E C9)96D#5ATES *
E5TE6 T7E ;' A5D >' 8ALUES * 2@@ '@
E5TE6 T7E ;2 A5D >2 8ALUES * 2(@ '@
E5TE6 T7E ;E A5D >E 8ALUES * 2(@ C@
E5TE6 T7E ;D A5D >D 8ALUES * 2@@ C@
'. T6A5SLAT#95 2. SCAL#5K E. E;#T
E5TE6 >9U6 C79#CE * '
E5TE6 T7E T6A5SLAT#95 :ACT96S T; A5D T> 8ALUES * '@@ @
'. T6A5SLAT#95 2. SCAL#5K E. E;#T
E5TE6 >9U6 C79#CE * 2
E5TE6 T7E SCAL#5K :ACT96S S; A5D S> 8ALUES * 2 2
32
RESULT:
Thus the a,o"e proram T%A)-&AT'.) A)/
-CA&')* 0-')* 3/1 's e2ecuted success3ull45

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy