Facebook
From cga, 1 Month ago, written in Plain Text.
Embed
Download Paste or View Raw
Hits: 156
  1. 1)draw coordinate axis at centre of screen
  2. #include<graphics.h>
  3. #include<conio.h>
  4. void main()
  5. {
  6. int gd=DETECT,gm,xcen,ycen;
  7. initgraph(&gd;,&gm;,"C:\\TC\\BGI");
  8. xcen=getmaxx()/2;
  9. ycen=getmaxy()/2;
  10. line(xcen,0,xcen,getmaxy());
  11. line(0,ycen,getmaxx(),ycen);
  12. getch();
  13. closegraph();
  14. }
  15.  
  16. 2)
  17. a. Develop the program for DDA Line drawing algorithm.
  18. CODE:
  19. #include<stdio.h>
  20. #include<conio.h>
  21. #include<graphics.h>
  22. #include<math.h>
  23. #include<dos.h>
  24. void main()
  25. {
  26. int gd=DETECT,gm;
  27. float x1,y1,x2,y2,i,dx,dy,m;
  28. printf("\nEnter the x1 and y1 coordinate: ");
  29. scanf("%f%f",&x1;,&y1;);
  30. printf("\nEnter the x2 and y2 coordinate: ");
  31. scanf("%f%f",&x2;,&y2;);
  32. m=(y2-y1)/(x2-x1);
  33. initgraph(&gd;,&gm;,"C:\\TC\\BGI");
  34. for(i=x1;i<=x2;i++)
  35. {
  36. if(m<1)
  37. {
  38. dx=x1+1;
  39. dy=y1+m;
  40. }
  41. else if(m>1)
  42. {
  43.  
  44. }
  45. else
  46. {
  47.  
  48. }
  49. dx=x1+(1/m);
  50. dy=y1+1;
  51.  
  52. dx=x1+1;
  53. dy=y1+1;
  54.  
  55. abs(dx);
  56. abs(dy);
  57. putpixel(dx,dy,15);
  58. x1=dx;
  59. y1=dy;
  60. delay(50);
  61. }
  62. outtextxy(x2,y2,"DDA LINE");
  63. getch();
  64. closegraph();}
  65.  
  66. 3)
  67. 5A WRITE A PROGRAM TO IMPLEMENT 2D SCALING
  68. A1 WRITE A PROGRAM TO SCALE 2D LINE
  69. CODE:
  70. #include<conio.h>
  71. #include<stdio.h>
  72. #include<graphics.h>
  73. void main()
  74. {
  75. float x1,x2,y1,y2,sx,sy;
  76. int gd=DETECT,gm;
  77. printf("\nEnter Start Cooridinate (x1,y1): ");
  78. scanf("%f%f",&x1;,&y1;);
  79. printf("\nEnter the End Cooridinate(x2,y2): ");
  80. scanf("%f%f",&x2;,&y2;);
  81.  
  82. printf("'\nEnter Scaling Parmeters: ");
  83. scanf("%f%f",&sx;,&sy;);
  84. initgraph(&gd;,&gm;,"C:\\TC\\BGI");
  85. line(x1,y2,x2,y2);
  86. outtextxy(x1,y1,"Line Before Scaling");
  87. x1=x1*sx;
  88. y1=y1*sy;
  89. x2=x2*sx;
  90. y2=y2*sy;
  91. line(x1,y1,x2,y2);
  92. outtextxy(x1,y1,"Line After Scaling");
  93. getch();
  94. closegraph();
  95. }
  96.  
  97. 4)
  98. A)Develop a simple text screen saver using graphics functions.
  99. #include <stdio.h>
  100. #include <stdlib.h>
  101. #include <graphics.h>
  102. #include <conio.h>
  103. #include <dos.h>
  104. void main()
  105. {
  106. int
  107. gdriver=DETECT,gmode,col=480,row=640,font=4,direction=2,size=8,col
  108. or=15;
  109. initgraph(&gdriver;,&gmode;,"C:\\TurboC3\\BGI");
  110. cleardevice();
  111. while(!kbhit()){
  112. settextstyle(random(font),random(direction),random(size));
  113. setcolor(random(color));
  114. outtextxy(random(col),random(row),"Komal");
  115. delay(250);
  116. }
  117. closegraph();
  118. }
  119.  
  120. 5)
  121. B. Draw a simple hut on the screen.
  122.  
  123. CODE:
  124. #include<graphics.h>
  125. #include<conio.h>
  126. void main()
  127. {
  128. int gd=DETECT, gm;
  129. initgraph(&gd;,&gm;,"C:\\TC\\BGI");
  130. rectangle(150,180,250,300);
  131. rectangle(250,180,420,300);
  132. rectangle(180,250,220,300);
  133. line(200,100,150,180);
  134. line(200,100,250,180);
  135. line(200,100,370,100);
  136. line(370,100,420,180);
  137. getch();
  138. closegraph();
  139. }
  140.  
  141. 6)
  142. A. Divide your screen into four region, draw circle, rectangle, ellipse and
  143. half ellipse in each region
  144.  
  145. CODE:
  146. #include<graphics.h>
  147. #include<conio.h>
  148. void main()
  149. {
  150. int gd=DETECT,gm,xcen,ycen;
  151. initgraph(&gd;,&gm;,"C:\\TC\\BGI");
  152. xcen=getmaxx()/2;
  153. ycen=getmaxy()/2;
  154. line(xcen,0,xcen,getmaxy());
  155. line(0,ycen,getmaxx(),ycen);
  156. rectangle(xcen+50,ycen-200,xcen+200,ycen-50);
  157. ellipse(xcen-xcen/2,ycen+ycen/2,0,360,100,50);
  158. ellipse(xcen+xcen/2,ycen+ycen/2,0,180,100,50);
  159. getch();
  160. closegraph();
  161. }
  162. 7)
  163. B) Perform smiling face animation using graphic functions.
  164. #include<stdio.h>
  165. #include<conio.h>
  166. #include<graphics.h>
  167. #include<stdlib.h>
  168. void main()
  169. {
  170. int gd=DETECT,gm,x=250,y=250;
  171. initgraph(&gd;,&gm;,"C:\\TC\\BGI");
  172. cleardevice();
  173. while(!kbhit())
  174. {
  175. setfillstyle(SOLID_FILL,14);
  176. fillellipse(x,y,100,100);
  177. setfillstyle(SOLID_FILL,random(6));
  178. fillellipse(x-30,y-30,20,40);
  179. fillellipse(x+30,y-30,20,40);
  180. setcolor(random(3));
  181. ellipse(x,y+10,180,0,60,50);
  182. delay(500);
  183. }
  184. closegraph();
  185. }
  186.  
  187. 8)
  188. 5B: WRITE A PROGRAM TO IMPLEMENT 2D Translation
  189. B1 WRITE A PROGRAM TO IMPLEMENT 2D Translation on a line
  190. CODE:
  191. #include<stdio.h>
  192. #include<conio.h>
  193. #include<graphics.h>
  194. void main()
  195. {
  196. int gd=DETECT,gm;
  197. float Tx,Ty,x1,y1,x2,y2;
  198. printf("Enterthe coordinates(x1,y1):");
  199.  
  200. SYIT CGA Practical
  201.  
  202. Komal Jambhale 6
  203. scanf("%f%f",&x1;,&y1;);
  204. printf("Enterthe second coordinations(x1,y2)");
  205. scanf("%f%f",&x2;,&y2;);
  206. printf("Enterthe translation parameter(Tx,Ty)");
  207. scanf("%f%f",&Tx;,&Ty;);
  208. initgraph(&gd;,&gm;,"C:\\TC\\BGI");
  209. line(x1,y1,x2,y2);
  210. outtextxy(x1,y1,"Before Translation");
  211. x1=x1+Tx;
  212. y1=y1+Ty;
  213. x2=y2+Tx;
  214. y2=y2+Ty;
  215. line(x1,y1,x2,y2);
  216. outtextxy(x2,y2,"After Translation");
  217. getch();
  218. closegraph();
  219. }
  220.  
  221.  
  222.  

Replies to exam rss

Title Name Language When
Re: exam cga prac text 1 Month ago.