Advertisement
zoro-10

1A. List of Basic Functions

Apr 1st, 2024 (edited)
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 3.58 KB | None | 0 0
  1. // (a)Study and enlist the basic functions used for
  2. // graphics in C/C++/Python language .Give an example
  3. // for each of them.
  4.  
  5. // (i)arc():
  6.  
  7. #include<graphics.h>
  8. #include<stdio.h>
  9. #include<conio.h>
  10. void main()
  11. {
  12. int gd=DETECT,gm;
  13. initgraph(&gd,&gm,"C:\\TurboC3\\BGI");
  14. arc(100,100,0,35,50);
  15. getch();
  16. closegraph();
  17. }
  18.  
  19. //(ii)bar() and bar3d():
  20.  
  21. #include<graphics.h>
  22. #include<stdio.h>
  23. #include<conio.h>
  24. void main()
  25. {
  26. int gd=DETECT,gm;
  27. initgraph(&gd,&gm,"C:\\TurboC3\\BGI");
  28. bar(100,100,200,200);
  29. bar3d(250,250,300,300,20,1);
  30. getch();
  31. closegraph();
  32. }
  33.  
  34.  
  35. //(iii)circle():
  36.  
  37. #include<graphics.h>
  38. #include<stdio.h>
  39. #include<conio.h>
  40. void main()
  41. {
  42. int gd=DETECT,gm;
  43. initgraph(&gd,&gm,"C:\\TurboC3\\BGI");
  44. circle(100,100,50);
  45. getch();
  46. closegraph();
  47. }
  48.  
  49.  
  50. //(iv)cleardevice():
  51. #include<graphics.h>
  52. #include<stdio.h>
  53. #include<conio.h>
  54. void main()
  55. {
  56. int gd=DETECT,gm;
  57. initgraph(&gd,&gm,"C:\\TurboC3\\BGI");
  58. circle(100,100,50);
  59. outtext("Press any key to clear the screen");
  60. getch();
  61. cleardevice();
  62. outtext("Press any key to exit");
  63. getch();
  64. closegraph();
  65. }
  66.  
  67.  
  68. //v)drawpoly():
  69.  
  70. #include<graphics.h>
  71. #include<stdio.h>
  72. #include<conio.h>
  73. void main()
  74. {
  75. int gd=DETECT,gm,points[]={520,150,420,300,250,300,520,150};
  76. initgraph(&gd,&gm,"C:\\TurboC3\\BGI");
  77. drawpoly(4,points);
  78. getch();
  79. closegraph();
  80. }
  81.  
  82.  
  83. //(vi)fillpoly():
  84.  
  85. #include<graphics.h>
  86. #include<stdio.h>
  87. #include<conio.h>
  88. void main()
  89. {
  90. int gd=DETECT,gm,points[]={520,150,420,300,250,300,520,150};
  91. initgraph(&gd,&gm,"C:\\TurboC3\\BGI");
  92. fillpoly(4,points);
  93. getch();
  94. closegraph();
  95. }
  96.  
  97.  
  98. //(vii)ellipse() and fillellipse():
  99.  
  100. #include<graphics.h>
  101. #include<stdio.h>
  102. #include<conio.h>
  103. void main()
  104. {
  105. int gd=DETECT,gm;
  106. initgraph(&gd,&gm,"C:\\TurboC3\\BGI");
  107. ellipse(100,100,0,360,50,25);
  108. fillellipse(300,200,150,75);
  109. getch();
  110. closegraph();
  111. }
  112.  
  113.  
  114. //(viii)floodfill():
  115.  
  116. #include<graphics.h>
  117. #include<stdio.h>
  118. #include<conio.h>
  119. void main()
  120. {
  121. int gd=DETECT,gm;
  122. initgraph(&gd,&gm,"C:\\TurboC3\\BGI");
  123. setcolor(RED);
  124. circle(100,100,50);
  125. floodfill(100,100,RED);
  126. getch();
  127. closegraph();
  128. }
  129.  
  130.  
  131. //(ix)getmaxx() and getmaxy():
  132.  
  133. #include <graphics.h>
  134. #include <stdio.h>
  135. #include <conio.h>
  136. void main()
  137. {
  138.   int gd = DETECT, gm, max_x, max_y;
  139.   char array[100];
  140.   initgraph(&gd, &gm, "C:\\TurboC3\\BGI");
  141.   max_x = getmaxx();
  142.   printf("Maximum x co-ordinates for current graphics mode and driver =
  143.  %d\n",max_x);
  144.   max_y=getmaxy();
  145.   printf("Maximum y co-ordinates for current graphics mode and driver =
  146.  %d",max_y);
  147.   outtext(array);
  148.   getch();
  149.   closegraph();
  150. }
  151.  
  152.          
  153. //(x)getpixel():
  154.  
  155. #include<graphics.h>
  156. #include<stdio.h>
  157. #include<conio.h>
  158. void main()
  159. {
  160. int gd=DETECT,gm,color;
  161. initgraph(&gd,&gm,"C:\\TurboC3\\BGI");
  162. color=getpixel(0,0);
  163. printf("Color of pixel at (0,0) = %d",color);
  164. getch();
  165. closegraph();
  166. }
  167.          
  168. //(xi)getx() and gety():
  169.  
  170. #include<graphics.h>
  171. #include<stdio.h>
  172. #include<conio.h>
  173. void main()
  174. {
  175. int gd=DETECT,gm;
  176. initgraph(&gd,&gm,"C:\\TurboC3\\BGI");
  177. printf("Current position of x = %d\n",getx());
  178. printf("Current position of y = %d",gety());
  179. getch();
  180. closegraph();
  181. }
  182.  
  183.    
  184. //(xiii)putpixel():
  185.  
  186. #include<graphics.h>
  187. #include<stdio.h>
  188. #include<conio.h>
  189. void main()
  190. {
  191. int gd=DETECT,gm;
  192. initgraph(&gd,&gm,"C:\\TurboC3\\BGI");
  193. putpixel(25,25,WHITE);
  194. getch();
  195. closegraph();
  196. }
  197.  
  198.  
  199.  
  200.          
  201.  
  202.          
  203.          
  204. //(xiii)putpixel():
  205.          
  206. #include<graphics.h>
  207. #include<stdio.h>
  208. #include<conio.h>
  209. void main()
  210. {
  211. int gd=DETECT,gm;
  212. initgraph(&gd,&gm,"C:\\TurboC3\\BGI");
  213. putpixel(25,25,WHITE);
  214. getch();
  215. closegraph();
  216. }
  217.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement