Вы находитесь на странице: 1из 94

EX.NO:1(a) DATE: 09.07.

2013

BRESENHAMS LINE

AIM:
To write a C Program to draw a line using Bresenhams algorithm.

FUNCTIONS USED:
1. detectgra h(!gd"!gm)# determine gra hics dri$er and mode to use %& chec'ing the hardware. gra hdri$er is an integer that s eci(ies the gra hics dri$er to %e used. gra hmode s eci(ies the initial gra hics mode.

2. initgra h (!gd"!gm")c*++tcc++%gi))# initiali,es the gra hics s&stem %& loading a gra hics dri$er (rom dis' then utting the s&stem into gra hics mode.

3.

ut i-el (-"&"1.)# lots a i-el at s eci(ied oint. /t also lots a oint in the color de(ined %& color at (-"&). /t doesnt return an&thing.

0. dela& (100)# with call to dela& "the current rogram is sus ended (rom e-ecution (or the time s eci(ied %& the arguments in milliseconds.

.. closegra h()# shuts down the gra hics s&stem. /t also deallocates all the memor& allocated %& the gra hics s&stem. /t then restores the screen to the mode it was in %e(ore &ou called initgra h.

ALGORITHM:
1. 2. 3. 0. .. 3. 7. 5. 1tart the rogram. /nitiali,e the $aria%les. Call the initgra h() (unction 2et the $alues (or le(t and right end oints (or drawing a line.. Calculate the distance to %e tra$eled %& the line. Put the i-els in the gi$en color to draw the line. 4is la& the out ut. 1to the rogram.

PROGRAM:
6include7stdio.h8 6include7conio.h8 6include7gra hics.h8 6include7math.h8 $oid main() 9 int gd"gm"i: (loat -"&"-1"&1"-2"&2"d-"d&"e: clrscr(): rint((;<nter the $alues o( -1"&1;): scan((;=(=(;"!-1"!&1): rint((;<nter the $alues o( -2"&2;): scan((;=(=(;"!-2"!&2): detectgra h(!gd"!gm): initgra h(!gd"!gm";c*++tcc++%gi;): d->a%s(-2#-1): d&>a%s(&2#&1): ->-1: &>&1: e>2?d&#d-: i>1: do 9

dela&(100): ut i-el(-"&"1.): while(e8>0) 9 &>&@1: e>e#2?d&: A ->-@1: e>e@2?d&: i>i@1: A while(i7>d-): getch(): closegra h(): A

OUTPUT:
<nter the $alues o( -1 and &1* 100 200

RESULT:
Thus the C rogram (or Bresenhams line had %een success(ull& e-ecuted and the out ut was $eri(ied.

EX.NO:1(%) DATE: 09.07.2013

BRESENHAM CIRCLE

AIM:
To write a C Program to draw a line using Bresenhams algorithm.

FUNCTIONS USED:
1. detectgra h(!gd"!gm)# determine gra hics dri$er and mode to use %& chec'ing the hardware. gra hdri$er is an integer that s eci(ies the gra hics dri$er to %e used. gra hmode s eci(ies the initial gra hics mode.

2. initgra h (!gd"!gm")c*++tcc++%gi))# initiali,es the gra hics s&stem %& loading a gra hics dri$er (rom dis' then utting the s&stem into gra hics mode.

3.

ut i-el (-"&"1.)# lots a i-el at s eci(ied oint. /t also lots a oint in the color de(ined %& color at (-"&). /t doesnt return an&thing.

0. dela& (100)# with call to dela& "the current rogram is sus ended (rom e-ecution (or the time s eci(ied %& the arguments in milliseconds.

.. closegra h()# shuts down the gra hics s&stem. /t also deallocates all the memor& allocated %& the gra hics s&stem. /t then restores the screen to the mode it was in %e(ore &ou called initgra h.

ALGORITHM:
1. 1tart the rogram . 2. /nitiali,e the $aria%les. 3. Call the initgra h() (unction

0. .. 3. 7. 5.

2et the $alues (or le(t and right end oints (or drawing a line.. Calculate the distance to %e tra$eled %& the line. Put the i-els in the gi$en color to draw the line. 4is la& the out ut. 1to the rogram

PROGRAM:
6include7stdio.h8 6include7conio.h8 6include7math.h8 6include7gra hics.h8 $oid main() 9 int gd"gm"-"&"r: (loat d: rint((;+n enter the radius o( the circle;): scan((;=d;"!r): detectgra h(!gd"!gm): initgra h(!gd"!gm";c*++tcc++%gi;): ->0:&>r: d>3#2?r: do 9 ut i-el(200@-"200@&"1.): ut i-el(200@&"200@-"1.): ut i-el(200@&"200#-"1.): ut i-el(200@-"200#&"1.):

ut i-el(200#-"200#&"1.): ut i-el(200#&"200#-"1.): ut i-el(200#&"200@-"1.): ut i-el(200#-"200@&"1.): i((d7>0) 9 d>d@0?-@3: A else 9 d@>0?(-#&)@10: &>&#1: A ->-@1: dela&(100): A while(-7&): getch(): closegra h(): A

OUTPUT:
<nter the radius o( the circle*00

RESULT:
Thus the C rogram (or Bresenhams circle had %een success(ull& e-ecuted and the out ut was $eri(ied.

EX.NO:1(c) DATE: 13.07.2013

BRESENHAM ELLIPSE

AIM:
To write a C rogram to demonstrate Bresenhams <lli se Blgorithm.

ALGORITHM:
1. /nitiali,e the $aria%les i"gd"gm"-"&"r-"r&"r&sC"r-sC"twor-sC"twor&sC"d-"d&. <nter the - and & radius. 2. Calculate r-sC>r-?r-" r&sC>r&?r&" twor-sC>2?r-sC"twor&sC>2?r&sC" r&sC# sC?r&@(0.2.?r-sC)" d->twor&sC?-" d&>twor-sC. 3. Dse do while loo to calculate the i-els oints. 0. Chec' i( (d170) is true then ->-@1"&>&" d->d-@twor&sC" d1>d1@d-@r&sC. Etherwise ->-@1" &>&#1" d->d-@twor&sC" d&>d&#twor-sC. .. Calculate d2>r&sC?(-@0..)?(-@0..)@r-sC?(&#1)?(&#1)?r-sC?r&sC. 3. /( (d280) is true then ->-" &>&#1" d&>d&#twor-sC" d2>d2#d&@r-sC. Etherwise ->-@1" &>&#1" d&>d&#twor-sC" d->d-#twor&sC" d2>d2@d-@r-sC#d&. 7. Thus the rogram is terminated and the gra h is generated.

FUNCTIONS USED:
1. detectgra h(!gd"!gm)# determine gra hics dri$er and mode to use %& chec'ing the hardware. gra hdri$er is an integer that s eci(ies the gra hics dri$er to %e used. gra hmode s eci(ies the initial gra hics mode.

2. initgra h (!gd"!gm")c*++tcc++%gi))# initiali,es the gra hics s&stem %& loading a gra hics dri$er (rom dis' then utting the s&stem into gra hics mode.

3.

ut i-el (-"&"1.)# lots a i-el at s eci(ied oint. /t also lots a oint in the color de(ined %& color at (-"&). /t doesnt return an&thing.

0. dela& (100)# with call to dela& "the current rogram is sus ended (rom e-ecution (or the time s eci(ied %& the arguments in milliseconds.

.. closegra h()# shuts down the gra hics s&stem. /t also deallocates all the memor& allocated %& the gra hics s&stem. /t then restores the screen to the mode it was in %e(ore &ou called initgra h.

PROGRAM:
6include7stdio.h8 6include7gra hics.h8 6include7math.h8 $oid main() 9 long d1"d2: int i"gd"gm"-"&: long r-"r&"r-sC"r&sC"twor-sC"twor&sC"d-"d&: rint((;<nter the - radius o( elli se*;): scan((;=ld;"!r-): rint((;<nter the & radius o( the elli se*;): scan((;=ld;"!r&): detectgra h(!gd"!gm):

initgra h(!gd"!gm";c*++tcc++%gi;): r-sC>r-?r-: r&sC>r&?r&: twor-sC>2?r-sC: twor&sC>2?r&sC: ->0: &>r&: d1>r&sC#r-sC?r&@(.2.?r-sC): d->twor&sC?-: d&>twor-sC?&: do 9 ut i-el(200@-"200@&"1.): ut i-el(200#-"200#&"1.): ut i-el(200@-"200#&"1.): ut i-el(200#-"200@&"1.): i((d170) 9 ->-@1: &>&: d->d-@twor&sC: d1>d1@d-@r&sC: A else 9 ->-@1: &>&#1: d->d-@twor&sC:

d&>d&#twor-sC: d1>d1@d-#d&@r&sC: A dela&(100): .

A while(d-7d&) :

d2>r&sC?(-@0..)?(-@0..)@r-sC?(&#1)?(&#1)#r-sC?r&sC: do 9 ut i-el(200@-"200@&"1.): ut i-el(200#-"200#&"1.): ut i-el(200@-"200#&"1.): ut i-el(200#-"200@&"1.): i((d280) 9 ->-: &>&#1: d&>d&#twor-sC: d2>d2#d&@r-sC: A else 9 ->-@1: &>&#1: d&>d&#twor-sC: d->d-#twor&sC: d2>d2@d-#d&@r-sC:

A A while(&80): getch(): closegra h(): A

OUTPUT:
<nter the - radius o( elli se*2. <nter the & radius o( elli se*.0

RESULT:
Thus the C rogram (or Bresenhams <lli se had %een success(ull& e-ecuted and the out ut was $eri(ied.

EX.NO:2 DATE:23.07.2013

2D TRANSFORMATION

AIM:
To write a C Program to im lement 24 trans(ormations.

FUNCTIONS USED: 1. Foid (ill ol&(int num oints"int ? ol& oints)# Gill ol& draws the outline o( a ol&gon
using the current line st&le and color "then (ills the ol&gon using the current (ill attern and (ill color.

2. detectgra h(!gd"!gm)# determine gra hics dri$er and mode to use %& chec'ing the
hardware. gra hdri$er is an integer that s eci(ies the gra hics dri$er to %e used. gra hmode s eci(ies the initial gra hics mode.

3. initgra h (!gd"!gm")c*++tcc++%gi))# initiali,es the gra hics s&stem %& loading a gra hics
dri$er (rom dis' then utting the s&stem into gra hics mode.

0. clearde$ice()# clears the gra hics s&stem. 4eclaration*$oid (ar clearde$ice($oid): ALGORITHM:
1. 1tart the rogram . 2. <nter the choice (or trans(ormation. 3. Per(orm the translation" rotation" scaling" re(lection and shearing o( 24 o%Hect. 4. 2et the needed arameters (or the trans(ormation (rom the user. 5. /ncase o( rotation" o%Hect can %e rotated a%out - or & a-is. 6. 4is la& the transmitted o%Hect in the screen 7. 1to the rogram

PROGRAM:
6include7stdio.h8 6include7conio.h8 6include7math.h8 6include7gra hics.h8 int m"angle"t-"t&"edges"i"H"o t" I2.J"t: (loat s-"s&"sh: int gd>4<T<CT"gm: $oid rotation($oid): $oid scaling($oid): $oid translation($oid): $oid re(lection($oid): $oid shear($oid):

int menu(): $oid main() 9 initgra h(!gd"!gm";c*++tcc++%gi;): clearde$ice(): while(1) 9 rint((;<nter the menu o tion;): rint((;+n1.Translation+n2.1caling+n3.Kotation+n0.Ke(lection+n..1hear+n3.<-it;): rint((;+n<nter &our o tions+n;): scan((;=d;"!o t): switch(o t) 9 case 1* translation(): %rea': case 2* scaling(): %rea': case 3* rotation(): %rea': case 0* re(lection(): %rea': case .* shear(): %rea':

case 3* e-it(0): %rea': A getch(): A A $oid translation() 9 rint((;+n<nter the num%er o( edges*+n;): scan((;=d;"!edges): rint((;+n<nter the translation (actors*+n;): scan((;=d=d;"!t-"!t&): rint((;+n<nter the $ertices;): (or(i>0:i72?edges:i@@) 9 rint((;+n<nter =d co#ordinate+n;"i): scan((;=d;"! IiJ): A rint((;+nThe ol&gon %e(ore translation+n;): (or(i>0"H>0:i72?edges:i@>2"H@>2) 9 IiJ> IiJ@t-: IHJ> IHJ@t&: A (ill ol&(edges" ): getch(): clearde$ice():

rint((;+nThe ol&gon a(ter translation+n;): (or(i>0"H>0:i72?edges:i@>2"H@>2) 9 IiJ> IiJ@t-: IHJ> IHJ@t&: A (ill ol&(edges" ): getch(): A $oid scaling() 9 rint((;+n<nter the num%er o( edges*+n;): scan((;=d;"!edges): rint((;+n<nter the scaling (actors s-"s&+n*;): scan((;=(=(;"!s-"!s&): rint((;+n<nter the $ertices;): (or(i>0:i72?edges:i@@) 9 rint((;+n<nter =d co#ordinate+n;"i): scan((;=d;"! IiJ): A rint((;+nThe ol&gon %e(ore scaling+n;): clearde$ice(): (ill ol&(edges" ): getch(): clearde$ice(): rint((;+nThe ol&gon a(ter scaling+n;): (or(i>0:i72?edges:i@>2)

9 IiJ> IiJ@s-: A (or(H>1:H72?edges:H@>2) 9 IHJ> IHJ?s&: A (ill ol&(edges" ): getch(): A $oid rotation() 9 (loat ang: rint((;+n<nter the num%er o( edges*+n;): scan((;=d;"!edges): rint((;+n<nter the angle*+n;): scan((;=d=d;"!angle): ang>angle?3.10L150.0: rint((;+n<nter the $ectices;): (or(i>0:i72?edges:i@@) 9 rint((;+n<nter =d co#ordinate+n;"i): scan((;=d;"! IiJ): A rint((;+nThe ol&gon %e(ore rotation+n;): clearde$ice(): (ill ol&(edges" ): getch():

clearde$ice(): rint((;+nThe ol&gon a(ter rotation+n;): (or(i>0:i72?edges:i@>2) 9 IiJ>(int)( IiJ?cos(ang)# IHJ?sin(ang)): A (or(m>0"H>0:m72?edges"H72?edges:m@>2"H@>2) 9 IHJ>(int)( IHJ?cos(ang)@ IHJ?sin(ang)): A (ill ol&(edges" ): getch(): A $oid re(lection() 9 rint((;+n<nter the num%er o( edges*+n;): scan((;=d;"!edges): rint((;+n<nter the $ertices;): (or(i>0:i72?edges:i@@) 9 rint((;+n<nter =d co#ordinate+n;"i): scan((;=d;"! IiJ): A rint((;+nThe ol&gon %e(ore re(lection+n;): clearde$ice(): (ill ol&(edges" ): getch(): clearde$ice():

rint((;+nThe ol&gon a(ter re(lection+n;): (or(i>0"H>1:i72?edges"H72?edges:i@>2"H@>2) 9 t> IHJ: IiJ> IHJ: IHJ>t: A (ill ol&(edges" ): getch(): A $oid shear() 9 rint((;+n<nter the num%er o( edges*+n;): scan((;=d;"!edges): rint((;+n<nter the shear $alue*+n;): scan((;=(;"!sh): rint((;+n<nter the $ertices;): (or(i>0:i72?edges:i@@) 9 rint((;+n<nter =d co#ordinate+n;"i): scan((;=d;"! IiJ): A rint((;+nThe ol&gon %e(ore shearing+n;): clearde$ice(): (ill ol&(edges" ): getch(): clearde$ice(): rint((;+nThe ol&gon a(ter shearing+n;):

(or(i>0"H>0:i72?edges"H72?edges:i@>2"H@>2) 9 IiJ> IiJ@(sh@ IHJ): A (or(H>1:H72?edges:H@>2) 9 IHJ> IHJ: A (ill ol&(edges" ): getch(): A

OUTPUT:
<MT<K N<MD EPT/EM 1.TKBM1OBT/EM 2.1CBO/M2 3.KETBT/EM 0.K<GO<CT/EM ..1P<BK 3.<Q/T <MT<K REDK EPT/EM*1 <nter no o( edges*3 <nter translation (actors*.0 .0 <nter the $ertices

<nter 0 coordinate*0. <nter 1 coordinate*.3 <nter 2 coordinate*37 <nter 3 coordinate*75 <nter 0 coordinate*59 <nter . coordinate*30

The ol&gon %e(ore translation

The ol&gon a(ter translation

<nter &our o tion*2 <nter no o( edges*2 <nter the scaling (actors*2 3 <nter 0 coordinate*0. <nter 1 coordinate*.3 <nter 2 coordinate*37 <nter 3 coordinate*7. <nter 0 coordinate*5. <nter . coordinate*33 The ol&gon %e(ore scaling The ol&gon a(ter scaling

<nter &our o tion*3 <nter num%er o( edges*3 <nter the angle*0. <nter 0 coordinate*0. <nter 1 coordinate*.3 <nter 2 coordinate*37 <nter 3 coordinate*7. <nter 0 coordinate*5. <nter . coordinate*33

Be(ore rotation

B(ter rotation

<nter &our o tion *0 <nter the num%er o( edges*3 <nter 0 coordinate*0. <nter 1 coordinate*.3 <nter 2 coordinate*37 <nter 3 coordinate*7. <nter 0 coordinate*5. <nter . coordinate*33 Be(ore re(lection B(ter re(lection

<nter &our o tion*. <nter the num%er o( edges 3 <nter shear $alue*. <nter 0 coordinate*0. <nter 1 coordinate*.3 <nter 2 coordinate*37 <nter 3 coordinate*7. <nter 0 coordinate*5. <nter . coordinate*33

Be(ore shearing

B(ter shearing

RESULT:
Thus the C rogram (or 24 Basic Trans(ormation had %een success(ull& e-ecuted and the out ut was $eri(ied.

EX.NO:3 DATE:13.05.2013

2D COMPOSITE TRANSFORMATION

AIM:
To write a C rogram to demonstrate 24 com osite Trans(ormation.

FUNCTIONS USED:
1. Foid initgra h(int ?gra hdri$er"int ?gra hmode"char ? ath to dri$er)# initgra h() (unction used to initiali,e the gra hics s&stem. To start the gra hics s&stem"&ou must (irst call initgra h. /nitgra h initiali,es the gra hics s&stem %& loading a gra hics dri$er (rom dis'(or $alidating a registered dri$er) then utting the s&stem into gra hics mode.

2. Foid set%'color(int color)# set%'color() (unction used to sets the current %ac'ground color using the alette. 1et%'color sets the %ac'ground to the color s eci(ied %& color. This is %ecause the color arameter to set%'color indicates the entr& num%er in the current alette"rather than a s eci(ied color. 3. Foid (ill ol&(int num oints"int ? ol& oints)# Gill ol& draws the outline o( a ol&gon using the current line st&le and color "then (ills the ol&gon using the current (ill attern and (ill color.

0. Foid setcolor(int color)# 1etcolor sets the current drawing color to color"which can range 0 to getma-color.

ALGORITHM:
1. 1tart the rogram . 2. Bssign in ut $alues -"&"i"H and matri-I3JI3J are declared to %o entered in rogram. 3. Create m remul() (unction and assign columns and rows using (or loo (or(r>0:r73:r@@) (or(c>0:c73:c@@) 0. Create translate() (unction with in uts t- and t&. .. Create sale() (unction with $alues s-"s& and re( t are declared. 3. Create rotate() (unction with in uts a and re( t to generate the matri- $alues. m remul(m"tm): 7. The trans(ormation() (unction can %e created and declared. 5. The com osite trans(ormation (unction scaling" rotation and translation can %e done. 9. 1to the rogram

PROGRAM:
6include7math.h8 6include7gra hics.h8 6include7dos.h8 6include7conio.h8 6include7stdio.h8 t& ede( (loat matri-I3JI3J: t& ede( struct9(loat -"&:Awe t: matri- tm: $oid midentit&(matri- m) 9 int i"H: (or(i>0:i73:i@@)

(or(H>0:H73:H@@) mIiJIHJ>(i>>H): A $oid m remul(matri- a"matri- %) 9 int r"c: matri- tem : (or(r>0:r73:r@@) (or(c>0:c73:c@@) tem IrJIcJ>aIrJI0J?%I0JIcJ@aIrJI1J?%I1JIcJ@aIrJI2J?%I2JIcJ: (or(r>0:r73:r@@) (or(c>0:c73:c@@) %IrJIcJ>tem IrJIcJ: A $oid translate(int t-"int t&) 9 matri- m: midentit&(m): mI0JI2J>t-: mI1JI2J>t&: m remul(m"tm): A $oid scale((loat s-"(loat s&"we t re( t) 9 matri- m: midentit&(m): mI0JI0J>s-: mI0JI2J>(1#s-)?re( t.-: mI1JI1J>s&:

mI1JI2J>(1#s&)?re( t.&: m remul(m"tm): A $oid rotate((loat a"we t re( t) 9 matri- m: a>a@3.10L150: mI0JI0J>cos(a): mI0JI1J>#sin(a): mI0JI2J>re( t.-?(1#cos(a))@re( t.&?sin(a): mI1JI0J>sin(a): mI1JI1J>cos(a): mI1JI2J>re( t.&?(1#cos(a))#re( t.-?sin(a): m remul(m"tm): A $oid trans(orm oints(int n ts"we t ? ts) 9 int ': (loat tem : (or('>0:'7n ts:'@@) 9 tem >tmI0JI0J? tsI'J.-@tmI0JI1J? tsI'J.&@tmI0JI2J: tsI'J.&>tmI1JI0J? tsI'J.-@tmI1JI1J? tsI'J.&@tmI1JI2J: tsI'J.->tem : A A $oid tsto ts(we t ? ts"int t tsI3J) 9

int i"H>0: trans(orm oints(3" ts): (or(i>0:i73:i@@) 9 t tsIHJ> tsIiJ.-: t tsIH@1J> tsIiJ.&: H>H@2: A (ill ol&(3"t ts): A $oid main() 9 we t tsI3J>9.0.0".0.0"1.0.0".0.0"100.0"1.0.0A: int t tsI3J>9.0.0".0.0"1.0.0".0.0"100.0"1.0.0A: we t re( t>9100.0"100.0A: int gd>4<T<CT"gm"i"H: initgra h(!gd"!gm";c*LtcL%gi;): set%'color(SP/T<): setcolor(BOD<): (ill ol&(3"t ts): midentit&(tm): slee (3): scale(0.."0.."re( t): tsto ts( ts"t ts): outte-t-&(.0"130";a(ter scaling;): slee (3): midentit&(tm): slee (2): rotate(90.0"re( t): tsto ts( ts"t ts):

outte-t-&(1.0"100";a(ter rotation;): slee (2): midentit&(tm): translate(0"1.0): tsto ts( ts"t ts): outte-t-&(.0"250";a(ter translation;): getch(): A

OUTPUT:

B(ter rotation

B(ter scaling

B(ter translation

RESULT:
Thus the C rogram (or 24 Com osite Trans(ormations had %een success(ull& e-ecuted and the out ut was $eri(ied.

EX.NO:0 DATE:13.05.2013

2D LINE CLIPPING AND WINDOWING

AIM:
To write a C rogram to demonstrate 2d line cli ing and windowing using Cohen# 1utherland algorithm.

FUNCTIONS USED:
1. initgra h()* initiali,es the gra hics s&stem. 4eclaration*$oid (ar initgra h(int (ar ?gra hdri$er"int (ar ?gra hmode"char (ar ? athtodri$er) 2. rectangle()*draws a rectangle in current linest&le"thic'ness"drawing color. 4eclaration*$oid (ar rectangle(int le(t"int to "int right"int %ottom) 3. line()*draws line %etween two s eci(ied oints (rom (-1"&1) to (-2"&2).4eclaration*$oid (ar line(int -1"int &1"int -2"int &2) 0. setcolor()*sets current drawing color to color which range (rom 0 to getma-color. 4eclaration* $oid (ar setcolor(int color): .. outte-t-&()*dis la&s a string at s eci(ied location. 4eclaration*$oid (ar outte-t-&(int -"int &"char (ar ?te-tstring): 3. clearde$ice()*clears the gra hics s&stem. 4eclaration*$oid (ar clearde$ice($oid):

7. closegra h()*shuts down the gra hics s&stem. 4eclaration*$oid (ar closegra h($oid):

ALGORITHM:
1 .in ut the line coordinates(-1"&1)and(-2"&2). 2. /n ut the window coordinates (-min"&min) and (-ma-"&ma-). 3. 4raw the window using rectangle (unction and line using line (unction. 0. Gind region code and draw line (or two line end oints. .. Based on region code draw line at le(t or right or to or %ottom. 3. i( region codes are not 0000 then (ind their intersection oints on the %oundar& edges o( cli ing window with res ect to original oints. 7. Calculate the slo e $alue (or - & $alues. 5. Call the line and rectangle (unction to dis la& the line a(ter cli ing. 9. /n ut the $iew ort coordinates (-umin"&umin)and(-uma-"&uma-). 10. Dsing rectangle (unction dis la&s the window to $iew ort trans(ormation.

PROGRAM:
6include7stdio.h8 6include7conio.h8 6include7stdli%.h8 6include7math.h8 6include7gra hics.h8 (loat -wma-"-wmin"&wma-"&wmin: (loat -1"&1"-2"&2"-3"&3"-0"&0"a"%"-min"&min"&ma-"-ma-" "C: int i"H"'"codeI10J: $oid reHection((loat"(loat): $oid rcode((loat"(loat"int cI10J): $oid main() 9 int gd>4<T<CT"gm: initgra h(!gd"!gm";c*++tcc++%gi;): rint((;+n <nter the line co#ordinate;):

scan((;=(=(=(=(;"!-1"!&1"!-2"!&2): rint((;+n <nter the window CoTordinate;): scan((;=(=(=(=(;"!-min"!&min"!-ma-"!&ma-): clearde$ice(): rint((;%e(ore cli ing in window;): rectangle(-min"&min"-ma-"&ma-): line(-1"&1"-2"&2): getch(): clearde$ice(): line(-1"&1"-2"&2): rectangle(-min"&min"-ma-"&ma-): getch(): clearde$ice(): while(1) 9 H>1: rcode(-1"&1"code): H>.: rcode(-2"&2"code): (or('>1:'7>0:'@@) 9 i(((codeI'J>>1)!!(codeI'@0J>>1)) rectangle(-min"&min"-ma-"&ma-): i(((codeI'J>>0)!!(codeI'@0J>>0)) 9 i(('8>3) goto ch: A

i((codeI'JU>1) 9 i((codeI'@0J>>1) 9 reHection(-2"&2): -2>a: &2>%: H>0: rcode(-2"&2"code): A A else 9 reHection(-1"&1): -1>a: &1>%:H>1: rcode(-1"&1"code): A A A ch* rint((;+n line a(ter cli ing the window;): setcolor(12): line(-1"&1"-2"&2): setcolor(3): rectangle(-min"&min"-ma-"&ma-): getch(): clearde$ice():

outte-t-&(200"100";window to $iew ort trans(ormation;): outte-t-&(200"100";$iew ort;): rint((;+n <nter the $iew ort coTordinate;): scan((;=(=(=(=(;"!-umin"!&umin"!-uma-"!&uma-): -3>-umin@(-1#-min)?((-uma-#-umin)L(-ma-#-min)): &3>&umin@(&1#&min)?((&uma-#&umin)L(&ma-#&min)): -0>-umin@(-2#-min)?((-uma-#-umin)L(-ma-#-min)): &0>&umin@(&2#&min)?((&uma-#&umin)L(&ma-#&min)): clearde$ice(): outte-t-&(200"100";window to $iew ort trans(orm;): setcolor(12): rectangle(-umin"&umin"-uma-"&uma-): line(-3"&3"-0"&0): getch(): clearde$ice(): closegra h(): A $oid rcode((loat -"(loat &"int cI10J) 9 i((-7-min) cIHJ>1: else cIHJ>0: H@@: i((-8-ma-) cIHJ>1: else cIHJ>0:

H@@: i((&7&min) cIHJ>1: else cIHJ>0: H@@: i((&8&ma-) cIHJ>1: else cIHJ>0: A $oid reHection((loat "(loat C) 9 (loat m: m>(&2#&2)L(-2#-1): i(((codeI1J>>1)VV(codeI.J>>1)) 9 C>C@(-min# )?m: >-min: A else9 i(((codeI2J>>1)VV(codeI3J>>1)) 9 C>C@(-ma-# )?m: >-ma-: A else 9 i(((codeI3J>>1)VV(codeI7J>>1))

9 > @(&min#C)Lm: C>&ma-: A else9 i(((codeI0J>>1)VV(codeI5J>>1)) 9 > @(&ma-#C)Lm: C>&ma-: AAAA a> : %>C: A

OUTPUT:
<nter the line co ordinate 10. 1.3 230 257 <nter window co ordinate 175 195 295 300 Be(ore cli ing in window line a(ter cli ing the window

Sindow to $iew ort trans(ormation $iew ort <nter the $iew ort coordination 1.0 130 2.0 230 Sindow to $iew ort trans(ormation

Sindow Port

Fiew Port

RESULT:
Thus the c rogram (or 24 Oine Cli ing and Sindowing had %een success(ull& e-ecuted and the out ut was $eri(ied.

EX.NO:. DATE:20.05.2013 SUTHERLAND HODGEMAN POLYGON CLIPPING ALGORITHM

AIM:
To write a C Program (or Pol&gon Cli ing using 1utherland Podgeman ol&gon cli ing algorithm.

FUNCTIONS USED:
1. initgra h()# initiali,es the gra hics s&stem. 4eclaration*$oid (ar initgra h(int (ar ?gra hdri$er"int (ar ?gra hmode"char (ar ? athtodri$er) 2. rectangle()# draws a rectangle in current linest&le"thic'ness"drawing color. 4eclaration*$oid (ar rectangle(int le(t"int to "int right"int %ottom) 3. setcolor()# sets current drawing color to color which range (rom 0 to getma-color. 4eclaration* $oid (ar setcolor(int color): 0. draw ol&()# draws the outline o( the ol&gon. 4raws a ol&gon using current line st&le and color.

ALGORITHM:
1. 1tart the rogram 2. declare the $aria%les and draw window using rectangle (unction 3. draw the ol&gon in the window to %e cli ed

0. chec' whether m& ol&IiJ8min- then assign m& ol& to tem ol& (unction .. i( m& ol& $alue is greater than -min then er(orm le(t cli ing 3. i( tem ol& $alue is lessthan -ma- then er(orm right cli ing 7. i( new ol& $alue is less than &ma- then er(orm %ottom cli ing 5. i( tem ol& $alue is greater then &min then er(orm to cli ing 9. Ginall& rint the cli ed ol&gon in the window and terminate the rogram.

PROGRAM:
6include 7gra hics.h8 6include 7conio.h8 6include 7string.h8 int min-" min&" ma--" ma-&: int m& ol&I22J > 9200".0"2.0"100"300"100"2.0"1.0"2.0"200"200"1.0" 1.0"200"1.0"1.0"100"100"1.0"100"200".0A: int new ol&I.0J: int cut-" cut&: $oid cli ol&(int" int IJ): $oid setTintersection(char ?" int" int" int" int): $oid main() 9 int gd>0" gm: initgra h (!gd" !gm";C*++TCC++B2/;): min- > 12.: min& > 7.: ma-->27.: ma-&>17.: rectangle(min-" min&" ma--" ma-&): getch():

draw ol&(11"m& ol&): getch(): cli ol&(11" m& ol&): getch(): closegra h(): A $oid cli ol&(int edges" int m& ol&IJ) 9 int tem ol&I00J: int i" counter>0: (or (i>0: i7edges?2: i@>2) 9 LL le(t cli ... i( ( m& ol&IiJ 8 min- ) 9 tem ol&Icounter@@J > m& ol&IiJ: tem ol&Icounter@@J > m& ol&Ii@1J: A else 9 i( ( i>>0 ) 9 setTintersection(;le(t;"m& ol&IiJ"m& ol&Ii@1J"m& ol&Iedges?2#0J"m& ol&Iedges?2#3J): tem ol&Icounter@@J > cut-: tem ol&Icounter@@J > cut&: setTintersection(;le(t;"m& ol&IiJ"m& ol&Ii@1J"m& ol&Ii@2J"m& ol&Ii@3J): tem ol&Icounter@@J > cut-: tem ol&Icounter@@J > cut&: A

else 9 setTintersection(;le(t;"m& ol&Ii#2J"m& ol&Ii#1J"m& ol&IiJ"m& ol&Ii@1J): tem ol&Icounter@@J > cut-: tem ol&Icounter@@J > cut&: setTintersection(;le(t;"m& ol&IiJ"m& ol&Ii@1J"m& ol&Ii@2J"m& ol&Ii@3J): tem ol&Icounter@@J > cut-: tem ol&Icounter@@J > cut&: A A A edges > counterL2: counter > 0: (or (i>0: i7edges?2: i@>2) 9 LL right cli ... i( ( tem ol&IiJ 7 ma-- ) 9 new ol&Icounter@@J > tem ol&IiJ: new ol&Icounter@@J > tem ol&Ii@1J: A else 9 i( ( i>>0 ) 9 setTintersection(;right;"tem ol&IiJ"tem ol&Ii@1J"tem ol&Iedges?2#0J"tem ol&Iedges?2#3J): new ol&Icounter@@J > cut-: new ol&Icounter@@J > cut&:

setTintersection(;right;"tem ol&IiJ"tem ol&Ii@1J"tem ol&Ii@2J"tem ol&Ii@3J): new ol&Icounter@@J > cut-: new ol&Icounter@@J > cut&: A else 9 setTintersection(;right;"tem ol&Ii#2J"tem ol&Ii#1J"tem ol&IiJ"tem ol&Ii@1J): new ol&Icounter@@J > cut-: new ol&Icounter@@J > cut&: setTintersection(;right;"tem ol&IiJ"tem ol&Ii@1J"tem ol&Ii@2J"tem ol&Ii@3J): new ol&Icounter@@J > cut-: new ol&Icounter@@J > cut&: A A A edges > counterL2: counter > 0: (or (i>0: i7edges?2: i@>2) 9 LL %ottom cli ... i( ( new ol&Ii@1J 7 ma-& ) 9 tem ol&Icounter@@J > new ol&IiJ: tem ol&Icounter@@J > new ol&Ii@1J: A else 9 i( ( i>>0 )

9 setTintersection(;%ottom;"new ol&IiJ"new ol&Ii@1J"new ol&Iedges?2#0J"new ol&Iedges?2#3J): tem ol&Icounter@@J > cut-: tem ol&Icounter@@J > cut&: setTintersection(;%ottom;"new ol&IiJ"new ol&Ii@1J"new ol&Ii@2J"new ol&Ii@3J): tem ol&Icounter@@J > cut-: tem ol&Icounter@@J > cut&: A else 9 setTintersection(;%ottom;"new ol&Ii#2J"new ol&Ii#1J"new ol&IiJ"new ol&Ii@1J): tem ol&Icounter@@J > cut-: tem ol&Icounter@@J > cut&: setTintersection(;%ottom;"new ol&IiJ"new ol&Ii@1J"new ol&Ii@2J"new ol&Ii@3J): tem ol&Icounter@@J > cut-: tem ol&Icounter@@J > cut&: A A A edges > counterL2: counter > 0: (or (i>0: i7edges?2: i@>2) 9 LL to cli ... i( ( tem ol&Ii@1J 8 min& ) 9 new ol&Icounter@@J > tem ol&IiJ: new ol&Icounter@@J > tem ol&Ii@1J:

A else 9 i( ( i>>0 ) 9 setTintersection(;to ;"tem ol&IiJ"tem ol&Ii@1J"tem ol&Iedges?2#0J"tem ol&Iedges?2#3J): new ol&Icounter@@J > cut-: new ol&Icounter@@J > cut&: setTintersection(;to ;"tem ol&IiJ"tem ol&Ii@1J"tem ol&Ii@2J"tem ol&Ii@3J): new ol&Icounter@@J > cut-: new ol&Icounter@@J > cut&: A else 9 setTintersection(;to ;"tem ol&Ii#2J"tem ol&Ii#1J"tem ol&IiJ"tem ol&Ii@1J): new ol&Icounter@@J > cut-: new ol&Icounter@@J > cut&: setTintersection(;to ;"tem ol&IiJ"tem ol&Ii@1J"tem ol&Ii@2J"tem ol&Ii@3J): new ol&Icounter@@J > cut-: new ol&Icounter@@J > cut&: A A A clearde$ice(): rectangle(min-" min&" ma--" ma-&): setcolor(2): draw ol&(counterL2" new ol&): setcolor(1.):

getch(): draw ol&(11"m& ol&): A $oid setTintersection(char ? cli side" int -1" int &1" int -2" int &2) 9 (loat slo e: i( ( -1 U> -2 ) slo e > (&2#&1)?1.0L(-2#-1):

i( ( strcm (cli side";le(t;)>>0 ) 9 cut- > min-: cut& > &1 @ slo e ? ( min- # -1 ): A i( ( strcm (cli side";right;)>>0 ) 9 cut- > ma--: cut& > &1 @ slo e ? ( ma-- # -1 ): A i( ( strcm (cli side";%ottom;)>>0 ) 9 i( ( -1 U> -2 ) cut- > -1 @ ( ma-& # &1 ) L slo e: else cut- > -1: cut& > ma-&: A i( ( strcm (cli side";to ;)>>0 ) 9 i( ( -1 U> -2 ) cut- > -1 @ ( min& # &1 ) L slo e: else cut- > -1: cut& > min&:

A A

OUTPUT:

RESULT:
Thus the C rogram (or Pol&gon cli ing using 1utherland Podgeman Blgorithm had %een success(ull& e-ecuted and the out ut was $eri(ied.

EX.NO:3 DATE:27.05.2013

3D BASIC TRANSFORMATION

AIM:
To write a C rogram that er(orms three dimensional %asic trans(ormations such as translation" rotation and scaling.

FUNCTIONS USED:
1. $oid %ar3d(int le(t" int to " int right" int %ottom" int de th" int to (lag)# %ar3d (unction is used to draw a 2#dimensional" rectangular (illed in %ar. Coordinates o( le(t to and right %ottom corner o( %ar are reCuired to draw the %ar. le(t s eci(ies the Q#coordinate o( to le(t corner" to s eci(ies the R#coordinate o( to le(t corner" right s eci(ies the Q# coordinate o( right %ottom corner" %ottom s eci(ies the R#coordinate o( right %ottom corner" de th s eci(ies the de th o( %ar in i-els" to (lag determines whether a 3 dimensional to is ut on the %ar or not. 2. $oid set(illst&le( int attern" int color)# set(illst&le (unction sets the current (ill attern and (ill color. Color $alues will %e (rom 0 to 1. (%ased on the color scheme &ou ut F2B" 1F2B"..) Patterns include* 0 or ; <NPTRTG/OO;"1 or ;1EO/4TG/OO;"2 or ;O/M<TG/OO;"3 or ;OT1OB1PTG/OO; "0 or ;1OB1PTG/OO;". or ;BW1OB1PTG/OO;"3 or ;OTBW1OB1PTG/OO;"7 or ;PBTCPTG/OO;"5 or ;QPBTCPTG/OO;"9 or

;/MT<KO<BF<TG/OO;"10 or; S/4<T4ETTG/OO;"11 or ;COE1<T4ETTG/OO;"12 or ;D1<KTG/OO;. 3. $oid clearde$ice()# clearde$ice (unction clears the screen in gra hics mode and sets the current osition to (0"0). Clearing the screen consists o( (illing the screen with current %ac'ground color. 0. slee ()# The sleep() (unction shall cause the calling thread to %e sus ended (rom e-ecution until either the num%er o( real#time seconds s eci(ied %& the argument seconds has ela sed or a signal is deli$ered to the calling thread and its action is to in$o'e a signal# catching (unction or to terminate the rocess. 4eclaration

ALGORITHM:
1. 1tart the rogram and declare translate" scaling and the rotation (unctions. 2. 2et the (i$e $alues (rom the user to draw the three dimensional o%Hect using the %ar3d (unction. 3. Call the rotation( )"translate( ) and the scaling( ) (unctions with the user de(ined coordinate $alues as the arameters. 0. 4e(ine the rotation( ) (unction %& getting the rotation angle (rom the user and then calculate the angle $alue as (3.10?ang) di$ided %& 150. .. Calculate the new coordinates -11"&11"-12"&12 %& er(orming mani ulations across each coordinate a-is using the calculated ang $alue. Then draw the three dimensional o%Hect a(ter rotation %& assing the new coordinates calculated to the %ar3d( ) (unction. 3. 4e(ine the tranlate( ) (unction %& getting the translation $ectors (rom the user along %oth - and & a-is. 7. Bdd the translation $ectors to the original coordinates to o%tain the new translated coordinates. Then draw the three dimensional o%Hect a(ter translation %& assing translated coordinates $alues -11"&11"-12"&12 to %ar3d( ) (unction. 5. 4e(ine the scaling ( ) (unction %& getting the scaling $alues (rom the user along -"& and , a-is. 9. Nulti l& the scaling $alues with the original coordinates to o%tain the new scaled coordinates .Then draw the three dimensional o%Hect a(ter scaling %& assing the scaled coordinates -11"&11"-12"&12 to %ar3d( ) (unction. 10. Call the closegra h( ) (unction and sto the rogram.

PROGRAM:
6include7conio.h8 6include7stdio.h8 6include7stdli%.h8 6include7gra hics.h8 6include7conio.h8 6include7math.h8 $oid translate(int"int"int"int"int): $oid rotation(int"int"int"int"int): $oid scaling(int"int"int"int"int): $oid main() 9 int gd>4<T<CT"gm"errorcode: int -1"-2"&1"&2"d t:

clrscr(): initgra h(!gd"!gm";c*LtcL%gi;): rint((;enter the $alue o( -1"&1"-2"&2 ! d t*;): scan((;=d=d=d=d=d;"!-1"!&1"!-2"!&2"!d t): set(illst&le(10"0): %ar3d(-1"&1"-2"&2"d t"1): slee (2): LLclearde$ice(): set(illst&le(5"0): translate(-1"&1"-2"&2"d t): slee (2): LLclearde$ice(): set(illst&le(3"5): rotation(-1"&1"-2"&2"d t): slee (.): LLclearde$ice(): scaling(-1"&1"-2"&2"d t): getch(): closegra h(): A $oid rotation(int a"int %"int c"int d"int e) 9 int -11"&11"-12"&12: (loat ang: rint((;+n+t KETBT/EM+n;): rint((;enter the rotation angle*;): scan((;=(;"!ang): ang>(3.10?ang)L150:

-11>a?cos(ang)#%?sin(ang): &11>a?sin(ang)@%?cos(ang): -12>c?cos(ang)#d?sin(ang): &12>c?sin(ang)@d?cos(ang): %ar3d(-11"&11"-12"&12"e"1): A $oid translate(int a"int %"int c"int d"int e) 9 int -11"&11"-12"&12"t-"t&: rint((;+n+tTKBM1OBT/EM+n;): rint((;enter the translate co#ordinate*;): scan((;=d=d=;"!t-"!t&): -11>a@t-: &11>%@t&: -12>c@t-: &12>d@t&: %ar3d(-11"&11"-12"&12"e"1): A $oid scaling(int a"int %"int c"int d"int e) 9 int -11"&11"-12"&12",1"s-"s&"s,: rint((;+n+t1CBO/M2+n;): rint((;enter the scaling $alue;): scan((;=d=d=d;"!s-"!s&"!s,): -11>a?s-: &11>%?s&: -12>c?s-: &12>d?s&:

,1>e?s,: %ar3d(-11"&11"-12"&12",1"1): A

OUTPUT:
<nter the $alue o( -1" &1" -2" &2 ! de t* 2.0 100 230 100 00

TKBM1OBT/EM <nter the translate co#ordinate $alue* 10 20

KETBT/EM <nter the rotation angle* 30

1CBO/M2 <nter the scaling $alues* 2 3 .

RESULT:
Thus the C rogram (or 34 Basic Trans(ormations had %een success(ull& e-ecuted and the out ut was $eri(ied.

EX.NO:7(a) DATE:03.09.2013

3D COMPOSITE TRANSFORMATION

AIM*
To write a C rogram to demonstrate 34 Com osite trans(ormation.

FUNCTIONS USED*
1. initgra h()#To start the gra hics s&stem" (irst call the initgra h (unction. initgra h loads the gra hics dri$er and uts the s&stem into gra hics mode 2. set%'color()# The 1etB'Color (unction sets the current %ac'ground color to the s eci(ied color $alue" or to the nearest h&sical color 3. setcolor()# The 1<T CEOEK command sets the (oreground and %ac'ground colors o( the (orm o%Hects s eci(ied %& o%Hect. 0. %ar3d()# Bar3d draws a 3#dimensional Bar with corners at (Q1"R1) and (Q2"R2) and (ills it with the current color and (ill#st&le. 4e th s eci(ies the num%er o( i-els . .. set(illst&le()# set(illst&le (unction sets the current (ill attern and (ill color. 4eclaration *# $oid set(illst&le( int attern" int color).

3. outte-t-&()# outte-t-& dis la&s a te-t string in the $iew ort at the gi$en osition (-" &). 6include 7gra hics.h8 $oid outte-t-&(int -" int &" char ?te-tstring):

ALGORITHM*
1. /nitiali,e the $aria%les %& using structure and initiali,e matri-I3JI3J. 2. /nitiali,e the gd" ts"t ts"%'color and setcolor. 3. Per(orm m remul"translate"scale"rotate"trans(orm ts"!trans(ormation. 0. Pass the arameter $alue to the a%o$e (unction and get the $alues to %e rotated"scaling and trans(ormation. .. 4is la& the gra hics o( triangle scaling"trans(ormation and rotation. 3. 1to the rogram.

PROGRAM:
6include7stdio.h8 6include7conio.h8 6include7dos.h8 6include7math.h8 6include7gra hics.h8 t& ede( (loat matri-I3JI3J: t& ede( struct9(loat -"&:A we t: matri- tm: $oid midentit&(matri- m) 9 int i"H: (or(i>0:i73:i@@) (or(H>0:H73:H@@)

mIiJIHJ>(i>>H): A $oid m remul(matri- a"matri- %) 9 int r"c: matri- tem : (or(r>0:r73:r@@) (or(c>0:c73:c@@) tem IrJIcJ>aIrJI0J?%I0JIcJ@aIrJI1J?%I1JIcJ@aI2JIrJ?%I2JIcJ: (or(r>0:r73:r@@) (or(c>0:c73:c@@) %IrJIcJ>tem IrJIcJ: A $oid translate(int t-"int t&) 9 matri- m: midentit&(m): mI0JI2J>t-: mI1JI2J>t&: m remul(m"tm): A $oid scale((loat s-"(loat s&"we t re( t) 9 matri- m: midentit&(m): mI0JI0J>s-: mI0JI2J>(1#s-)?re( t.-: mI1JI1J>s&:

mI1JI2J>(1#s&)?re( t.&: m remul(m"tm): A $oid rotate((loat a"we t re( t) 9 matri- m: a>a?3.10L150: mI0JI0J>cos(a): mI0JI1J>sin(a): mI0JI2J>re( t.-?(1#cos(a))@re( t.&?sin(a): mI1JI0J>sin(a): mI1JI1J>cos(a): mI1JI2J>re( t.&?(1#cos(a))#re( t.-?sin(a): m remul(m"tm): A $oid trans(ormation(int n ts"we t ? ts) 9 int ': (loat tem : (or('>0:'7 ts:'@@) 9 tem >tmI0JI0J? tsI'J.-@tmI0JI1J? tsI'J.&@tmI0JI2J: tsI'J.&>tmI1JI0J? tsI'J.-@tmI1JI2J: tsI'J.->tem : A A $oid tsto s(we t ? ts"int t tsI3J) 9 int i"H>0:

trans(orm oints(2" ts): (or(i>0:i72:i@@) 9 t tsIHJ> tsIiJ.-: t tsIH@1J> tsIiJ.&: H>H@2: A %ar3d(t tsI0J"t tsI1J"t tsI2J"t tsI3J"10"1): A $oid main() 9 we t tsI3J>92.0.0"2.0.0"200.0"200.0A: int t tsI3J>9.0.0".0.0"200.0"200.0A: we t re( t>937..0"37..0A: int gd>4<T<CT"gm"i"H"'"tem : initgra h(!gd"!gm";c*LLtccLL%gi;): set%'color(SP/T<): setcolor(BOD<): %ar3d(1.0"1.0"200"200"201): midentit&(tm): slee (0): set(illst&le(3".): scale(0.."0.."re( t): tstot ts( ts"t ts): outte-t-&(2.0"330";BGT<K 1CBO/M2;): slee (2): midentit&(tm): slee (2):

rotate(50.0"re( t): set(illst&le(3".): tstot ts( ts"t ts): outte-t-&(3.0"300";BGT<K KETBT/EM;): slee (2): translate(0"1.0): tstot ts( ts"t ts): outte-t-&(000"0.0";BGT<K TKBM1OBT/EM;): getch(): A

OUTPUT:

RESULT:
Thus the C rogram (or 34 Com osite Trans(ormations had %een success(ull& e-ecuted and the out ut was $eri(ied.

EX.NO:7(%) DATE:03.09.2013

3D OBLIQUE PROJECTION

AIM:
To write a C rogram (or demonstrating 3d o%liCue roHection.

FUNCTIONS USED:
1. initgra h (!gd"!gm")c*++tcc++%gi))# initiali,es the gra hics s&stem %& loading a gra hics dri$er (rom dis' then utting the s&stem into gra hics mode.

2. outte-t-&()# outte-t-& dis la&s a te-t string in the $iew ort at the gi$en osition (-" &). 6include 7gra hics.h8 $oid outte-t-&(int -" int &" char ?te-tstring): 3. line()#Oine draws a line %etween two s eci(ied oints. Oine draws a line (rom (-1"&1) to (-2"&2) using the current color "line st&le and thic'ness. /t does not u date the current osition(CP). 0. clearde$ice()*clears the gra hics s&stem. 4eclaration*$oid (ar clearde$ice($oid):

ALGORITHM:
1. 1tart the rogram.

2. 4eclare the $aria%les are -"&","- "& "/"-1"&1",1"- 1"& 1. 3. /nitiali,e the gra h and enter the coordinate ositions (or the line" i and angle $alues. 0. Calculate the $alues. .. 4raw the arallel roHection o%liCue through line (unction. 3. 1to the rogram.

PROGRAM:
6include7stdio.h8 6include7conio.h8 6include7stdli%.h8 6include7math.h8 6include7gra hics.h8 $oid main() 9 int -"&","- "& "i: int -1"&1",1"- 1"& 1: int gd>4<T<CT"gm: (loat " i"a"a1"l: initgra h(!gd"!gm")c*++tcc++%gi)): clearde$ice(): rint((X+n PBKBOO<O PKEY<CT/EM)): rint((X+n <nter the starting -1"&1",1"co#ordinate o( line ! i"an angle $alue+n)):

scan((X=d=d=d=(=()"!-"!&"!,"! i"!a): rint((X+n <nter the starting -2"&2",2"co#ordinate o( line +n)): scan((X=d=d=d)"!-1"!&1"!,1): clearde$ice(): line(-"&"-1"&1): getch(): > i?3.10L150: a1>a?3.10L150: l>,Ltan(a1): - >-@l?cos( ): & >&@l?sin( ): - 1>-1@l?cos( ): & 1>&1@l?sin( ): outte-t-&(.0".0") arallel roHection o%liCue+n)): line(- "& "- 1"& 1): getch(): A

OUTPUT:
PARALLEL PROJECTION <nter the starting -1"&1",1"co#ordinate o( line ! i"angle $alue* 100 120 1.0 30 .0 <nter the -2"&2",2 co#ordinates o( line* 200 220 200

Parall l !r"# $%&"' l&'

RESULT:
Thus the C was $eri(ied. rogram (or 3d E%liCue ProHection had %een e-ecuted success(ull& and out ut

EX.NO:7(c) DATE:10.09.2013

3D PERSPECTI(E PROJECTION

AIM:
To write a C rogram to demonstrate the conce t o( Pers ecti$e roHection.

FUNCTIONS USED:
1. detectgra h(!gd"!gm)# determine gra hics dri$er and mode to use %& chec'ing the hardware. gra hdri$er is an integer that s eci(ies the gra hics dri$er to %e used. gra hmode s eci(ies the initial gra hics mode.

2. initgra h (!gd"!gm")c*++tcc++%gi))# initiali,es the gra hics s&stem %& loading a gra hics dri$er (rom dis' then utting the s&stem into gra hics mode. 3. clearde$ice()*clears the gra hics s&stem. 4eclaration*$oid (ar clearde$ice($oid): 0. closegra h()# shuts down the gra hics s&stem. /t also deallocates all the memor& allocated %& the gra hics s&stem. /t then restores the screen to the mode it was in %e(ore &ou called initgra h.

ALGORITHM:
1. 1tart the rogram.

2. 4eclare the gdri$er> 4<T<CT" gmode. 3. /nitiali,e the gra hic mode with the ath location in the TC (older. Then" clear the de$ice using the a ro riate (unction. 0. Dsing the (or loo "we draw the cu%e with the calculated $alues o( the co#ordinate oints as -1"&1"-2"&2 res ecti$el&. .. Me-t in ut the two end oints to draw the line with the hel o( the line (unction. 3. Then" in ut the num%er o( line (unctions to draw the lines using line (unction it resem%les the triangle sha e on one (ace the cu%e. 7. Me-t using the switch statement we er(orm the ers ecti$e roHection along the di((erent a-is Q" R" and Z a-is res ecti$el&. 5. Btlast in the main (unction declares the $alues (or drawing the edges o( the cu%e in Three dimensional $iew %& calling the a ro riate (unctions as ers ect and draw cu%e. 9. Close the gra h. 10. Terminate the rogram.

PROGRAM:
6include7stdio.h8 6include7conio.h8 6include7math.h8 6include7stdli%.h8 6include7gra hics.h8 int gd>4<T<CT"gm: dou%le -1"-2"&1"&2: $oid drawcu%e(dou%le edgeI20JI3J) 9 int i: initgra h(!gd"!gm";c*++tcc++%gi;): clearde$ice(): (or(i>0:i719:i@@) 9 -1>edgeIiJI0J@edgeIiJI2J?(cos(2.3.32)):

&1>edgeIiJI1J#edgeIiJI2J?(sin(2.3.32)): -2>edgeIi@1JI0J@edgeIi@1JI2J?(cos(2.3.32)): &2>edgeIi@1JI1J#edgeIi@1JI2J?(sin(2.3.32)): line(-1@320"200#&1"-2@320"200#&2): A line(320"200"320"2.): line(320"200"..0"200): line(320"200"1.0"010): getch(): closegra h():A $oid ers ect(dou%le edgeI20JI3J) 9 int ch: int i: (loat "C"r: clrscr(): rint((;+n ers ecti$e roHection;): rint((;+n1*>>8- a-is;): rint((;+n2*>>8& a-is;): rint((;+n3*>>8, a-is;): scan((;=d;"!ch): switch(ch) 9 case 1* rint((;+n enter the *>;): scan((;=(;"! ): (or(i>0:i720:i@@) 9

edgeIiJI0J>edgeIiJI0JL( ?edgeIiJI0J@1): edgeIiJI1J>edgeIiJI1JL( ?edgeIiJI0J@1): edgeIiJI2J>edgeIiJI2JL( ?edgeIiJI0J@1): A drawcu%e(edge): %rea': case 2* rint((;+n enter the C*>;): scan((;=(;"!C): (or(i>0:i720:i@@) 9 edgeIiJI1J>edgeIiJI1JL(C?edgeIiJI1J@1): edgeIiJI0J>edgeIiJI0JL(C?edgeIiJI1J@1): edgeIiJI2J>edgeIiJI2JL(C?edgeIiJI1J@1): A drawcu%e(edge): %rea': case 3* rint((;+n enter the r*>;): scan((;=(;"!r): (or(i>0:i720:i@@) 9 edgeIiJI2J>edgeIiJI2JL(r?edgeIiJI2J@1): edgeIiJI0J>edgeIiJI0JL(r?edgeIiJI2J@1): edgeIiJI1J>edgeIiJI1JL(r?edgeIiJI2J@1): A drawcu%e(edge): %rea':

A closegra h():A $oid main() 9 int choice: dou%le edgeI20J I3J>9100"0"0"100"100"0"0"100"0"0"100"100"0"0"100"0"0"0"100"0"0"100"0"100"100"7."100"7."100"10 0"100"100"7."100"100"0"100"100"7."100"7."100"7."100"100"0"100"100"0"100"0"0"0"0"0"0"100"100" 0"100A: clrscr(): drawcu%e(edge): ers ect(edge): closegra h():A

OUTPUT:

P<K1P<CT/F< PKEY<CT/EM BBEDT 1*Q#B-is 2*R#B-is 3*Z#B-is

1 <nter the $alue o( P*2.

P<K1P<CT/F< PKEY<CT/EM BBEDT 1*Q#B-is 2*R#B-is 3*Z#B-is 2 <nter the $alue o( [*2.

P<K1P<CT/F< PKEY<CT/EM BBEDT 1*Q#B-is 2*R#B-is 3*Z#B-is

3 <nter the $alue o( K*2.

RESULT:
Thus the C rogram (or 34 Pers ecti$e ProHection had %een e-ecuted success(ull& and out ut was $eri(ied.

EX.NO:5 DATE:10.09.2013

3D OBJECTS AND SCENES

AIM:
To write a C rogram to demonstrate the conce t o( three dimensional scenes and o%Hects.

FUNCTIONS USED:
1.arc()#Brc draws a circular arc. Brc draws a circular arc in the current drawing color. $oid (ar arc(int -"int &"int stangle"int endangle"int radius): 2.line()#Oine draws a line %etween two s eci(ied oints. Oine draws a line (rom (-1"&1) to (-2"&2) using the current color "line st&le and thic'ness. /t does not u date the current osition(CP). $oid (ar line(int -1"int &1"int -2"int &2): 3.rectangle()# 4raws a rectangle in gra hics mode. /t draws a rectangle in the current line st&le" thic'ness and drawing color. (le(t" to ) is the u er le(t corner o( the rectangle" and(right" %ottom) is its lower right corner. Foid (ar rectangle(int le(t"int to "int right"int %ottom): 0.circle()# Circle draws the circle. Circle draws a color in the current drawing color. $oid (ar circle(int -"int &"int radius)

ALGORITHM:
1. 1tart the rogram. 2. 4eclare the gdri$er >4<T<CT" gmode. 3. /nitiali,e the gra hic mode with the ath location in TC (older.

0. /n ut the num%er o( $arious two line end oints using num%er o( line (unctions to draw the line. .. /n ut the radius"- and & $alues using a circle (unction to draw the circle. 3. /n ut the $arious (our oints to the rectangle (unction to draw a rectangle that is le(t" to " right and %ottom oints. 7. /n ut the -" &" start angle" end angle and radius to draw the arc using the arc (unction to get a three dimensional image (ie" here is the hut). 5. Close the gra h. 9. Terminate the rogram.

PROGRAM:
6include7conio.h8 6iinclude7stdio.h8 6include7gra hics.h8 6include7math.h8 6include7dos.h8 6include7 rocess.h8 6include7stdli%.h8 $oid main()9 int gra hdri$er>4<T<CT"gra hmode: initgra h(!gra hdri$er"!gra hmode";c*++tcc++%in;): line(100"100"1.0".0): line(1.0".0"200"100): line(100"100"200"100): line(1.0".0"3.0".0): line(200"100"3.0"100): line(3.0".0"3.0"100): circle(1.0"7."100):

rectangle(100"100"200"300): rectangle(200"100"3.0"300): rectangle(2.0"17."300"22.): line(2.0"17."300"22.): line(300"17."2.0"22.): line(12."300"12."22.): line(17."300"17."22.): arc(1.0"22."0"150"2.): getch(): closegra h():A

OUTPUT:

RESULT:
Thus the C rogram (or 34 E%Hects and 1cenes had %een success(ull& e-ecuted and the out ut was $eri(ied.

EX.NO:9(a) DATE:17.09.2013

FRACTALS

AIM:
To write a C rogram to demonstrate the conce t o( (ractals.

ALGORITHM:
1. start the rogram 2. 4e(ine the rad $aria%le and declare the $aria%les -" &" num%ranch as int and s readratio" lenratio as (loat. 3. 4eclare the drawtree() (unction inside int main() 0. /n drawtree() (unction chec' whether n is greater than ,ero i( so calculate the $alue o( -2"&2 .. Then set color as white using setcolor() (unction and draw a line using line() (unction 3. Mow assign the $alue o( num%ranch (or num 7. Chec' the condition i( num greater than l then calculate $alue o( delang else set delang as ,ero and (ind $alue o( ang 5. Dsing (or loo call drawtree() (unction. 9. <lse setcolor()" drawelli se()" and (illelli se() (unction is called and close the gra h 10. 1to the rogram

FUNCTIONS USED:
1. line()# Oine draws a line %etween two s eci(ied oints. Oine draws a line (rom (-1"&1) to (-2"&1) using the correct color" line st&le" and thic'ness. /t does not u date the current osition.

line(int -1"int&1"int -2"int &2): 2. setcolor()#1etcolor sets the current drawing color. 1etcolor sets the current drawing color to color" which can range (rom 0 to getma-color 1etcolor(int color): 3. elli se()# elli se draws on elli tical arc. <lli se draws an elli tical arc in the current drawing color elli se(int -" int &" int stangle" int endangle" int -radius" int &radius): 0. (illelli se()# (ill elli se draws and (ills an elli se. Gillelli se draws an elli se" then (ills the elli se with the current (ill color and (ill attern. (illelli se(int -" int &" int -radius" int &radius):

PROGRAM:
6include7stdio.h8 6include7conio.h8 6include7stdli%.h8 6include7gra hics.h8 6include7math.h8 6de(ine rads .30.270L?3.10L150?L int ->350"&>0.0"num%ranch>3: (loat s readratio>0.5"lenratio>0.7.: int main() 9 int gd>4<T<CT"gm: int drawtree(int -1"int &1"(loat a"(loat l"(loat ("int n): initgra h(!gd"!gm";c*++tcc++%gi;): drawtree(-"&"250"3.0"150"27): getch(): closegra h(): restorecrtmode(): return 0: A drawtree(int -1"int &1"(loat a"(loat l"(loat ("int n) 9 int i"num"-2"&2: (loat delang"ang: i((n80) 9 -2>-1@l?cos(rads?a): &2>&1@l?sin(rads?a): setcolor(SP/T<): line(-1"&1"-2"&2):

num>num%ranch: i((num8l) delang>(L(num#1.0): else delang>0.0: ang>a#(L2.0#delang: (or(i>1:i7>num:i@@) 9 ang@>delang: drawtree(-2"&2"ang"l?lenratio"(?s readratio"n#1): A A else 9 setcolor(random(7)@1): elli se(-2"&2"0"273"2"0): (illelli se(-2"&2"2"0): A return 0: A

OUTPUT:

RESULT:
Thus the C rogram (or Gractals had %een success(ull& e-ecuted and the out ut was $eri(ied.

EX.NO:9(%) DATE:20.09.2013

FRACTAL TREE

AIM:
To write a C rogram to demonstrate the conce t o( (ractals tree.

ALGORITHM*
1.1tart the rogram 2.4e(ine the rad $aria%le and declare the $aria%les -" &" num%ranch as int and s readratio" lenratio as (loat. 3.4eclare the drawtree() (unction inside int main(). 0./n drawtree() (unction chec' whether n is greater than ,ero i( so e-ecute switch case (unction. calculate the $alue o( -2"&2. ..using (or loo condition draw the lines arallel using line() (unction. Mow (ind the $alue o( num. 3.Chec' the condition i( num greater than l then calculate $alue o( delang else set delang as ,ero and (ind $alue o( ang. 7.Dsing (or loo call drawtree() (unction. 5.<lse set(illst&le()" and (illelli se() (unction is called and close the gra h. 9.1to the rogram

FUNCTIONS USED:

1.line()#Oine draws a line %etween two s eci(ied oints. Oine draws a line (rom (-1"&1) to (-2"&1) using the correct color" line st&le" and thic'ness. /t does not u date the current osition. line(int -1"int&1"int -2"int &2): 2.setcolor()# 1etcolor sets the current drawing color. 1etcolor sets the current drawing color to color" which can range (rom 0 to getma-color. 1etcolor(int color): 3.elli se()# <lli se draws on elli tical arc. <lli se draws an elli tical arc in the current drawing color. elli se(int -" int &" int stangle" int endangle" int -radius" int &radius): 0.(illelli se()# (ill elli se draws and (ills an elli se. Gillelli se draws an elli se" then (ills the elli se with the current (ill color and (ill attern. (illelli se(int -" int &" int -radius" int &radius):

PROGRAM*
)include7stdio.h8 6include7conio.h8 6include7stdli%.h8 6include7gra hics.h8 6include7math.h8 6de(ine rads 0.0170L?3.10L150?L int ->250"&>3.0"num%ranch>3: (loat s readratio>0.5"lenratio>0.7.: main() 9 int gd>4<T<CT"gm: int drawtree(int -1"int &1"(loat a"(loat l"(loat ("int n): initgra h(!gd"!gm";c*++tcc++%gi;): drawtree(-"&"270"7."30"7): getch(): closegra h(): restorecrtmode(): return 0: A drawtree(int -1"int &1"(loat a"(loat l"(loat ("int n) 9 int i"num"-2"&2: (loat delang"ang: i((n80) 9 switch(n) 9 case 1* setcolor(O/2PT2K<<M): %rea': case 2*

setcolor(2K<<M): %rea': case 3* setcolor(K<4): %rea': case 0* setcolor(BKESM): %rea': de(ault* setcolor(4BKW2KBR): %rea': A -2>-1@l?cos(rads?a): &2>&1@l?sin(rads?a): (or(i>0:i7n:i@@) 9 line(-1@i"&1"-2@i"&2): line(-1#i"&1"-2#i"&2): A num>random(3)@1: i((num8l) delang>(L(num#1.0): else delang>0.0: ang>a#(L2.0#delang: (or(i>1:i7>num:i@@) 9 ang@>delang: drawtree(-2"&2"ang@10"l?lenratio"1.0?random(90)@1"#1): A A else 9 set(illst&le(1EO/4TG/OO"random(1.)): (illelli se(-1"&1"3"3): A return 0: A

OUTPUT*

RESULT:
Thus the C rogram (or Gractals Tree had %een success(ull& e-ecuted and the out ut was $eri(ied.

Вам также может понравиться