cg-lab
TRANSCRIPT
-
7/23/2019 CG-LAB
1/34
1
COMPUTER GRAPHICSCS2405
LAB MANUAL
INDEX
-
7/23/2019 CG-LAB
2/34
2
SN TITLE PAGE
1A
Line Drawing Using Bresenham Algorithm
1B Circle Drawing Using Bresenham Algorithm
1CEllipse Drawing Using Bresenham Algorithm
2 . Implementation of Line, Circle and ellipse Attributes
3 Two Dimensional Transformations
4
5 Cohen Sutherland 2D line clipping and Windowing
6
7. Three dimensional transformations
8
9
10
-
7/23/2019 CG-LAB
3/34
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 +olgon clipping Algorithm
-. hree dimensional transformations # ranslation, $otation, %caling
. Composite 3" transformations
/. "ra!ing three dimensional ob0ects and %cenes
1. enerating ractal images TOTAL: 45 PERIODS
LIST OF EQUIPMENTS:
14 urbo C
24 5isual C66 !ith 7+E8L
34 An 3" animation soft!are li9e 3"%:A;, :aa, Blender
LINE DRAWING USING BRESENHAM ALGORITHM
EX.NO: 1A
-
7/23/2019 CG-LAB
4/34
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-
-
7/23/2019 CG-LAB
5/34
5
+include,dos.h-
+include,math.h-
+include,graphics.h-
!oid main/
0
float %&&%'&'&%2&2&d%&d&e1
int i&gdDETECT&gm1
clrscr/1
printf34n E5TE6 T7E 8ALUE 9: ;'*3/1
scanf3
-
7/23/2019 CG-LAB
6/34
6
getch/1
OUTUT:
E5TE6 T7E 8ALUE 9: ;' * @@
E5TE6 T7E 8ALUE 9: >' * @@
E5TE6 T7E 8ALUE 9: ;2 A5D >2 * @@ @@
!IR!LE DRAWING USING BRESENHAM ALGORITHM
E". N# : 1B
D$te :
AIM:
-
7/23/2019 CG-LAB
7/34
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 circlefunint %center& int center&int %&int /1
!oid main/
0
int %@&radius&%center¢er1
int &p&gdDETECT&gm1
clrscr/1
initgraph=gd&=gm&3 3/1
printf34n E5TE6 T7E ;CE5TE6 =>CE5TE6*3/1
scanf3
-
7/23/2019 CG-LAB
8/34
8
while%,/
0
ifp,@/
%%'1
else
0
%%'1
)'1
ifp,@/
pp2?%'1
else
pp2?%)/'1
circlefun%center¢er&%&/1
getch/1
!oid circlefunint %center&int center&int %&int /
0
putpi%el%center%¢er&'/1
putpi%el%center)%¢er&'/1
putpi%el%center%¢er)&'/1
putpi%el%center)%¢er)&'/1
putpi%el%center¢er%&'/1
putpi%el%center)¢er%&'/1
putpi%el%center¢er)%&'/1
putpi%el%center)¢er)%&'/1
OUTUT:
E5TE6 T7E ; CE5TE6 A5D > CE5TE6 * (@@ 2(@
-
7/23/2019 CG-LAB
9/34
9
E5TE6 T7E 6AD#US * I@
RESULT:
Thus the a"o!e program JC#6CLE D6AW#5K US#5K B6EASE57AM 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.
-
7/23/2019 CG-LAB
10/34
10
ALGORITHM:
Step '* Start the program.
Step 2* #nitiali$e the !aria"les.
Step * Call the initgraph/ function.
Step * Ket the initiali$e points H'&H2.
Step (* Ket the !alues of Co)9rdinates of the ellipse %&/.
Step * 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 gdDETECT&gm1
int a&"1
float p'&p21
clrscr/1
initgraph=gd&=gm&33/1
scanf3
-
7/23/2019 CG-LAB
11/34
11
ifp',@/
p'p'2.@?"?"?%/"?"/1
else
0
))1
p'p'2.@?"?"?%/"?"/)2.@?a?a?/1
disp/1
%)%1
disp/1
%)%1
%a1
@1
disp/1
p2a?a/2.@?"?"?a/"?"/O1
while2.@?"?"?%/-2.@?a?a?//
0
1
ifp2-@/
p2p2a?a/)2.@?a?a?/1
else
0
%))1
p2p22.@?"?"?%/)2.@?a?a?/a?a/1
disp/1
)1
disp/1
)1
getch/1
closegraph/1
!oid disp/
-
7/23/2019 CG-LAB
12/34
12
0
putpi%el%c%&c&'@/1
putpi%el%c)%&c&'@/1
putpi%el%c%&c)&'@/1
putpi%el%c%&c)&'@/1
INUT
Ellipse Drawing Algorithm
E'te( t)e *#+#(,-'$te
;c 2@@
>c 2@@
A '@@
B I@
OUTUT
Re/0t:
http://studentwebsite.blogspot.com/2009/10/ellipse-drawing-algorithm-in-c-program.htmlhttp://4.bp.blogspot.com/_Gmn-kEVg3hk/SciNd6U29yI/AAAAAAAAAYk/g20WQMLr8rg/s1600-h/Graphics+and+multimedia+Lab+Bresenhams++Ellipse+Drawing+Algorithm+c+program.JPGhttp://studentwebsite.blogspot.com/2009/10/ellipse-drawing-algorithm-in-c-program.html -
7/23/2019 CG-LAB
13/34
13
Thus using C program implementation of BresenhamPs algorithm for line& circle and
ellipse drawing is done.
TWO DIMENSIONAL TRANSORMATIONS
-
7/23/2019 CG-LAB
14/34
Ex. No. : 3Date :
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 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
-
7/23/2019 CG-LAB
15/34
15
int %&&c1
float a1
int gdDETECT&gm1
initgraph=gd&=gm&3 3/1
do
0
clearde!ice/1
printf3'.T6A5SLAT#95 2.SCAL#5K .69TAT#95
.E;#T3/1
printf34n E5TE6 >6 C79#CE*3/1
scanf3 8ALUE*3/1
scanf3
8ALUE*3/1
scanf3
-
7/23/2019 CG-LAB
16/34
16
printf34n E5TE6 T7E A5KLE13/1
scanf3
-
7/23/2019 CG-LAB
17/34
17
OUTUT:
'.T6A5SLAT#95 2. SCAL#5K . 69TAT#95 . E;#T
E5TE6 >9U6 9HT#95 * '
E5TE6 T7E T; A5D T> 8ALUE * '(@ '(@
96#K#5AL 9BECT T6A5SLAT#95 9BECT
'. T6A5SLAT#95 2.SCAL#5K . 69TAT#95 . E;#T
E5TE6 >9U6 9HT#95 * 2
E5TE6 >9U6 S; A5D S> 8ALUE * 2 2
'. T6A5SLAT#95 2.SCAL#5K . 69TAT#95 . E;#T
E5TE6 >9U6 9HT#95 *
E5TE6 T7E ; A5D > 8ALUE *'@@ '@@
E5TE6 T7E A5KLE *V@
C9U5TE6 CL9CW#SE
69TAT#95
96#K#5AL 9BECT CL9CW#SE 69TAT#95
-
7/23/2019 CG-LAB
18/34
18
RESULT:
Thus the a"o!e programMTW9 D#E5S#95AL
T6A5S:96AT#95SM #s e%ecuted successfull.
!OHEN SUTHERLAND 2D LINE !LIING AND WINDOWINGE". N# : 5
-
7/23/2019 CG-LAB
19/34
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
codefloat &float/1
!oid clipfloat &float&float&float/1
!oid rectfloat &float&float&float/1main/
0
float %'&'&%2&21
int g@&d1
initgraph=g&=d&3c*44tc44"in3/1
sette%tstle'&@&'/1
outte%t%@&'(&3BE:96E CL#HH#5K3/1
printf34n Hlease Enter Left&Bottom&6ight&Top 9f Clip Window3/1
scanf3
-
7/23/2019 CG-LAB
20/34
20
sette%tstle'&@&'/1
outte%t%@&'(&3A:TE6 CL#HH#5K3/1
clip%'&'&%2&2/1
getch/1
closegraph/1
!oid clipfloat %'&float '&float %2&float 2/
0
int c&c'&c21
float %&1
c'code%'&'/1
c2code%2&2/1
getch/1
whilec'@/c2@//
0
ifc'=c2/@/
goto out1
cc'1
ifc@/
cc21
ifc='/'/
0
'2)'/?c%l)%'/1
%c%l1
else
ifc=2/2/
0
'2)'/?c%l)%'/O%2)%'/1
%c%r1
-
7/23/2019 CG-LAB
21/34
21
else
ifc=N/N/
0
%%'%2)%'/?c")'/O2)'/1
c"1
else
ifc=//
0
%%'%2)%'/?ct)'/O2)'/1
ct1
ifcc'/
0
%'%1
'1
c'code%&/1
else
0
%2%1
21
c2code%&/1
out*
rectc%l&c"&c%r&ct/1
line%'&'&%2&2/1
codefloat % &float /
0
int c@1if%,c%l/ c'1
-
7/23/2019 CG-LAB
22/34
22
else
if%-c%r/ c21
else
if,c"/ ccN1
else
if-ct/ cc1
return c1
!oid rectfloat %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
OUTUT
SAMLE INUT:
Hlease Enter Left & Bottom & 6ight & Top 9f The Clip window
2@@
2@@
@@
@@
Hlease Enter The Line Coordinates ;'& >'& ;2& >2/
'(@
@@@@
-
7/23/2019 CG-LAB
23/34
23
(@
SAMLE OUTUT:
BE:96E CL#HH#5K
A#T$% C&'((')*+
W-',#-' T# -ep#(t M$pp-'
-
7/23/2019 CG-LAB
24/34
24
+include,stdio.h-
+include,conio.h-
+include,graphics.h-
+include,math.h-
main/
0
float s%&s1
int w'&w2&w&w&%'&%2&%&%&'&2&&&!'&!2&!&!1
int gdDETECT&gm1
initgraph=gd&=gm&3c*44tc44"gi3/1
printf3Enter The Coordinate %'&'&%2&2&%&4n3/1
scanf3
-
7/23/2019 CG-LAB
25/34
25
!2floorfloat/)w2/?s/.(/1
line%'&'&%2&2/1
line%2&2&%&/1
line%&&%'&'/1
getch/1
return @1
SAMLE INUT:
Enter The Coordinate %'&'&%2&2&%&
'@@
2@@
@@
@@
(@@
(@
SAMLE OUTUT:
-
7/23/2019 CG-LAB
26/34
26
%esult +
-
7/23/2019 CG-LAB
27/34
Ex. No. : 07Date :
27
TRANSLATION AND S!ALING USING 3D
AIM:
To write a C program for Translation and Scaling Using D ethod.
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.
-
7/23/2019 CG-LAB
28/34
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 drawfloat %XY&float XY/1
!oid get/1
!oid main/
0
int gdDETECT&gm&i&ch1
initgraph=gd&=gm&3 3/1
get/1
do
0
clearde!ice/1
draw%&/1
printf34n '.T6A5SLAT#95 2.SCAL#5K .E;#T3/1
printf34n E5TE6 U6 C79#CE*3/1
scanf3
-
7/23/2019 CG-LAB
29/34
29
case 2*
scaling/1
"reaF1
case *
closegraph/1
e%it@/1
getch/1
whilech/1
!oid get/
0
int i1
printf34n E5TE6 T7E 59.9: S#DES= DEHT7 9: T7E
H9L>K95*3/1
scanf3
-
7/23/2019 CG-LAB
30/34
30
!oid translation/
0
int i&ch1
float t%&t1
draw%&/1
printf3E5TE6 T7E T6A5SLAT#95:ACT96 T; =T>
8ALUE*3/1
scanf3
-
7/23/2019 CG-LAB
31/34
31
OUTUT:
E5TE6 T7E 59 9: S#DES = DEHT7 9: T7E H9L>K95 * '@
E5TE6 T7E C9)96D#5ATES *
E5TE6 T7E ;' A5D >' 8ALUES * 2@@ '@
E5TE6 T7E ;2 A5D >2 8ALUES * 2(@ '@
E5TE6 T7E ; A5D > 8ALUES * 2(@ @
E5TE6 T7E ; A5D > 8ALUES * 2@@ @
'. T6A5SLAT#95 2. SCAL#5K . E;#T
E5TE6 >9U6 C79#CE * '
E5TE6 T7E T6A5SLAT#95 :ACT96S T; A5D T> 8ALUES * '@@ @
'. T6A5SLAT#95 2. SCAL#5K . E;#T
E5TE6 >9U6 C79#CE * 2
E5TE6 T7E SCAL#5K :ACT96S S; A5D S> 8ALUES * 2 2
-
7/23/2019 CG-LAB
32/34
32
RESULT:
Thus the a,o"e proram T%A)&AT'.) A)/CA&')* ')* 3/ 's eecuted successull
-
7/23/2019 CG-LAB
33/34
33
-
7/23/2019 CG-LAB
34/34
34