Vous êtes sur la page 1sur 66
Computer Graphics Lab Manual [Type text] ‘CSE/6"/CG Lab/Prepared by Vivek Kumar Sinha NIVE) 1. Implementation of line drawing , cirele drawing & cllipse algorithm, ITY SYLLABUS FOR PRACTICA! 2, Programs to implement 2D transfarmation( Line, Cube , Rectangle) © Scaling * Translation + Rotation 3. Program to implement simple clipping algorithm, Implementation of Bezier Curve, [Type text] CSE/6"/CG Lab/Prepared by Vivek Kumar Sinha List Of Experiments 1, Weite a program to draw the pixel(x,y) and display the color in which pixel(x.y) is illuminated on the screen, 2, Write a program to- implement DDA line drawing algorithm. 3. Write a program to implement Bresenham’s Line drawing algorithm, 4, Write a program to implement Bresenham’s Cirele drawing algorithm. 5. Write a program to implement Bresenham’s Ellips drawing algorithm, 6. Write a program to ent Boundary Fill algorithm. 7. Write a program to implement Flood Fill algorithm, 8 Write a program to Draw Rectangle from (100,200) pixel to (400,500) pixel . 9. Write a program to draw a Circle with center (150,150) pixel and radius 25. 1, Write a program to draw a Hexagon on the screen, Mh. Write a program to implement Composite Transformations. 12. Write a program to implement Basic Transformations (translation rotation , and scaling on a rectangle). 13. Write a program to implement Cohen Sutherland algorithm: 14. Write a program to implement Bezier Curve. 15, Write a program to implement B-Spline Curve. 16, — Write a program fo implement animation using © function, 17, Write a program to implement a cartoon using C function, 18, Write a program to draw a chain of eire 19, Write a program to draw concentric circles. 20. Write a program to fill an ellipse by reducing the size of an ellipse. [Type text] ‘CSE/6"/CG Lab/Prepared by Vivek Kumar Sinha EXPERI Ni I AIM : Write a program to draw the pixel(xy) a pixel(x,y) is illuminated on the screen, display the color in which DESCRIPTION: With the help of this program ,we are going to draw a Pixel(x,y) and also displaying the olor in which this pixel(x.y) is illuminated on the screen. PROGRAM Hinkcude #include finelude Void main() ‘ int gd=DETECT, gm; initgraph( & gm dad putpixel(100,200,R imgetpixcl( 100,20 printi(“The color of printtt%d".i); getch(); \\te\\ba: 100,200,RED ourpur ‘The color of pixel is : 4 (RED) VIVA -VOCE QUESTIONS What are the parameters ofinitgraph0. What is graphies driver. What is graphics mode. Define the function of putpixel the function of getpixel. [Type text] ‘CSE/6"/CG Lab/Prepared by Vivek Kumar Sinha EXPERI Ni 2. AIM :Write a program to implement DDA line drawing algorithm. DESCRIPTION: Digital Differential Analyzer (DDA) Method ‘The basis of the DDA method is to take unit steps along one coordinate and compute the corresponding values along the other coordinate, The unit steps are always along the coordinate of greatest change, e.g. if dx = 10. and dy = 5, then we would take unit steps along x and compute the steps along y. ALGORITHM input line endpoints, (xa,ya) and (xb, yb) 1. set pixel at position (xa,ya) 3. calculate slope m 4. Case |mjs1: repeat the following steps until (xb, yb) is reached: i yitl dy/ dx xitl=xi+1 ii. set pixel at position (xi+1,Round(yi+1)) 5, Case |m>1; repeat the following steps until (xn, yn) is reached: xitL = xi + dx/ dy i, yt =yi Ft set pixel at position (Round(xi+1), yi+1 PROGRAM ude < graphics. > # define Round (a) (int (a+0.5)) void main() { int xa, ya, xb,yb , dx , dy, steps ,k float Xiner , Yiner , X,Y ; int gd=DETECT , gm ; initgraph ( &gd,, Sem, “\tellbgi”) ; printf ( “Enter the value of (xa , ya ) & (xb, yb)") : scanf ( “Yed%d%d%d", &xa Aeya , &xb , &yb): [Type text] ‘CSE/6"/CG Lab/Prepared by Vivek Kumar Sinha X=xa;¥=yb; dx = xb—xa; dy =yb-ya; sleardevice (5 if (abs (dx) > abs (dy) steps = abs (dx) ; else steps = abs (dy) + Xiner = dx / (Moat) steps ; Yiner = dy / (Moai) steps ; putpixe! (Round (x), Round (y), RED) ; for (k= 0; k < steps: k++) ( X= x + Xiner; Y=y+ Viner ; putpixel ( Round (x). Round (y) , RED) ; } getch(); ‘closegraph () } [Type text] ‘CSE/6"/CG Lab/Prepared by Vivek Kumar Sinha INPUT. Enter the value of (xa, ya) & (xb , yb) = 190 42 25 200 ourTPUT VIVA—VOCE QUESTIONS Define DDA algorithm. What is abs function? . Why we use steps? ' 2 3 [Type text] ‘CSE/6"/CG Lab/Prepared by Vivek Kumar Sinha [Type text] ‘CSE/6"/CG Lab/Prepared by Vivek Kumar Sinha EXPERI NT AIM :Write a program to implement Bresenham's line drawing algorithm, DESCRIPTION:In this method, developed by Jack Bresenham, we look at just the center of the pixels, We determine dl and d2 which is the "error", ic, the difference from the " true line”, true line a2 Xi =Xi+1 Steps in the Bresenharn algorithm: 1, Determine the error terms: 2. Define a relative error term such that the sign of this term tells us which pixel to choose 3. Derive equation to compute successive error terms from first 4. Compute first error term ALGORITHM 1. Input fine endpoints, (x0,y0) and (xn, yn) 2. Calculate Ax= xn «x0 and Ay = yn = y 3. Calculate parameter pO = 2 Ay - Ax 4© Set pixel at position (x0,y0) 3 6 Repeat the following steps u if pi <0 Set the next pixel at position (xi +1, yi ) Calculate new pit = pi +2 Ay 1 (xn, yn) is reached: 7. ifpiz0 Set the next pixel at position (xi +1, yi + 1) Calculate new pi = pi + 2(Ay - Ax) PROGRAM CSE/6"/CG Lab/Prepared by Vivek Kumar Sinha void main () ‘ int Xa, Ya, Xb, Yb; im ds .dy.ps int twody , twodydx ; int x.y, Xend ; int gd=DETECT , gm ; initgraph ( &gd , &gm , “\tei\bgi”) ; printf (“Enter the value of (Xa , Ya) & (Xb. Yb)"); seanf (“tod %od %d %d", &Xa LY A, KX, KYB); dx = abs (Xb - Xa) ; dy = abs ( Yb- Ya) 5 pa2*dy-dx; twody=2 * dy; twodydx = 2 * (dy -dxy 5 ‘if ( Xa> Xb) t X= Xb; Vie Ya; Xend = else . 1 X=xa¥=¥i Xend = Xb; 1 while (x # include void circle ( int , int ‘void main () ( intx.y.parsis ‘int gd=DETECT , gm; initgraph ( &gd , &gm , [Type text] e\bgi") ; ‘CSE/6"/CG Lab/Prepared by Vivek Kumar Sinha setbkcolor (WHITE) ; printf (“Enter the radius =") seanf (“Yd der): x=0:y=r; p-3-2¢r: putpixel (x,y, RED); while (x<=y) { if(p <0) pred*x +6; else pe=4*(x-yy*10; yess ) xt cirele p (x.y): } getch (): closegraph (); } void circle p (int a, intb) t imtx ys [Type text] ‘CSE/6"/CG Lab/Prepared by Vivek Kumar Sinha x=asy=b; puipixel (300+ x, 300+y,1) ; purpixel (300+ y, 300+, 1) 5 puipixel (300-x 300% y,1) puipixel (300 +x ,300-y,1) 5 puipinel (300-x 300-1) 5 putpixel (300-y ,300-x, 1) 5 purpixel (300+y 300-1) ; puipixel (300-y ,3004x.1) ; ‘ geteh () ) INPUT Enter the radius = 80 OUTPUT VIVA~VOCE QUESTIONS 1. How many parameters 2. Why we calculate the init asp0= 5/4—r=1—r? required to draw the circle? | value of the decision parameter [Type text] ‘CSE/6"/CG Lab/Prepared by Vivek Kumar Sinha 3. What is symmetry points? 4, What is plot points? 5. What is circle mid point? [Type text] ‘CSE/6"/CG Lab/Prepared by Vivek Kumar Sinha EXPERIMENT NO. 05 AIM :Write a program to implement Bresenham’s ellipse algorithm. DESCRIPTION: We only need to calculate the values on the border of the ci ein the first octant, The other values may be determined by symmetry, Assume a circle of radius r with center at (0,0). ALGORITHM ae Input rr, and ellipse center(x,,y,) and obtain the first point on an ellipse centered on the origin as Gro.y)=(045) Calculate the initial value of the decision parameter in region | as Ploe=r, Py + hr n in region 1, starting at k=O perform the following test: If ph, along the ellipse centered on (0,0) i8:x..1,y1) and Phau = plit 27 Ree + Otherwise the next point along the circle is (X.-),yx) and Phu = ple2Pn Py Fy With 2wPyhess BP K+ IP, 2Paym 2h, Caleulate the initial-value of the decision parameter in region 2 using the last point (xi) calculated in region | as Poe, (409 1/2) (yee)? = Py ‘Ateach ye position in region 2 , starting at k=0 perform the following test: IF p20, the next point along the ellipse centered on (0,0) is (X,Y) and Pa.) ptr y rt Otherwise , the next point along the circle is (aa.1,y.1) and P21 =PAtQ yee — BPagner + Using the same incremental calculations forx and y as in region | Determine symmetry points in the other three quadrants. Move each calculated pixel position (x.y) onto the elliptical path centered on(,y.) and plot the coordinated values [Type text] CSE/6"/CG Lab/Prepared by Vivek Kumar Sinha TAK Ye 8. Repeat the steps for region F until 2° x>=2P.y PROGRAM void ellipse ( int , int ) ; void main () { inta, intx=O,y; int aa, bb , aa2 , bb2; int k=O. ys int p; int gd=DETECT , gm ; initgraph ( &gd , &gm , “\te\\bei*) printf (“*\n Enter the value of a and b) ; seanf (“tod %od”., &a, &b); y=bjaa=a"a; bb=b* b;aa2=an #2; bb? = bb * 2; fy=aa2 *b; p= bb—(aa* b)+(0.25 * aa) 5 while ( fx < fy) x fix = fe +bb2; [Type text] CSE/6"/CG Lab/Prepared by Vivek Kumar Sinha if(p<0) p+=fx+bb; else ( y- 1 } aH circle p(x.y): 3 getch () ; closegraph ( ) ; ) ‘void circle pinta ,int b) t int xy x-ayy=b; putpixel (300+ x, 30049 ,1) ; putpixel (300 y, 300% x,1) 3 putpixel (300-x 300% y,1) 5 puipinel (300+ x ,300-y,1) putpixel (300-x ,300-y,1) [Type text] ‘CSE/6"/CG Lab/Prepared by Vivek Kumar Sinha putpixel (300 -y ,300-%, 1) ; puipixel (300+y, 300-1) ; putpixel (300-y ,3004x,1) 3 geteh¢ as ) INPUT Enter the value of a and b = 16 25 OUTPUT VIVA—VOCE QUESTIONS Define region in ellipse. Define ellipse mid point? What do you mean by gm? What is putpixel() & getpixel()? What do you mean by decision parameter? yeep [Type text] ‘CSE/6"/CG Lab/Prepared by Vivek Kumar Sinha [Type text] ‘CSE/6"/CG Lab/Prepared by Vivek Kumar Sinha EXPERIMENT. 06 AIM :Write a program to implement Boundary fill algorithm, DESCRIPTION : Siari at a point inside the figure and paint with a particular color. Filling continues until a boundary color is encountered, oO OeA oO ALGORITHM ata point side a region, + Paint the interior outward to the edge. The edge must be specified in.a single color. Fill the 4. re connected or 8-conni ted region. connected fill is faster, but can have problems: see e eee @e e008 ecco PROGRAM # include # include < conio.h > # include < graphics.h > void bfill (int x, int y , int fil, int boundary ) ; void main () Int bfill , boundary ; [Type text] CSE/6"/CG Lab/Prepared by Vivek Kumar Sinha int gd=DETECT , gm ; initgraph ( &gd , &em , “\te\bgi") ; setcolor (WHITE ); getch (): bfill (22,22 .RED , WHITE); closegraph () ; 4 ‘void bfill ( int x, int y int fill boundary) { int eurrent ; current = getpixel (x,y); if (current ! boundary && current | setcolor (ill); purpixel (xy sill); puipixel (x. fill); bhill (x1 ,y, fill , boundary) ; bfill(x~ 1, y, fill , boundary) ; bfill (x.y +1, fill, boundary) ; bail (x ,y- 1 , fill, boundary) ; [Type text] ‘CSE/6"/CG Lab/Prepared by Vivek Kumar Sinha ouTPUT VIVA—VOCE QUESTIONS Define Boundary Fill Algorithm? How many parameters are required in Boundary Fill Algorithm? Define the 4-connected region, Define the 8-connected region, BeRS [Type text] ‘CSE/6"/CG Lab/Prepared by Vivek Kumar Sinha [Type text] ‘CSE/6"/CG Lab/Prepared by Vivek Kumar Sinha EXPERI 07 AIM :Write a program to implement Flood fill algorithm. DESCRIPTION: The user speciies an interior color to be replaced by fill calor (use 4 or 8 fill method). The process stops when no adjacent pixels are of interior color, ¢.g., replace white with blue. Vow But, even worse for overlapping polygons Same result as before, but no eure, In general the Sean Conversion method is the most versatile. ALGORITHM + Used when an area defined with multiple color boundaries * Start ata point inside region + Replace a specified interior color (old color) with fill color + Fill the 4-connected or 8-connected region until all interior points being replaced. PROGRAM ‘tinelude #inelude include void fTill( int x , int y , int fill, int boundary , int new , int old ) ; void main( ) { int fill , boundary , gd = DETECT , gm ; [ype text] CSE/6"/CG Lab/Prepared by Vivek Kumar Sinha initgraph (&gd , &gm eli setcolor ( WHITE ) : rectangle ( 20, 20 40,50); getch () 5 closegraph ( ); void FFll (int x ,int.y , int new , int old ) if (getpixel (x y = = old ) setcolor ( new}; putpixel (x.y .new ) ; ffill (x+ .y .new ,old ) ; ffill (x-1 .y new ald) NIE x y+) snew old ) ; AMIE .yel new old ) : ouTPUT VIVA—VOCE QUESTIONS [Type text] ‘CSE/6"/CG Lab/Prepared by Vivek Kumar Sinha L. Define Flood Fill Algorithm, 2. How many parameters are needed in Flood Fill Alorithm? 3. Define fillarea fiznction, [Type text] ‘CSE/6"/CG Lab/Prepared by Vivek Kumar Sinha EXPERI 0. 08 AIM :Write a program to draw Rectangle from (100,200) pixel to (400,500) pixel DESCRIPTION : In this program ave are going to draw a Rectangle having a pixel position from (100,200) pixel to (400,500) pixel. PROGRAM Hinclude #include #include #inelude main() ( int gd-DETECT,gm; initgraph(&gd.&em,"\\te\\bgi setpalette(0,3); maoveto( 100,200); -geteh(); restoreeetmode(); return; geteh()s ) OUTPUT VIVA—VOCE QUESTIONS 1. Expain all the parameters of initgraph(), 2. What do you mean by DETECT? 3. What is lineto and moveto function? [Type text] ‘CSE/6"/CG Lab/Prepared by Vivek Kumar Sinha [Type text] ‘CSE/6"/CG Lab/Prepared by Vivek Kumar Sinha EXPERI 0. 09 AIM : Write program to draw a Circle with center (150,150) pixel and radius 25, DESCRIPTION: With the help of this program ,we are going to draw a Cirele having a center (150,150) pixel. And radius of the circle is 25, PROGRAM #include #includesconio.h> #include #include Moat x1,yl,r; main() { int gd=DETECT.gm; initgraph(&gd.&em,"\\te\\bgi prinif("Enter the center 'x1'/1" and radius "?\n"); seanft"*6M6M%o",8ex 1 yl er); setpalette(0,12} /*background will change from O-block to 12*/ geteh(); seteolon(3); J*eircle will be drawn in 3-green coler*? scitcle(x Lye; geteh(); restoreertmode(); return; ourpur VIVA—VOCE QUESTIONS [Type text] CSE/6"/CG Lab/Prepared by Vivek Kumar Sinha What is setpalleite()? How many parameters are required to draw a circle? What is restorecrimode function? EXPERIMENT NO. 10 AIM :Write a program to draw a Hexagon on the sereen. DESCRIPTION: In this program , we are going to draw a hexagon on the screen using line(),moveto() & lineto(). PROGRAM #include Iudde #inelude #inelude define PI (22.0/7.0) main() ( int gd=DETECT.gm.x1. yl. initgraph(&gd,&em,"c:\tc\\bgi") seteolond x linetx! moveto(x2,y theta~60°PI/180.02 xe=cos(theta lineto(x2=s moveto(x2, lineto(x2=x2- moveto(x2,y linetog1 10,200), getch(); ) OFS y2=y2+50% Ke); [Type text] ‘CSE/6"/CG Lab/Prepared by Vivek Kumar Sinha OUTPUT VIVA—VOCE QUESTIONS [Type text] CSE/6"/CG Lab/Prepared by Vivek Kumar Sinha EXPERIMENT NO. 11 AIM :Write a program to implement Composite Transformation DESCRIPTION : A composite transformation is a sequence of transformations, For example, scaling followed by translation and rotation is a composite translation, The MultiplyTransform, RotateTransform, SealeTransform, and Translate Transform methods fare used to generate composite transformations, PROGRAM : include include #inelude void main( ) t int gd = DETECT , gm; intl, yl, x4 yt tyl 182) 192) elrser() initgraph (&gd , Rem ,"\we\bgi") rectangle (250 250250 , 250); printf ( “Enter the End Points”) ; scant (*9%6d %6d", Rex, ty! ); x1 = 250; x4 = 300; yl =230 ; y4 = 300; xlaxl+inl; yl=yl ttyl: xdexd tind; ydsydriyl: rectangle (x1, yl, x4 .y4); [Type text] ‘CSE/6"/CG Lab/Prepared by Vivek Kumar Sinha INPUT. getch () printf (‘* Enter the value” }; scant ("9d 96d”, &tx2 , Sety2 ); xD = x1 +02; xd = ad +002; yl =yl +ty2 syd = 94 +2; rectangle (xl ,yl,x4,y4); getch (); closegraph (): Enter the End Points 90 80 ouTPUT INPUT. Enter the value 30 40 OUTPUT || VIVA-QUESTIONS [Type text] ‘CSE/6"/CG Lab/Prepared by Vivek Kumar Sinha Define Composite Transformation. . What do you mean by DETECT? What do you mean by End points? EXPERIMENT NO. 12 AIM :Write a program to implement Basic Transformations ( translation , rotation, and scaling on a Rectangle). DESCRIPTION; Translation is one of the simplest transformations. A translation moves. all points of an object a fixed distance in a specified direction, Ttean also be expressed in terms of two frames by expressing the coordinate system of object in terms of translated frames, | Development of the Transformation in Terms of Frames. 2. Applying the Transformation Directly to the Local Coordinates ofa Point. ALGORITHM /*FOR SCALE (SX, SY) */ L.Anput the Sealing Factors SX, SY, 2.Calculate Scaled points by using Seal NewX=oldX * SX New’ Id¥*SY 3.Repeat step 2 for all points. 4.Draw the new seale usi new points. PROGRAM JA) SCALING// # include # include < conio.h > # include < graphies.h > void main ( ) t [Type text] ‘CSE/6"/CG Lab/Prepared by Vivek Kumar Sinha OUTPUT [Type text] float t; int gd = DETECT , gm ; int XT yl, x4, 4581, 8915 initgraph (.&gd , &gm , “\uel\bgi* ); x1= 30; y1 = 50 34-130; y4= 130 rectangle (x1, yl, x4, ¥4 5 getch (); cleardeviee () 5 printf (*\n Enter The Scaling Vector seanf(*%d Yd”, Sox, &esyl): xl=xl * exh; yl=yl *syl: xd x4 * sxl 5 y4=yd yl: rectangle (x1 vy]. x4. y4): getch (); closegraph ( ): CSE/6"/CG Lab/Prepared by Vivek Kumar Sinha INPUT. Enter The Sealing Vector: 23 ourTPUT ALGORITHM #*For Translate (TX, TY)*/ LAnput the Translation Factors TX, TY. 2.Calculate Translated points by using Translation Factors: NewX=oldX + TX NewY=ollY+TY 3.Repeat step 2 for all paints. 4.Draw the new rectangle using new points, PROGRAM [Type text] ‘CSE/6"/CG Lab/Prepared by Vivek Kumar Sinha 1 (B) TRANSLATION/ # include # include # include < graphies.h > void main () { float ts int gd= DETECT, gm; int x yl xd yin], ty initgraph ( ed , &em , “\te\\bgi”); printf (“ ‘The Four Co-ordinate For Rectangle :”) ; scant (al Sad od od”, x1, KYL, Red, yd); rectangle (x1, yl, x4, 4 )5 geteh (); sleardevice () ; ion Vector printf (* \n Enter The Transk scant (**%d%d ", &tx1, Styl); xESxd * txl; yl=yl ttyl; xd x4 x15 yd yd yl rectangle (x1, yl, x4, y4); getch (5 slosegraph (); [Type text] ‘CSE/6"/CG Lab/Prepared by Vivek Kumar Sinha INPUT. Enter The Four Co-ordinate For Rectangle : 50 50 100 100 OUTPUT ouTPUT ALGORITHM "FOR ROTATE (A)*/ Lnput the Rotation angel A, 2.Calculate rotated points by using Rotation angle: ldX cost — Old Y*sine> oldX*cos+OldY “cos New. New 3.Repeat step 2 for all points. 4.Draw the new roiation using new points [Type text] CSE/6"/CG Lab/Prepared by Vivek Kumar Sinha PROGRAM U(C) ROTATION// # include # include # include < graphies.h > # include < math.h > void main ( ) float t; im gd= DETECT, gm; ‘int x1 yl, x4, y4 initgraph ( &gd , &gm , “\tellbgi ) $ printf (‘" Enter Four Co-ordinates”); seanf (“%d Sd %d db, &x1, &yl , xd, ky); rectangle (X1, yloxd, y4 ): getch(): cleardevice () ; printf (“*\n Enter Angle For Rotation seanf(“%f", &t); T= (0829 3.14) / 3605 xb= (xt cos (t) yl *sin(1y); yl=(-xt*sin(t) + yl *e0s(1)); x4=(x4 * cos (1) +y4 * sin(t) }s y= (-x4* sin (t) + y4 * co (1))5 [Type text] ‘CSE/6"/CG Lab/Prepared by Vivek Kumar Sinha rectangle (x1, yl x4, y4); getch (5 slosegraph (); } INPUT. Enter Four Co-ordinates : - 50 50 110 110 ourPpUT INPUT. Enter Angle For Rotation : - 30 ouTPUT VIVA. VOCE QUESTIONS What is translation? How many arguments. are passed for translation? ‘What is rotation? How many arguments are passed for rotation? What is scaling on a rectangle? How many arguments are passed for rectangle? ed [Type text] ‘CSE/6"/CG Lab/Prepared by Vivek Kumar Sinha [Type text] ‘CSE/6"/CG Lab/Prepared by Vivek Kumar Sinha EXPERIMENT NO. 13 AIM : Write a program to implement Cohen Sutherland line Clipping algorithm. DESCRIPTION: The Cohen-Sutherland line clipping algorithm quickly detects and dispenses with two common and trivial cases. To clip a line, we need to consider only its endpoints, If both endpoints of a line lie inside the window, the entire line lies inside the ‘window. Its trivially aceepted and needs no clipping. On the other hand, if both endpoints of a line lie entirely to one side of the window, the line must lie entirely outside of the window. It is trivially rejected and needs to be neither clipped nor displayed. GORITHM. End-points pairs are checked for trivial acceptance of rejection using outcode; . If not trivially accepted or rejected, divide the line segment into two at lip edge; 3. Iteratively clipped by two segments un Dt tance or trivial-rejeetion, and divided into c or trivialerejection 100 ---L....7__ 5. 5, PROGRAM. #inelude #inelude #inelude < graphies.h> fidefine ROUND (a }( (int) (a+0.5 )) define LEFT_EDGE ox! define RIGHT_EDGE ox? define BOTTOM_EDGE ox4 #define TOP_EDGE ox8 unsigned char encode ( wept2 pt, dept winmin, dept winmax) [Type text] CSE/6"/CG Lab/Prepared by Vivek Kumar Sinha unsigned char code = ox00 ; if (pix < winmin.x) code = code | LE if(ptx > winmax.x) code = code | RIGHT_EDGE ; if ( pty winmax.y) code = code | TOP_EDGE ; return ( code ) ; ) void swappts ( unsigned char *cl, unsigned char *e2) unsigned char temp ; temp 1; “cl = "02x ¥e2 = temp; ) void dipline ( dept winmin, dept winmax, wept2 pl, wept 2 p2) t unsigned char codel,code? ; int done = FALSE, draw = FALSE ; float ms [Type text] ‘CSE/6"/CG Lab/Prepared by Vivek Kumar Sinha while (! done ) t code = emode ( p1, winmin, wittmax) ; code? = emode ( p2, w! in, winmax) ; if( ACCEPT ( codel,code2 }) t done = FALSE; else if( REJECT ( code! code2)) done = TRUE; else if( INSIDE ( code!)) { swappts ( &pl, &p2); swapcades ( &eodel, dteode?) ; if(p2x! # include < conio.h > # include < graphicd.h > void main () double numsteps i, float stepsize ; int x0 ,yO,xt yl x2, y2.08 98 xy int ax ,ay, bx, by ,ex. cy, dx, dys int gd = DETECT, gm ; initgraph (&gd em,“ \uedbgi”); print(“\n Enter The Value of x0.& yO"): seanf (“ %d %d” , &x0, &y0 ) ; print?(“\n Enter The Value of x1 & yl): scanf(“%d Yd", &xl, dey! ); printf (“*\n Enter The Value of x2.& y2” }: scant (*"%d Yd”, &x2 , &ey2); printt(“ \n Enter The Value of x3 & 3"): scanf( %d Yd", 8x3, &ey3); ax =-xO+ 3" x1 +(-3* x2) +835 ay =-yO4 3" yl #(-3* y2) + y3; bx= 34x04 (6% xi) +342: by=3* 0+ (6% yl +3925 cx=3" x43 "XI; CSE/6"/CG Lab/Prepared by Vivek Kumar Sinha cy=3*y0r3* yl; dx = x0; dy = 0; setcolor ( MAGENDA ) ; numstep = 100; stepsize = 1.0 /( double } numsteps ; moveto (dx ,dy ); for (i= 1; i #inelude < conio.h > #inelude < graphics.h> void SplinePoint(int *u,int n,int (double y,.XYZ *control, XYZ *oulput) intk; double b; output->x = 0; omipu>y =0; output>2= 0; for (k=O; k= b= SplineBlendtk.t.u.v): [Type text] ‘CSE/6"/CG Lab/Prepared by Vivek Kumar Sinha outpute>x += control[k].x * b; output->y + = control[k].y * b; output->z + =eantrolfk].z * b; 1 1 double SplincBlend(int k,int tint *u,double v) { double value; if (Culk] <= vy && (vy n) ufi=n-1+2; } } ouTPUT rps SL S™ ‘CSE/6"/CG Lab/Prepared by Vivek Kumar Sinha VIVA-VOCE QUESTIONS What is B-Spline Curve? What is SplinePoint Define the SplineBlend? What do you mean by SplineKnots? EXPERIMENT NO. 16 AIM :Write a program to implement Animation using C funetion. DESCRIPTION: A simulation of movement created by displaying a series of pictures, or frames. Cartoons on television is one example of animation, Animation on computers is one of the chief ingredients of multimedia presentations. There are many software applications that enable you to create animations that you ean display on a computer monitors. ‘The difference between animation and video. Whereas video takes continuous motion: and breaks it up into discrete frames, animation starts with independent pictures and puts them together to form the illusion of continuous motion. PROGRAM Ainelude # inelude < conio.h > #timclude < graphicd.h > void m t im x,y,a,b,i; int gd = DETECT gm; initgraph ( &gd S&gm ,*\\e\\bgi ™) ; for (i=0; 1<320;i++) { [Type text] CSE/6"/CG Lab/Prepared by Vivek Kumar Sinha rectangle ( 325,440 , 330, 50): rectangle ( 325.440 , 440, 455); rectangle ( 325,440 -1, 450,370 - circle (387, 410i, 10): line (325, 399i, 450, 399i); line (325, 420—i , 450, 420i): delay (15 clear device ( ) ) rectangle (325, 410, 330,50); reetangle (325 , 440, 440 _455); rectangle (325, 120, 450,50) circle ( 387.90, 10); line ( 325 79 , 430,79); line (325, 100 , 450 , 100) ; outtextxy (xy. * aoteh () 5 elosegraph (); ourPpuT [Type text] CSE/6"/CG Lab/Prepared by Vivek Kumar Sinha VIVA-VOCE QUESTIONS What is outtextxy()? Write the purpose of rectangle function & how tany parameters are required? What is graphies mode? What is graphics driver? EXPERIMENT NO. 17 AIM :Writea program to implement a cartoon using C function. iad DESCRIPTION = In this program we are going to create a cartoon, PROGRAM #include=stdio,h> #inelude nelude #include void main() { int gd = DETECT , gm, ia; elrser( ); initgraph ( &gd, &gm, "e:\\e\lbs [Type text] Yi ‘CSE/6"/CG Lab/Prepared by Vivek Kumar Sinha for (i= (+ 80); =300;i+=5) t circle ( 200+ i, 200,100); setfillstyle(SOLID_FILL.i) ; flood fill (200 + i, 200, WHITE ) ; circle ( 160+ i, 160, 10); setfillstyle ( SOLID_FILL, i+ 1); flood fill (160+ 160, WHITE ) ; circle ( 240+ 4, 160, 10); setfillstyle ( SOLID_FILL, i+ 1)s floodfill ( 240 + i, 160, WHITE ) ; are (200 + i, 200, 200, 340, 60 ) ; delay (200); celrsen ); } getch( 5 ' ourTPUT [Type text] ‘CSE/6"/CG Lab/Prepared by Vivek Kumar Sinha VIVA-VOCE QUESTIONS Define setfillstyle function. Define flood{fill function. Define delay function . Why we used are function? Pee [Type text] ‘CSE/6"/CG Lab/Prepared by Vivek Kumar Sinha EXPERI 0. 18 AIM : Write a program to draw a chain of Circle. DESCRIPTION : Here in this program , weare drawing a chain of circles. PROGRAM clude clude lude include void main() { int gd = DETECT, gm , i; initgraph ( &gd, &em, " far(i=S0si<=200 t circle(i,i+30,50), getch(); restorcrimode(); } ourruT VIVA-VOCE QUESTIONS L.Expain all the parameters of initgraphi), 2.AVhat do you mean by DETECT? 3.What is restorertmode()? [Type text] CSE/6"/CG Lab/Prepared by Vivek Kumar Sinha EXPERIMENT NO. 19 AIM :Writea program to display concentrie circles. DESCRIPTION ; Here in this program , we are drawing a concentric circles, PROGRAM #inelude #inelude include void main() { int d-DETECT,m; initgraph(&éd,dem,"e:\\te\bge setcolort4y; 28) circle(150,150,i); getch(); /*draw concentric circle of radius i pixels and center at 50,50, in color 3°/ restorertmode(): ouTPUT VIVA-VOCE QUESTION 1.Expain all the parameters of initgraph(), 2.What do you mean by DETECT? 3. What is restorcrimode(}? [Type text] CSE/6"/CG Lab/Prepared by Vivek Kumar Sinha EXPERIMENT NO. 20 AIM :Writea program to fill an ellipse by reduce the size of ellipse. DESCRIPTION : PROGRAM #include include nelude include elli_Réxe,yecrxay) float xc,ye,rx,t { while(rx>0,0 && ry>0,0) t ellipse(xe,ye,0,360,rx,F9); ~m% Hy: getch(); } return; } Void main) { float xe.yesrs.rys int gd=DETECT,2m, initgraph(&ed,&em, setpalette( 0,2 fortis t ellipse(250,250,0,360, 140,80); getehOs elli_R(250.0,250.0,140.0,80.09, } restorecrtmode(); retum; } [Type text] ‘CSE/6"/CG Lab/Prepared by Vivek Kumar Sinha OUTPUT ‘VIVA-VOCE QUESTION 1. Define ellipse function. 2. What do you mean by setpalette function? 3. What is DETECT driver? 4. What is Graphics Mode” [Type text] CSE/6"/CG Lab/Prepared by Vivek Kumar Sinha

Vous aimerez peut-être aussi