tashu.docx
TRANSCRIPT
8/19/2019 Tashu.docx
http://slidepdf.com/reader/full/tashudocx 1/62
1. Program to draw a line using Direct Method.
#include<stdio.h>#include<conio.h>
#include<math.h>int main(){int gd=DETECT,gm,xc,yc,r,x ,x!,y,y ,i"initgra h($gd,$gm,%C&''tur oc '' gi%)"
rint*(%enter the center oints%)"scan*(%+d+d%,$xc,$yc)"
rint*(%enter the radius%)"scan*(%+d%,$r)"x = "
x!=r-s rt(!)"/hile(x 0=x!){y =s rt((r1r)2(x 1x ))"
ut ixel(x 3xc,y 3yc, )" ut ixel(y 3xc,x 3yc,!)" ut ixel(2y 3xc,x 3yc, )" ut ixel(2x 3xc,y 3yc,4)" ut ixel(2x 3xc,2y 3yc,5)" ut ixel(2y 3xc,2x 3yc,6)" ut ixel(y 3xc,2x 3yc,7)" ut ixel(x 3xc,2y 3yc,8)"x 33"9delay(! )"setcolor(i- )"settextstyle(:; ?@AT,B@ D ,8)"outtextxy( 7 ,4 ,%;ade Fy Tashu Aan/al%)"getch()"
closegra h()"return "9
1
8/19/2019 Tashu.docx
http://slidepdf.com/reader/full/tashudocx 2/62
OUTPUT:
2
8/19/2019 Tashu.docx
http://slidepdf.com/reader/full/tashudocx 3/62
2. Program to draw a line using Simple DDA line drawing algorithm.
#include<gra hics.h>#include<stdio.h>#include<conio.h>int main(){int gd=DETECT,gm,x ,x!,y ,y!,m,c,i"initgra h($gd,$gm,%C&''tur oc '' gi%)"
rint*(%enter the starting oints%)"scan*(%+d+d%,$x ,$y )"
rint*(%enter the ending oints%)"scan*(%+d+d%,$x!,$y!)"m=((y!2y )-(x!2x ))"i*(m<= ){/hile(x 0=x!){x =x 3 "y =y 3m"
ut ixel(x ,y ,G EEA)"99i*(m> ){/hile(y 0=y!){y =y 3 "x =x 3m"
ut ixel(x ,y ,G EEA)"
99delay(! )"setcolor(i- )"settextstyle(:; ?@AT,B@ D ,8)"outtextxy( 7 ,4 ,%;ade Fy Tashu Aan/al%)"getch()"
3
8/19/2019 Tashu.docx
http://slidepdf.com/reader/full/tashudocx 4/62
closegra h()"return "9
OUTPUT:
4
8/19/2019 Tashu.docx
http://slidepdf.com/reader/full/tashudocx 5/62
3. Program to draw a ine using !resenham line drawing algorithm.
#include<gra hics.h>#include<conio.h>#include<dos.h>#include<stdio.h>Hoid main(){int gd=DETECT,gm"int x ,x!,y ,y!,dy,dx,*,*n,i"--x=getmaxx()"--int y=getmaxy()"
initgra h($gd,$gm,%C&''tur oc '' gi%)" rint*(% enter the starting oints%)"
scan*(%+d+d%,$x ,$y )" rint*(% enter the ending oints%)"scan*(%+d+d%,$x!,$y!)"dy=y!2y "dx=x!2x "
*=(!1dy)2dx"i*(*< ){
/hile(x 0=x!){x =x 3y "
ut ixel(x ,y , ED)"*n=!1dy"*=*3*n"9
9i*(*> ){
/hile(y 0=y!){x =x 3 "y =y 3 "
5
8/19/2019 Tashu.docx
http://slidepdf.com/reader/full/tashudocx 6/62
ut ixel(x ,y , ED)"*n=!1(dy2dx)"*=*3*n"9
9delay(! )"setcolor(i- )"settextstyle(:; ?@AT,B@ D ,8)"outtextxy( 7 ,4 ,%;ade Fy Tashu Aan/al%)"getch()"closegra h()"9
OUTPUT:
6
8/19/2019 Tashu.docx
http://slidepdf.com/reader/full/tashudocx 7/62
". Program to draw circle using Direct Method.
#include<stdio.h>#include<conio.h>#include<gra hics.h>#include<math.h>int main(){int gd=DETECT,gm"int xc,yc,r,x ,x!,y ,i"initgra h($gd,$gm,%c&-tur oc - gi%)"
rint*(%enter the center oints%)"scan*(%+d+d%,$xc,$yc)"
rint*(%enter the radius%)"scan*(%+d%,$r)"x = "x!=r-s rt(!)"/hile(x 0=x!){y =s rt((r1r)2(x 1x ))"
ut ixel(x 3xc,y 3yc, ED)" ut ixel(y 3xc,x 3yc,G EEA)" ut ixel(2y 3xc,x 3yc,F IE)" ut ixel(2x 3xc,y 3yc,JE @K)" ut ixel(2x 3xc,2y 3yc, ED)" ut ixel(2y 3xc,2x 3yc,G EEA)" ut ixel(y 3xc,2x 3yc,F IE)" ut ixel(x 3xc,2y 3yc,JE @K)"x 33"9delay(! )"
setcolor(i- )"settextstyle(:; ?@AT,B@ D ,8)"outtextxy( 7 ,4 ,%;ade Fy Tashu Aan/al%)"getch()"closegra h()"return( )"9
7
8/19/2019 Tashu.docx
http://slidepdf.com/reader/full/tashudocx 8/62
OUTPUT:
8
8/19/2019 Tashu.docx
http://slidepdf.com/reader/full/tashudocx 9/62
#. Program to draw a circle using Midpoint $ircle Drawing Algorithm.
#include<stdio.h>#include<gra hics.h>#include<conio.h>#include<math.h>int main(){int gd=DETECT,gm,xc,yc,x,y,r,d,i"initgra h($gd,$gm,%C&''tur oc '' gi%)"
rint*(%enter the center oints%)"scan*(%+d+d%,$xc,$yc)"
rint*(%enter the radius%)"scan*(%+d%,$r)"x= "y=r"d= 2r"/hile(x<=y){x33"
ut ixel(x3xc,y3yc, )"
ut ixel(y3xc,x3yc,!)" ut ixel(2y3xc,x3yc, )" ut ixel(2x3xc,y3yc,4)" ut ixel(2x3xc,2y3yc,5)" ut ixel(2y3xc,2x3yc,6)" ut ixel(y3xc,2x3yc,7)" ut ixel(x3xc,2y3yc,8)"i*(d< ){d=(d3(!1x)3 )"
9else{d=(d3(!1(x2y))35)"y22"99
9
8/19/2019 Tashu.docx
http://slidepdf.com/reader/full/tashudocx 10/62
delay(! )"setcolor(i- )"settextstyle(:; ?@AT,B@ D ,8)"outtextxy( 7 ,4 ,%;ade Fy Tashu Aan/al%)"getch()"closegra h()"return "9
OUTPUT:
10
8/19/2019 Tashu.docx
http://slidepdf.com/reader/full/tashudocx 11/62
%. Program to draw a circle using !resenham $ircle Drawing.
#include<stdio.h>#include<conio.h>#include<math.h>int main(){int gd=DETECT,gm,xc,yc,x,y,r,i,d,i"
initgra h($gd,$gm,%C&''tur oc '' gi%)" rint*(%enter the center oints%)"scan*(%+d+d%,$xc,$yc)"
rint*(%enter the radius%)"scan*(%+d%,$r)"
"x= "y=r"d=( 2(!1r))"
/hile(x<=y){x33"
ut ixel(x3xc,y3yc, )" ut ixel(y3xc,y3yc,!)" ut ixel(2y3xc,x3yc, )" ut ixel(2x3xc,y3yc,4)" ut ixel(2x3xc,2y3yc,5)" ut ixel(2y3xc,2x3yc,6)" ut ixel(y3xc,2x3yc,7)" ut ixel(x3xc,2y3yc,8)"i*(d< ){d=(d3(41x)36)"9else{
11
8/19/2019 Tashu.docx
http://slidepdf.com/reader/full/tashudocx 12/62
d=(d3(41(x2y))3 )"y22"99delay(! )"setcolor(i- )"settextstyle(:; ?@AT,B@ D ,8)"outtextxy( 7 ,4 ,%;ade Fy Tashu Aan/al%)"getch()"closegra h()"return "9
OUTPUT:
12
8/19/2019 Tashu.docx
http://slidepdf.com/reader/full/tashudocx 13/62
&. Program to draw a circle using Polar $o'ordinates.
#include<stdio.h>#include<conio.h>#include<gra hics.h>#include<math.h>int main(){int gd=DETECT,gm"int x ,x!,y ,y!,i,xc,yc,r"
13
8/19/2019 Tashu.docx
http://slidepdf.com/reader/full/tashudocx 14/62
initgra h($gd,$gm,%c&-tur oc - gi%)" rint*(%enter the center oints%)"scan*(%+d+d%,$xc,$yc)"
rint*(%enter the radius%)"scan*(%+d%,$r)"x = "y =r"*or(i=L "i>=45"i22){x =r1cos(i)"y =r1sin(i)"
ut ixel(x 3xc,y 3yc, ED)" ut ixel(y 3xc,x 3yc,G EEA)" ut ixel(2y 3xc,x 3yc,F IE)"
ut ixel(2x 3xc,y 3yc,JE @K)" ut ixel(2x 3xc,2y 3yc, ED)" ut ixel(2y 3xc,2x 3yc,G EEA)" ut ixel(y 3xc,2x 3yc,F IE)" ut ixel(x 3xc,2y 3yc,JE @K)"x 33"9delay(! )"setcolor(i- )"settextstyle(:; ?@AT,B@ D ,8)"
outtextxy( 7 ,4 ,%;ade Fy Tashu Aan/al%)"getch()"closegra h()"return "9
OUTPUT:
14
8/19/2019 Tashu.docx
http://slidepdf.com/reader/full/tashudocx 15/62
(. Program to per)orm 2D Trans)ormations.
15
8/19/2019 Tashu.docx
http://slidepdf.com/reader/full/tashudocx 16/62
#include<stdio.h>#include<conio.h>#include<gra hics.h>#include<math.h>
Hoid translate(int,int)"Hoid scale(int,int)"Hoid rotate(*loat)"
Hoid main(){ int ch" int gd=DETECT,gm"
int tx,ty,sx,sy,i" *loat theta" initgra h($gd,$gm,%C&''tur oc '' gi%)" setcolor(6)" outtextxy ( ,88,%@ Mect.%)" rectangle( ,!5 , 5 ,! )"
rint*(%222;EAI222%)" rint*(%'n !)Translate'n ):cale'n 4) otate%)" rint*(%'nEnter your choice& %)"
scan*(%+d%,$ch)" cleardeHice()"
s/itch(ch) { case !& outtextxy( ,45,%Enter Halue o* tx and ty&%)" scan*(%+d +d%,$tx,$ty)" translate(tx,ty)" reaN" case & outtextxy( ,45,%Enter the Halue o* sx and sy&%)" scan*(%+d+d%,$sx,$sy)" scale(sx,sy)" reaN" case 4& outtextxy( ,5 ,%Enter the angle *or rotation& %)"
16
8/19/2019 Tashu.docx
http://slidepdf.com/reader/full/tashudocx 17/62
scan*(%+*%,$theta)" rotate(theta)" reaN" de*ault& rint*(%you haHe enterd /rong choice%)" reaN" 9delay(! )"setcolor(i- )"settextstyle(:; ?@AT,B@ D ,6)"outtextxy( 7 ,4 ,%;ade Fy Tashu Aan/al%)" getch()" closegra h()"9
Hoid translate(int tx,int ty){ setcolor(!)" outtextxy(!4 , ,%T A: T @A%)" outtextxy(! 8,! ,%222222222222%)" rectangle( ,!5 , 5 ,! )" rectangle( 3tx,!5 3ty, 5 3tx,! 3ty)"9
Hoid scale(int sx,int sy)
{ setcolor(!)" outtextxy(!4 , ,%:C AG%)" outtextxy(! 8,! ,%22222222%)" rectangle(5 ,! , , 5 )" rectangle(5 1sx,! 1sy, 1sx, 5 1sy)"9
Hoid rotate(*loat theta){ int x ,x!,x ,x4" int y ,y!,y ,y4" int ax ,ax!,ax ,ax4,ay ,ay!,ay ,ay4" int re*x,re*y" theta=theta1( . 4- 8 )" setcolor(!)" outtextxy(!4 , ,% @T TE%)"
17
8/19/2019 Tashu.docx
http://slidepdf.com/reader/full/tashudocx 18/62
outtextxy(! 8,! ,%2222222%)" re*x= " re*y= "
x = " y = " x!= 5 " y!= " x = 5 " y = 5 " x4= " y4= 5 "
ax =re*y3(x 2re*x)1cos(theta)2(y 2re*y)1sin(theta)"
ay =re*y3(x 2re*x)1sin(theta)3(y 2re*y)1cos(theta)"
ax!=re*y3(x!2re*x)1cos(theta)2(y!2re*y)1sin(theta)" ay!=re*y3(x!2re*x)1sin(theta)3(y!2re*y)1cos(theta)"
ax =re*y3(x 2re*x)1cos(theta)2(y 2re*y)1sin(theta)" ay =re*y3(x 2re*x)1sin(theta)3(y 2re*y)1cos(theta)"
ax4=re*y3(x42re*x)1cos(theta)2(y42re*y)1sin(theta)" ay4=re*y3(x42re*x)1sin(theta)3(y42re*y)1cos(theta)"
rectangle( , 5 , 5 , )" line(ax ,ay ,ax!,ay!)" line(ax!,ay!,ax ,ay )" line(ax ,ay ,ax4,ay4)" line(ax4,ay4,ax ,ay )"9
OUTPUT:
18
8/19/2019 Tashu.docx
http://slidepdf.com/reader/full/tashudocx 19/62
19
8/19/2019 Tashu.docx
http://slidepdf.com/reader/full/tashudocx 20/62
20
8/19/2019 Tashu.docx
http://slidepdf.com/reader/full/tashudocx 21/62
*. Program to per)orm 3D Trans)ormations.
#include<stdio.h>#include<conio.h>#include<gra hics.h>#include<math.h>int maxx,maxy,midx,midy"
Hoid axis(){ getch()" cleardeHice()"
line(midx, ,midx,maxy)" line( ,midy,maxx,midy)"9Hoid main(){ int gd,gm,x,y,O,ang,x ,x!,y ,y!,i" detectgra h($gd,$gm)" initgra h($gd,$gm,%C&''tur oc '' gi%)" set*illstyle( ,!5)" maxx=getmaxx()" maxy=getmaxy()" midx=maxx-!" midy=maxy-!" outtextxy( , ,%@ G A @FPECT%)" line(midx, ,midx,maxy)" line( ,midy,maxx,midy)" ar d(midx3 ,midy2! ,midx36 ,midy2L ,! ,5)" axis()" outtextxy( ,! ,%T A: T @A%)"
rint*(%'n'n Enter the Translation Hector& %)" scan*(%+d+d%,$x,$y)" ar d(midx3 ,midy2! ,midx36 ,midy2L ,! ,5)" ar d(midx3(x3 ),midy2(y3! ),midx3(x36 ),midy2(y3L ),! ,5)" delay(! )" setcolor(i- )" settextstyle(:; ?@AT,B@ D ,6)"
21
8/19/2019 Tashu.docx
http://slidepdf.com/reader/full/tashudocx 22/62
outtextxy( 7 ,4 ,%;ade Fy Tashu Aan/al%)" axis()"
outtextxy( ,! ,%:C AG%)" rint*(%'n Enter the :caling ?actor& %)" scan*(%+d+d+d%,$x,$y,$O)" ar d(midx3 ,midy2! ,midx36 ,midy2L ,! ,5)" ar d(midx3(x1 ),midy2(y1! ),midx3(x16 ),midy2(y1L ),! 1O,5)" delay(! )" setcolor(i- )" settextstyle(:; ?@AT,B@ D ,6)" outtextxy( 7 ,4 ,%;ade Fy Tashu Aan/al%)" axis()"
outtextxy( ,! ,% @T T @A%)" rint*(%'n Enter the otation angle& %)" scan*(%+d%,$ang)" x = 1cos(ang1 . 4- 8 )2! 1sin(ang1 . 4- 8 )" y = 1sin(ang1 . 4- 8 )3! 1sin(ang1 . 4- 8 )" x!=6 1cos(ang1 . 4- 8 )2L 1sin(ang1 . 4- 8 )" y!=6 1sin(ang1 . 4- 8 )3L 1sin(ang1 . 4- 8 )" delay(! )" setcolor(i- )" settextstyle(:; ?@AT,B@ D ,6)"
outtextxy( 7 ,4 ,%;ade Fy Tashu Aan/al%)" axis()"
rint*(%'n *ter rotating a out O2axis'n%)" ar d(midx3 ,midy2! ,midx36 ,midy2L ,! ,5)" ar d(midx3x ,midy2y ,midx3x!,midy2y!,! ,5)" delay(! )" setcolor(i- )" settextstyle(:; ?@AT,B@ D ,6)" outtextxy( 7 ,4 ,%;ade Fy Tashu Aan/al%)" axis()"
rint*(%'n *ter rotating a out x2axis'n%)" ar d(midx3 ,midy2! ,midx36 ,midy2L ,! ,5)" ar d(midx3 ,midy2x ,midx36 ,midy2x!,! ,5)" delay(! )" setcolor(i- )"
22
8/19/2019 Tashu.docx
http://slidepdf.com/reader/full/tashudocx 23/62
settextstyle(:; ?@AT,B@ D ,6)" outtextxy( 7 ,4 ,%;ade Fy Tashu Aan/al%)" axis()"
rint*(%'n *ter rotating a out y2axis'n%)" ar d(midx3 ,midy2! ,midx36 ,midy2L ,! ,5)" ar d(midx3x ,midy2! ,midx3x!,midy2L ,! ,5)" delay(! )" setcolor(i- )" settextstyle(:; ?@AT,B@ D ,6)" outtextxy( 7 ,4 ,%;ade Fy Tashu Aan/al%)" axis()"
closegra h()"
9
OUTPUT:
23
8/19/2019 Tashu.docx
http://slidepdf.com/reader/full/tashudocx 24/62
24
8/19/2019 Tashu.docx
http://slidepdf.com/reader/full/tashudocx 25/62
25
8/19/2019 Tashu.docx
http://slidepdf.com/reader/full/tashudocx 26/62
26
8/19/2019 Tashu.docx
http://slidepdf.com/reader/full/tashudocx 27/62
1+. Program to con,ert -indow to iewport $o'ordinates.
#include<stdio.h>#include<conio.h>#include<math.h>#include<gra hics.h>Hoid ress(*loat x ,*loat y , *loat x!,*loat y!){int x,y,end,inc= , ,dx=a s(x!2x ),dy=a s(y!2y ),c= ,current= "i* ( dx > dy ){
=!1dy2dx"i*(x <x!){x=x "y=y "end=x!"i*(y <y!)inc= "i*(y >y!)
inc=2 "9else{x=x!"y=y!"end=x "i*(y!<y )inc= "i*(y!>y )inc=2 "9/hile(x<=end){
ut ixel(x,y, 5)"i*( < )
= 3!1dy"
27
8/19/2019 Tashu.docx
http://slidepdf.com/reader/full/tashudocx 28/62
else{y=y3inc"
= 3!1(dy2dx)"9x33"i*(current== $$ c== ){current= "c=2 "9i*(current== $$ c==6){current= "
c=2 "9c33"99else{
=!1dx2dy"i*(y <y!){
x=x "y=y "end=y!"i*(x <x!)inc= "i*(x >x!)inc=2 "9else{x=x!"y=y!"end=y "i*(x!<x )inc= "i*(x!>x )inc=2 "
28
8/19/2019 Tashu.docx
http://slidepdf.com/reader/full/tashudocx 29/62
9/hile(y<=end){
ut ixel(x,y, 5)"i*( < )
= 3!1dx"else{x=x3inc"
= 3!1(dx2dy)"9y33"i*(current== $$ c== ){
current= "c=2 "9i*(current== $$ c==6){current= "c=2 "9c33"9
9
9
Hoid main(){*loat x ,x!,x ,x4,y ,y!,y ,y4"dou le ch"int i,t"*loat Hx,Hy,Hx ,Hx!,Hy!"int gd=DETECT,gm=DETECT"initgra h($gd,$gm,%C&''tur oc '' gi%)"
outtextxy(!5 , L ,%Korld coordinates%)" ress(! ,! ,4 ,! )" ress(! ,! ,! ,4 )" ress(4 ,! ,4 ,4 )"
29
8/19/2019 Tashu.docx
http://slidepdf.com/reader/full/tashudocx 30/62
ress(! ,4 ,4 ,4 )"
outtextxy(! , ,%Qie/ ort%)" ress(! ,! , ,! )" ress(! ,! ,! , )" ress( ,! , , )" ress(! , , , )"
-- ; GE(triangle) ress(!5 ,!5 , 5 ,!5 )" ress(!5 ,!5 , , )" ress( 5 ,!5 , , )"
--T A:?@ ; T @A
Hx=((( 2! )1(!5 2! ))-(4 2! ))3! "Hy=((( 2! )1(!5 2! ))-(4 2! ))3! "
Hx =((( 2! )1( 5 2! ))-(4 2! ))3! "
Hx!=((( 2! )1( 2! ))-(4 2! ))3! "Hy!=((( 2! )1( 2! ))-(4 2! ))3! "
--T A:?@ ;ED ; GE ress(Hx,Hy,Hx ,Hy)"
ress(Hx,Hy,Hx!,Hy!)" ress(Hx ,Hy,Hx!,Hy!)"delay(! )"setcolor(i- )"settextstyle(:; ?@AT,B@ D ,8)"outtextxy( 7 ,4 ,%;ade Fy Tashu Aan/al%)"getch()"9
OUTPUT :
30
8/19/2019 Tashu.docx
http://slidepdf.com/reader/full/tashudocx 31/62
11. Program to show ine $lipping using $ohen Sutherland.
31
8/19/2019 Tashu.docx
http://slidepdf.com/reader/full/tashudocx 32/62
#include<stdio.h>#include<conio.h>#include<gra hics.h>
ty ede* unsigned int outcode"enum { T@R= x , F@TT@;= x!, GBT= x4, E?T= x8 9"
Hoid linecli (x ,y ,x ,y ,x/min,y/min,x/max,y/max )*loat x ,y ,x ,y ,x/min,y/min,x/max,y/max"{
int gd,gm"outcode code ,code ,codeout"
int acce t = , done= "
code = calcode(x ,y ,x/min,y/min,x/max,y/max)"code = calcode(x ,y ,x/min,y/min,x/max,y/max)"
do{i*(0(code S code )){ acce t = " done = " 9elsei*(code $ code ) done = "else{*loat x,y"codeout = code code & code "i*(codeout $ T@R){x = x 3 (x 2x )1(y/max2y )-(y 2y )"y = y/max"9
elsei*( codeout $ F@TT@;){x = x 3 (x 2x )1(y/min2y )-(y 2y )"y = y/min"9else
32
8/19/2019 Tashu.docx
http://slidepdf.com/reader/full/tashudocx 33/62
i* ( codeout $ GBT){y = y 3(y 2y )1(x/max2x )-(x 2x )"x = x/max"9else{y = y 3 (y 2y )1(x/min2x )-(x 2x )"x = x/min"9i*( codeout == code ){x = x" y = y"code =calcode(x ,y ,x/min,y/min,x/max,y/max)"
9else{x = x" y = y"code = calcode(x ,y ,x/min,y/min,x/max,y/max)"999 /hile( done == )"
i*(acce t) line(x ,y ,x ,y )"
rectangle(x/min,y/min,x/max,y/max)"
getch()"
9-1222222222222222222222222222222222222222222222222222222222222222222221-
int calcode (x,y,x/min,y/min,x/max,y/max)*loat x,y,x/min,y/min,x/max,y/max"{int code = "
i*(y> y/max)code S=T@R"else i*( y<y/min)code S= F@TT@;"
33
8/19/2019 Tashu.docx
http://slidepdf.com/reader/full/tashudocx 34/62
else i*(x > x/max)code S= GBT"else i* ( x< x/min)code S= E?T"
return(code)"9
-122222222222222222222222222222222222222222222222221-
Hoid main(){
*loat x!,y!,x ,y ,x/min,y/min,x/max,y/max"
int gd,gm"int i"
detectgra h($gd,$gm)"initgra h($gd,$gm,%C&''tur oc '' gi%)"
rint*(%'n'n'tEnter the co2ordinates o* ine &%)"
rint*(%'n'n'tU J & %)"scan*(%+* +*%,$x ,$y )"
rint*(%'n'n'tU! J! & %)"scan*(%+* +*%,$x!,$y!)"
rint*(%'n'tEnter the co ordinates o* /indo/ &'n %)" rint*(%'n'tx/min , y/min & %)"scan*(%+* +*%,$x/min,$y/min)"
rint*(%'n'tx/max , y/max & %)"scan*(%+* +*%,$x/max,$y/max)"line(x ,y ,x!,y!)"rectangle(x/min,y/min,x/max,y/max)"delay(! )"setcolor(i- )"settextstyle(:; ?@AT,B@ D ,8)"outtextxy( 7 ,4 ,%;ade Fy Tashu Aan/al%)"getch()"cleardeHice()"
34
8/19/2019 Tashu.docx
http://slidepdf.com/reader/full/tashudocx 35/62
linecli (x ,y ,x!,y!,x/min,y/min,x/max,y/max )"getch()"closegra h()"
9
Output :
35
8/19/2019 Tashu.docx
http://slidepdf.com/reader/full/tashudocx 36/62
36
8/19/2019 Tashu.docx
http://slidepdf.com/reader/full/tashudocx 37/62
12. Program to show ine $lipping using iang !ars/0.
#include<gra hics.h>
#include<dos.h>#include<conio.h>#include<stdli .h>
Hoid main(){int gd, gm "int x , y , x! , y! "int /xmin,/ymin,/xmax, /ymax "*loat u = . ,u! = . "int , , ! , ! , , , 4 , 4 "*loat r , r! , r , r4 "int x , y , x!! , y!! "clrscr()"
rint*(%Enter the /indo/s le*t xmin , to oundry ymin'n%)"scan*(%+d+d%,$/xmin,$/ymin)"
rint*(%Enter the /indo/s right xmax , ottom oundry ymax'n%)"scan*(%+d+d%,$/xmax,$/ymax)"
rint*(%Enter line x , y co2ordinate'n%)"scan*(%+d+d%,$x ,$y )"
rint*(%Enter line x! , y! co2ordinate'n%)"scan*(%+d+d%,$x!,$y!)"
rint*(%liang arsNy ex ress these 4 ine ualities using l N<= N'n%)" = 2(x! 2 x )" = x 2 /xmin " ! = ( x! 2 x ) " ! = /xmax 2 x " = 2 ( y! 2 y ) " = y 2 /ymin " 4 = ( y! 2 y ) " 4 = /ymax 2 y " rint*(% = line is arallel to le*t cli ing'n%)" rint*(% != line is arallel to right cli ing'n%)"
rint*(% = line is arallel to ottom cli ing'n%)" rint*(% 4= line is arallel to to cli ing'n%)"
i*( ( ( == . ) $$ ( < . ) ) SS( ( ! == . ) $$ ( ! < . ) ) SS( ( == . ) $$ ( < . ) ) SS( ( 4 == . ) $$ ( 4 < . ) ) )
37
8/19/2019 Tashu.docx
http://slidepdf.com/reader/full/tashudocx 38/62
{ rint*(% ine is reMected'n%)"getch()"detectgra h($gd,$gm)"initgra h($gd,$gm,%c&''tc'' gi%)"setcolor( ED)"rectangle(/xmin,/ymax,/xmax,/ymin)"setcolor(F IE)"line(x ,y ,x!,y!)"getch()"setcolor(KB TE)"line(x ,y ,x!,y!)"getch()"9
else{i*( 0= . ){r =(*loat) - "i*( < )u = max(r , u )"elseu! = min(r , u! )"9
i*( ! 0= . ){r! = (*loat ) ! - ! "i*( ! < )u = max(r! , u )"elseu! = min(r! , u! )"
9i*( 0= . ){r = (*loat ) - "i*( < )u = max(r , u )"elseu! = min(r , u! )"9
38
8/19/2019 Tashu.docx
http://slidepdf.com/reader/full/tashudocx 39/62
i*( 4 0= . ){r4 = (*loat ) 4 - 4 "i*( 4 < )u = max(r4 , u )"elseu! = min(r4 , u! )"9
i*( u > u! ) rint*(%line reMected'n%)"else{x = x 3 u 1 ( x! 2 x ) "
y = y 3 u 1 ( y! 2 y ) "
x!! = x 3 u! 1 ( x! 2 x )"y!! = y 3 u! 1 ( y! 2 y )"
rint*(%@riginal line cordinates'n%)" rint*(%x = +d , y = +d, x! = +d, y! = +d'n%,x ,y ,x!,y!)" rint*(%Kindo/s coordinate are 'n%)" rint*(%/xmin = +d, /ymin = +d,/xmax = +d , /ymax = +d%,/xmin,/ymin,/xmax,/ymax)"
rint*(%Ae/ coordinates are 'n%)" rint*(%x = +d, y = +d,x! = +d , y! = +d'n%,x ,y ,x!!,y!!)"detectgra h($gd,$gm)"initgra h($gd,$gm,%C&''tur oc '' gi%)"setcolor(!)"rectangle(/xmin,/ymax,/xmax,/ymin)"setcolor( )"line(x ,y ,x!,y!)"delay(! )"setcolor(i- )"settextstyle(:; ?@AT,B@ D ,8)"outtextxy( 7 ,4 ,%;ade Fy Tashu Aan/al%)"getch()"setcolor( )"line(x ,y ,x!,y!)"setcolor( )"
39
8/19/2019 Tashu.docx
http://slidepdf.com/reader/full/tashudocx 40/62
line(x ,y ,x!!,y!!)"getch()"
999
OUTPUT :
40
8/19/2019 Tashu.docx
http://slidepdf.com/reader/full/tashudocx 41/62
13. Program to show Pol0gon clipping.
#include<stdio.h>#include<conio.h>
#include<gra hics.h>#de*ine round(a) ((int)(a3 .5))int N"*loat xmin,ymin,xmax,ymax,arrV! W,m"
Hoid cli l(*loat x ,*loat y ,*loat x!,*loat y!){i*(x!2x )m=(y!2y )-(x!2x )"i*(x >=xmin $$ x!>=xmin)
{arrVNW=x!"arrVN3 W=y!"N3=!"9i*(x <xmin $$ x!>=xmin){arrVNW=xmin"arrVN3 W=y 3m1(xmin2x )"arrVN3!W=x!"arrVN3 W=y!"N3=4"9i*(x >=xmin $$ x!<xmin){arrVNW=xmin"arrVN3 W=y 3m1(xmin2x )"N3=!"9
9
Hoid cli t(*loat x ,*loat y ,*loat x!,*loat y!){i*(y!2y )m=(x!2x )-(y!2y )"i*(y <=ymax $$ y!<=ymax)
41
8/19/2019 Tashu.docx
http://slidepdf.com/reader/full/tashudocx 42/62
{arrVNW=x!"arrVN3 W=y!"N3=!"9i*(y >ymax $$ y!<=ymax){arrVNW=x 3m1(ymax2y )"arrVN3 W=ymax"arrVN3!W=x!"arrVN3 W=y!"N3=4"9i*(y <=ymax $$ y!>ymax)
{arrVNW=x 3m1(ymax2y )"arrVN3 W=ymax"N3=!"99
Hoid cli r(*loat x ,*loat y ,*loat x!,*loat y!){i*(x!2x )
m=(y!2y )-(x!2x )"i*(x <=xmax $$ x!<=xmax){arrVNW=x!"arrVN3 W=y!"N3=!"9i*(x >xmax $$ x!<=xmax){arrVNW=xmax"arrVN3 W=y 3m1(xmax2x )"arrVN3!W=x!"arrVN3 W=y!"N3=4"9i*(x <=xmax $$ x!>xmax){
42
8/19/2019 Tashu.docx
http://slidepdf.com/reader/full/tashudocx 43/62
arrVNW=xmax"arrVN3 W=y 3m1(xmax2x )"N3=!"99
Hoid cli (*loat x ,*loat y ,*loat x!,*loat y!){i*(y!2y )m=(x!2x )-(y!2y )"i*(y >=ymin $$ y!>=ymin){arrVNW=x!"arrVN3 W=y!"
N3=!"9i*(y <ymin $$ y!>=ymin){arrVNW=x 3m1(ymin2y )"arrVN3 W=ymin"arrVN3!W=x!"arrVN3 W=y!"N3=4"9
i*(y >=ymin $$ y!<ymin){arrVNW=x 3m1(ymin2y )"arrVN3 W=ymin"N3=!"99
Hoid main(){int gdriHer=DETECT,gmode,n, olyV! W,i"*loat xi,yi,x*,y*, olyyV! W"clrscr()"
rint*(%Coordinates o* rectangular cli /indo/ &'nxmin,ymin&%)"scan*(%+*+*%,$xmin,$ymin)"
rint*(%Coordinates o* rectangular cli /indo/ &'nxmax,ymax&%)"scan*(%+*+*%,$xmax,$ymax)"
43
8/19/2019 Tashu.docx
http://slidepdf.com/reader/full/tashudocx 44/62
rint*(%'n'nRolygon to e cli ed &'nAum er o* sides &%)"scan*(%+d%,$n)"
rint*(%Enter the coordinates &%)"*or (i= "i<!1n"i33)scan*(%+*%,$ olyyViW)"
olyyViW= olyyV W" olyyVi3 W= olyyV W"*or(i= "i<!1n3!"i33)
olyViW=round( olyyViW)"initgra h($gdriHer,$gmode,%C&''tur oc '' gi%)"rectangle(xmin,ymax,xmax,ymin)"
rint*(%'tIAC RRED R@ JG@A%)" rint*(%hi%)"*ill oly(n, oly)"
getch()"cleardeHice()"N= "*or(i= "i<!1n"i3=!)cli l( olyyViW, olyyVi3 W, olyyVi3!W, olyyVi3 W)"n=N-!"*or(i= "i<N"i33)
olyyViW=arrViW" olyyViW= olyyV W" olyyVi3 W= olyyV W"
N= "*or(i= "i<!1n"i3=!)cli t( olyyViW, olyyVi3 W, olyyVi3!W, olyyVi3 W)"n=N-!"*or(i= "i<N"i33)
olyyViW=arrViW" olyyViW= olyyV W" olyyVi3 W= olyyV W"N= "*or(i= "i<!1n"i3=!)cli r( olyyViW, olyyVi3 W, olyyVi3!W, olyyVi3 W)"n=N-!"*or(i= "i<N"i33)
olyyViW=arrViW" olyyViW= olyyV W" olyyVi3 W= olyyV W"N= "
44
8/19/2019 Tashu.docx
http://slidepdf.com/reader/full/tashudocx 45/62
*or(i= "i<!1n"i3=!)cli ( olyyViW, olyyVi3 W, olyyVi3!W, olyyVi3 W)"*or(i= "i<N"i33)
olyViW=round(arrViW)"i*(N)*ill oly(N-!, oly)"rectangle(xmin,ymax,xmax,ymin)"
rint*(%'tC RRED R@ JG@A%)"delay(! )"setcolor(i- )"settextstyle(:; ?@AT,B@ D ,8)"outtextxy( 7 ,4 ,%;ade Fy Tashu Aan/al%)"getch()"closegra h()"
9
OUTPUT:
45
8/19/2019 Tashu.docx
http://slidepdf.com/reader/full/tashudocx 46/62
1". Program to show Mouse Programming.
46
8/19/2019 Tashu.docx
http://slidepdf.com/reader/full/tashudocx 47/62
#include<gra hics.h>#include<conio.h>#include<stdio.h>#include<dos.h>int initmouse()"Hoid sho/mouse tr()"Hoid hidemouse tr()"Hoid getmouse os(int1,int1,int1)"union EG: i, o"main(){ int gd = DETECT, gm, status, utton, x, y, tem x, tem y" int x ,y ,x*,y*"
char arrayV5 W"
initgra h($gd,$gm,%C&''Tur oc ''FG %)" settextstyle(DE? I T ?@AT, ,!)" status = initmouse()" i* ( status == ) rint*(%;ouse su ort not aHaila le.'n%)" else { sho/mouse tr()" getmouse os($ utton,$x,$y)" tem x = x" tem y = y" /hile(0N hit()) {
getmouse os($ utton,$x,$y)"
i*( x == tem x $$ y == tem y ) {9
else { cleardeHice()"delay(! )"
setcolor(i- )"settextstyle(:; ?@AT,B@ D ,8)"outtextxy( 7 ,4 ,%;ade Fy Tashu Aan/al%)"
47
8/19/2019 Tashu.docx
http://slidepdf.com/reader/full/tashudocx 48/62
s rint*(array,%U = +d, J = +d%,x,y)" outtext(array)" tem x = x"
tem y = y" 9 9 9 getch()" return "9int initmouse(){ i.x.ax = " int86( U ,$i,$o)"
return ( o.x.ax )"9Hoid sho/mouse tr(){ i.x.ax = " int86( U ,$i,$o)"9Hoid getmouse os(int 1 utton, int 1x, int 1y){ i.x.ax = "
int86( U ,$i,$o)" 1 utton = o.x. x" 1x = o.x.cx" 1y = o.x.dx"9
OUTPUT :
48
8/19/2019 Tashu.docx
http://slidepdf.com/reader/full/tashudocx 49/62
49
8/19/2019 Tashu.docx
http://slidepdf.com/reader/full/tashudocx 50/62
1#. -rite a program to draw !e ier' Sur)ace
#include<stdio.h>#include<conio.h>
#include<gra hics.h>Hoid main(){int gd,gm, x ,x!,x ,x4,y ,y!,y ,y4,y ,y!!,y ,y44,i"gd=DETECT,gm=DETECT"clrscr()"initgra h($gd,$gm,%C&''tur oc '' gi%)"x = "x!= "x = 7 "x4=! "y = 5 "y!= 6 "y = 6 "x4= 65"line(x ,y ,x!,y!)"line(x!,y!,x ,y )"
line(x ,y ,x4,y4)"y =y "y!!=y!"y =y "y44=y4"*or(i= "i<5"i33){y =y 3 "y!!=y!!3 "y =y 3 "y44=y443 "line(x ,y ,x!,y!!)"line(x!,y!!,x ,y )"line(x ,y ,x4,y44)"9line(x ,y ,x ,y )"line(x!,y!,x!,y!!)"line(x ,y ,x ,y )"line(x4,y4,x4,y44)"
delay(! )"setcolor(i- )"settextstyle(:; ?@AT,B@ D ,8)"outtextxy( 7 ,4 ,%;ade Fy Tashu Aan/al%)"getch()"closegra h()"9
50
8/19/2019 Tashu.docx
http://slidepdf.com/reader/full/tashudocx 51/62
OUTPUT :
51
8/19/2019 Tashu.docx
http://slidepdf.com/reader/full/tashudocx 52/62
1%. Program to show Perspecti,e Pro ection o) a 3D o ect.
#include<stdio.h>#include<math.h>#include<gra hics.h>
Hoid main(){int gd=DETECT,gm"int x ,y ,x!,y!"int ymax,aV4WV8W"*loat arV4WV4W, V4WV8W"int i,M,N,m,n, "int x , y , O , x, y, O"aV WV W = " aV WV W = " aV!WV W = 2 "aV WV W = ! " aV WV W = " aV!WV W = 2 "aV WV!W = ! " aV WV!W = ! " aV!WV!W = 2 "
aV WV W = " aV WV W = ! " aV!WV W = 2 "aV WV4W = " aV WV4W = " aV!WV4W = 2! "aV WV5W = ! " aV WV5W = " aV!WV5W = 2! "aV WV6W = ! " aV WV6W = ! " aV!WV6W = 2! "aV WV7W = " aV WV7W = ! " aV!WV7W = 2! "detectgra h($gd,$gm)"initgra h($gd,$gm, %C&''tur oc '' gi%)"ymax = getmaxy()"x = " y = ! " O = "
*or(M= " M<8" M33)
{x = aV WVMW" y = aV WVMW" O = aV!WVMW"
V WVMW = x 2 ( (*loat)( x 2 x )-(O 2 O )) 1 (O )" V WVMW = y 2 ( (*loat)( y 2 y )-(O 2 O )) 1 (O )"9
-12 *ront lane dis lay 21-
*or(M= "M< "M33){
x =(int) V WVMW" y =(int) V WVMW"x!=(int) V WVM3 W" y!=(int) V WVM3 W"line( x ,ymax2y ,x!,ymax2y!)"9x =(int) V WV W" y =(int) V WV W"x!=(int) V WV W" y!=(int) V WV W"line( x , ymax2y , x!, ymax2y!)"
52
8/19/2019 Tashu.docx
http://slidepdf.com/reader/full/tashudocx 53/62
-12 acN lane dis lay 21-
setcolor( )"*or(M=4"M<7"M33){
x =(int) V WVMW" y =(int) V WVMW"x!=(int) V WVM3 W" y!=(int) V WVM3 W"line( x , ymax2y , x!, ymax2y!)"9x =(int) V WV7W" y =(int) V WV7W"x!=(int) V WV4W" y!=(int) V WV4W"line( x , ymax2y , x!, ymax2y!)"setcolor(7)"delay(! )"setcolor(i- )"settextstyle(:; ?@AT,B@ D ,8)"
outtextxy( 7 ,4 ,%;ade Fy Tashu Aan/al%)"*or(i= "i<4"i33){x =(int) V WViW" y =(int) V WViW"x!=(int) V WV43iW" y!=(int) V WV43iW"line( x , ymax2y , x!, ymax2y!)"9getch()"closegra h()"9
53
8/19/2019 Tashu.docx
http://slidepdf.com/reader/full/tashudocx 54/62
OUTPUT :
54
8/19/2019 Tashu.docx
http://slidepdf.com/reader/full/tashudocx 55/62
1&. Program to show Animation
#include<conio.h>#include<gra hics.h>
#include<stdio.h>#include<math.h>Hoid main(){int gd,gm"int x,y"int i,M,NN"
detectgra h($gd,$gm)"initgra h($gd,$gm,%C&''tur oc '' gi%)"
setcolor(KB TE)"line( ,4 ,64 ,4 )"rectangle( , , 4 ,4 )"rectangle( , ! , , )"setcolor(4)"line( L,!8 , L, L8)"line( ! ,!8 , ! , L8)"rectangle( ! ,!8 , , )"outtextxy( 4 ,!8 ,%R E:: AJ XEJ T@ GA TE TBE @CXET%)"getch()"*or(M=4 "M<64 "M33){cleardeHice()"setcolor(KB TE)"line( ,M,64 ,M)"rectangle( ,M27 , 4 ,M)"rectangle( ,M28 , ,M27 )"
setcolor( ED)"line( L,!8 , L,4 )"line( ! ,!8 , ! ,4 )"rectangle( ! ,!8 , , )"
setcolor(JE @K)"circle( !5, ,!)"
55
8/19/2019 Tashu.docx
http://slidepdf.com/reader/full/tashudocx 56/62
delay(5)"9
*or(i=4 "i> 4 "i22){cleardeHice()"
setcolor( ED)"line( L,i, L,i2 ! )"line( ! ,i, ! ,i2 ! )"rectangle( ! ,i2 ! , ,i2 )"
setcolor(JE @K)"
circle( !5,i2 ,!)"delay(!5)"9
cleardeHice()"NN= "*or(M= "M< 5 "M33){i*(M+! == ){
setcolor(NN)"NN=NN3 "delay(5 )"9elli se( ! , , , 6 ,M3 ,M3 )"9*or(M= "M< 5 "M33){i*(M+! == ){setcolor(F CX)"delay(!)"9elli se( ! , , , 6 ,M3 ,M3 )"9cleardeHice()"*or(i= "i<7 "i33)
56
8/19/2019 Tashu.docx
http://slidepdf.com/reader/full/tashudocx 57/62
{setcolor(i)"settextstyle(G@TB C ?@AT,B@ D ,6)"outtextxy( , 5 ,%;ade Fy Tashu Aan/al%)"delay(L )"9
getch()"9
OUTPUT :
57
8/19/2019 Tashu.docx
http://slidepdf.com/reader/full/tashudocx 58/62
58
8/19/2019 Tashu.docx
http://slidepdf.com/reader/full/tashudocx 59/62
M45O6 P6O78$T O5SM4 89
using circle 0 Polar $o'ordinates ;
#include<stdio.h>#include<conio.h>
#include<gra hics.h>#include<math.h>int main(){int gd=DETECT,gm"int xc,yc,r,x ,x!,y ,i"
initgra h($gd,$gm,%C&''tur oc '' gi%)" rint*(%enter the center oints%)"scan*(%+d'n+d%,$xc,$yc)"
rint*(%enter the radius%)"
scan*(%+d%,$r)"--setcolor(KB TE)"setcolor( 5) "circle(!7 , 5 , 5)"
setcolor( )"
circle(!7 , 5 ,5)"
59
8/19/2019 Tashu.docx
http://slidepdf.com/reader/full/tashudocx 60/62
setcolor( 5)"
--set*illstyle(:@ D ? ,KB TE)"--*lood*ill(!7 , 5 ,KB TE)"
--setcolor(KB TE)"
circle( , 5 , 5)"
setcolor( )" circle( , 5 ,5)" setcolor( )"--set*illstyle(:@ D ? ,KB TE)"--*lood*ill( , 5 ,KB TE)"
circle( ,! , )"--setcolor( ED)"setcolor(4)"elli se( ,! , 8 , 6 ,6 ,5 )"--*lood*ill( ,! , ED)"
x = "y =r"*or(i=L "i>=45"i22){x =r1cos(i)"y =r1sin(i)"
ut ixel(x 3xc,y 3yc, ED)" ut ixel(y 3xc,x 3yc,G EEA)" ut ixel(2y 3xc,x 3yc,F IE)" ut ixel(2x 3xc,y 3yc,JE @K)" ut ixel(2x 3xc,2y 3yc, ED)" ut ixel(2y 3xc,2x 3yc,G EEA)" ut ixel(y 3xc,2x 3yc,F IE)" ut ixel(x 3xc,2y 3yc,JE @K)"x 33"9delay(! )"setcolor(!)"settextstyle(: A: :E ? ?@AT,B@ D ,5)"outtextxy( , ,%;ade Fy &2%)"setcolor( 4)"settextstyle(: A: :E ? ?@AT,B@ D ,5)"outtextxy( , 5 ,%Tashu Aan/al%)"
60
8/19/2019 Tashu.docx
http://slidepdf.com/reader/full/tashudocx 61/62
getch()"closegra h()"return( )"9
OUTPUT :
61
8/19/2019 Tashu.docx
http://slidepdf.com/reader/full/tashudocx 62/62