Advertisement
Guest User

Untitled

a guest
Dec 12th, 2017
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.46 KB | None | 0 0
  1. 1//
  2. #include<stdio.h>
  3. #include<graphics.h>
  4. #include<conio.h>
  5.  
  6. int main(){
  7. char ch;
  8. int gd = DETECT,gm; //gdriver,gmode
  9. int i,x,y,xrad=200,yrad=100;
  10. initgraph(&gd, &gm, "C:\\TURBOC3\\BGI");
  11.  
  12. /* Initialize center of circle with center of screen */
  13. x = getmaxx()/2;
  14. y = getmaxy()/2;
  15. outtextxy(x-100, 50, "Ellipse Using Graphics in C");
  16. line(x-220,y,x+220,y);
  17. line(x,y-120,x,y+120);
  18. ellipse(x,y,0,360,xrad,yrad);
  19. for(i=EMPTY_FILL;i<USER_FILL;i++)
  20. {
  21. setfillstyle(i,RED); //getmaxcolor()
  22. fillellipse(x,y,xrad,yrad);
  23. getch();
  24. }
  25. closegraph();
  26. return 0;
  27. }
  28.  
  29. 2//
  30. #include<stdio.h>
  31. #include<graphics.h>
  32. #include<conio.h>
  33.  
  34. int main(){
  35. char ch;
  36. int gd = DETECT,gm;
  37. int x,y,x1,y1,radius=50,dir=0,speed=2;
  38. initgraph(&gd, &gm, "C:\\TURBOC3\\BGI");
  39.  
  40. /* Initialize center of circle with center of screen */
  41. x1 = getmaxx()/2-100;
  42. y1 = getmaxy()/2;
  43. x=x1;
  44. y=y1;
  45. while(1)
  46. {
  47. outtextxy(x1-50, 50, "CIRCLE Rolling Using Graphics in C");
  48. line(x1,y1+radius,x1+200,y1+radius);
  49. circle(x, y, radius);
  50. if(dir==2) break;
  51. if(dir==0) //UP
  52. {
  53. x+=speed;
  54. if(x>x1+200) {dir=1;x-=speed;y+=(2*radius);}
  55. }
  56. else //DOWN
  57. {
  58. x-=speed;
  59. if(x<x1) {dir=2;x+=speed;y-=(2*radius);}
  60. }
  61. delay(30);
  62. cleardevice();
  63. }
  64. getch();
  65. closegraph();
  66. return 0;
  67. }
  68.  
  69. 3//
  70. #include<stdio.h>
  71. #include<graphics.h>
  72. #include<conio.h>
  73.  
  74. int main(){
  75. char ch;
  76. int gd = DETECT,gm;
  77. int x,y,x1,y1,radius=50,dir=0,speed=2;
  78. initgraph(&gd, &gm, "C:\\TURBOC3\\BGI");
  79.  
  80. /* Initialize center of circle with center of screen */
  81. x1 = getmaxx()/2-100;
  82. y1 = getmaxy()/2;
  83. x=x1;
  84. y=y1;
  85. while(1)
  86. {
  87. outtextxy(x1-50, 50, "CIRCLE Rolling Using Graphics in C");
  88. line(x1,y1+radius,x1+200,y1+radius);
  89. circle(x, y, radius);
  90.  
  91. ch=getch();
  92. if(ch==27) exit(0);
  93. if(ch==0)
  94. {
  95. ch=getch();
  96. if(ch==77) //D,Right,Clockwise
  97. {
  98. if(dir==0) //UP
  99. {
  100. x+=speed;
  101. if(x>x1+200) {dir=1;x-=speed;y+=(2*radius);}
  102. }
  103. else //DOWN
  104. {
  105. x-=speed;
  106. if(x<x1) {dir=0;x+=speed;y-=(2*radius);}
  107. }
  108. }
  109. else if(ch==75) //A,Left,Anticlockwise
  110. {
  111. if(dir==0) //UP
  112. {
  113. x-=speed;
  114. if(x<x1) {dir=1;x+=speed;y+=(2*radius);}
  115. }
  116. else //DOWN
  117. {
  118. x+=speed;
  119. if(x>x1+200) {dir=0;x-=speed;y-=(2*radius);}
  120. }
  121. }
  122. }
  123. cleardevice();
  124. delay(1);
  125. }
  126. //closegraph();
  127. //return 0;
  128. }
  129.  
  130. 4//
  131. #include<stdio.h>
  132. #include<graphics.h>
  133. #include<conio.h>
  134.  
  135. int main(){
  136. char ch;
  137. int gd = DETECT,gm;
  138. int x,y,radius=50;
  139. initgraph(&gd, &gm, "C:\\TURBOC3\\BGI");
  140.  
  141. /* Initialize center of circle with center of screen */
  142. x = getmaxx()/2;
  143. y = getmaxy()/2;
  144.  
  145. while(1)
  146. {
  147. outtextxy(x-170, 50, "CIRCLE Zoom in-Zoom out Using Graphics.h in C");
  148. circle(x, y, radius);
  149. ch=getch();
  150. if(ch==27) exit(0);
  151. if(ch=='a') {radius+=1;}
  152. if(ch=='z') {radius-=1;}
  153. cleardevice();
  154. delay(1);
  155. }
  156. }
  157.  
  158. 5//
  159. #include<stdio.h>
  160. #include<graphics.h>
  161. #include<conio.h>
  162.  
  163. int main(){
  164. char ch;
  165. int gd = DETECT,gm; //gdriver,gmode
  166. int i,j,x,y,max,x1,sx,ex,l,dx;
  167. initgraph(&gd, &gm, "C:\\TURBOC3\\BGI");
  168.  
  169. /* Initialize center of circle with center of screen */
  170. x = getmaxx()/2;
  171. y = getmaxy()/2;
  172. max=getmaxcolor();
  173. sx=x-200,ex=x+200,l=5,dx=2;
  174. for(i=0;i<max;i++)
  175. {
  176. setcolor(WHITE);
  177. outtextxy(x-120, 50, "Dashed Line Using Graphics in C");
  178. setcolor(i+1);
  179. for(x1=sx;x1<=ex;x1+=(l+dx)) line(x1,y,x1+l,y);
  180. //setcolor((i+2)%max+1);
  181. //for(x1=sx;x1<=ex;x1+=(l+dx)) line(x1,y+20,x1+l,y+20);
  182. //setcolor((i+3)%max+1);
  183. //for(x1=sx;x1<=ex;x1+=(l+dx)) line(x1,y+40,x1+l,y+40);
  184.  
  185. getch();
  186. }
  187. closegraph();
  188. return 0;
  189. }
  190.  
  191. 6//
  192. #include<stdio.h>
  193. #include<graphics.h>
  194. #include<conio.h>
  195.  
  196. int main(){
  197. char ch;
  198. int gd = DETECT,gm; //gdriver,gmode
  199. int i,x,y,dx=50,dy=20;
  200. initgraph(&gd, &gm, "C:\\TURBOC3\\BGI");
  201.  
  202. /* Initialize center of circle with center of screen */
  203. x = getmaxx()/2;
  204. y = getmaxy()/2;
  205. outtextxy(x-70, 50, "Ghus Jao Andar :P");
  206. rectangle(x-dx,y-dy,x+dx,y+dy);
  207. for(i=0;i<2;i++)
  208. {
  209. dx*=2;dy*=2;
  210. line(x-dx,y,x,y-dy);
  211. line(x,y-dy,x+dx,y);
  212. line(x+dx,y,x,y+dy);
  213. line(x,y+dy,x-dx,y);
  214. rectangle(x-dx,y-dy,x+dx,y+dy);
  215. }
  216. getch();
  217. closegraph();
  218. return 0;
  219. }
  220.  
  221. 7//
  222. #include<stdio.h>
  223. #include<graphics.h>
  224. #include<conio.h>
  225. #include<math.h>
  226.  
  227. int main(){
  228. char ch;
  229. int gd = DETECT,gm; //gdriver,gmode
  230. int i,x,y,x1,y1,x2,y2,rad=100;
  231. float alpha=0.0;
  232. initgraph(&gd, &gm, "C:\\TURBOC3\\BGI");
  233.  
  234. /* Initialize center of circle with center of screen */
  235. x = getmaxx()/2;
  236. y = getmaxy()/2;
  237. x1=x,y1=y,x2=x+rad*cos(alpha),y2=y+rad*sin(alpha);
  238. while(1)
  239. {
  240. outtextxy(x-50, 50, "De Ghumake :P");
  241. circle(x,y,rad);
  242. line(x1,y1,x2,y2);
  243. ch=getch();
  244. if(ch==27) exit(0);
  245. if(ch==0)
  246. {
  247. ch=getch();
  248. if(ch==77) //Right Key
  249. {
  250. alpha+=0.05;
  251. x2=x+rad*cos(alpha);
  252. y2=y+rad*sin(alpha);
  253. }
  254. if(ch==75) //Left Key
  255. {
  256. alpha-=0.05;
  257. x2=x+rad*cos(alpha);
  258. y2=y+rad*sin(alpha);
  259. }
  260.  
  261. }
  262. delay(1);
  263. cleardevice();
  264. }
  265. }
  266.  
  267.  
  268. 8//
  269.  
  270. #include <graphics.h>
  271. #include <dos.h>
  272. union REGS i,o;
  273. void detect_mouse ()
  274. {
  275. i.x.ax = 0;
  276. int86 (0X33,&i,&o); //invoke interrupt
  277. if (o.x.ax == 0)
  278. printf ("\nMouse Failed To Initialize");
  279. else
  280. printf ("\nMouse was Succesfully Initialized");
  281. }
  282. show_mouse()
  283. {
  284. i.x.ax=1;
  285. int86(0x33,&i,&o);
  286. }
  287. hide_mouse()
  288. {
  289. i.x.ax=2;
  290. int86(0x33,&i,&o);
  291. }
  292. get_mouse_pos(int *x,int *y,int *button)
  293. {
  294. i.x.ax=3;
  295. int86(0x33,&i,&o);
  296. *x=o.x.cx;
  297. *y=o.x.dx;
  298. *button=o.x.bx&1;
  299. }
  300. main()
  301. {
  302. int gdriver = DETECT, gmode, errorcode,button,x1,y1,x2,y2;
  303. initgraph(&gdriver, &gmode, "c:\\tc\\bgi");
  304. detect_mouse ();
  305. outtextxy(230,400,"Press any key to exit....");
  306. while(!kbhit())
  307. {
  308. show_mouse();
  309. get_mouse_pos(&x1,&y1,&button);
  310. x2=x1;
  311. y2=y1;
  312. while(button==1)
  313. {
  314. hide_mouse();
  315. line(x1,y1,x2,y2) ;
  316. x1=x2;
  317. y1=y2;
  318. get_mouse_pos(&x2,&y2,&button);
  319. }
  320. }
  321. }
  322.  
  323. 9//
  324. #include <graphics.h>
  325. #include <dos.h>
  326. union REGS i,o;
  327. void detect_mouse ()
  328. {
  329. i.x.ax = 0;
  330. int86 (0X33,&i,&o); //invoke interrupt
  331. printf(" ");
  332. //if (o.x.ax == 0) printf ("\nMouse Failed To Initialize");
  333. //else printf ("\nMouse was Succesfully Initialized");
  334. }
  335.  
  336. show_mouse()
  337. {
  338. i.x.ax=1;
  339. int86(0x33,&i,&o);
  340. }
  341.  
  342. hide_mouse()
  343. {
  344. i.x.ax=2;
  345. int86(0x33,&i,&o);
  346. }
  347.  
  348. get_mouse_pos(int *x,int *y,int *button)
  349. {
  350. i.x.ax=3;
  351. int86(0x33,&i,&o);
  352. *x=o.x.cx;
  353. *y=o.x.dx;
  354. *button=o.x.bx&7;
  355. }
  356.  
  357. main()
  358. {
  359. int gdriver = DETECT, gmode, errorcode,button,x1,y1,x2,y2;
  360. initgraph(&gdriver, &gmode, "C:\\TC\\BGI");
  361. detect_mouse();
  362.  
  363. //outtextxy(175,50,"Engineering chodo, Painting Karo :P ");
  364.  
  365. while(!kbhit())
  366. {
  367. show_mouse();
  368. get_mouse_pos(&x1,&y1,&button);
  369. x2=x1;
  370. y2=y1;
  371. if(button>0)
  372. {
  373. while(button==1)
  374. {
  375. setcolor(WHITE);
  376. hide_mouse();
  377. line(x1,y1,x2,y2) ;
  378. x1=x2;
  379. y1=y2;
  380. get_mouse_pos(&x2,&y2,&button);
  381. }
  382. if(button==2) {cleardevice();}
  383. }
  384. }
  385. }
  386.  
  387. 10//
  388. #include <graphics.h>
  389. #include <dos.h>
  390. union REGS i,o;
  391. void detect_mouse ()
  392. {
  393. i.x.ax = 0;
  394. int86 (0X33,&i,&o); //invoke interrupt
  395. if (o.x.ax == 0) printf ("\nMouse Failed To Initialize");
  396. else printf ("\nMouse was Succesfully Initialized");
  397. }
  398.  
  399. show_mouse()
  400. {
  401. i.x.ax=1;
  402. int86(0x33,&i,&o);
  403. }
  404.  
  405. hide_mouse()
  406. {
  407. i.x.ax=2;
  408. int86(0x33,&i,&o);
  409. }
  410.  
  411. get_mouse_pos(int *x,int *y,int *button)
  412. {
  413. i.x.ax=3;
  414. int86(0x33,&i,&o);
  415. *x=o.x.cx;
  416. *y=o.x.dx;
  417. *button=o.x.bx&1;
  418. }
  419.  
  420. main()
  421. {
  422. int gdriver = DETECT, gmode, errorcode,button,x1,y1,x2,y2;
  423. initgraph(&gdriver, &gmode, "C:\\TC\\BGI");
  424. detect_mouse();
  425.  
  426. outtextxy(175,50,"Engineering chodo, Painting Karo :P ");
  427. setfillstyle(SOLID_FILL,RED);
  428. rectangle(270,400,300,430);
  429. floodfill(285,415,WHITE);
  430. setfillstyle(SOLID_FILL,GREEN);
  431. rectangle(300,400,330,430);
  432. floodfill(315,415,WHITE);
  433. setfillstyle(SOLID_FILL,BLUE);
  434. rectangle(330,400,360,430);
  435. floodfill(345,415,WHITE);
  436.  
  437. while(!kbhit())
  438. {
  439. show_mouse();
  440. get_mouse_pos(&x1,&y1,&button);
  441. x2=x1;
  442. y2=y1;
  443. while(button==1)
  444. {
  445. if(x1>270 &&x1<300 && y1>400 && y1<430) {setcolor(RED);}
  446. if(x1>300 &&x1<330 && y1>400 && y1<430) {setcolor(GREEN);}
  447. if(x1>330 &&x1<360 && y1>400 && y1<430) {setcolor(BLUE);}
  448.  
  449. hide_mouse();
  450. line(x1,y1,x2,y2) ;
  451. x1=x2;
  452. y1=y2;
  453. get_mouse_pos(&x2,&y2,&button);
  454. }
  455. }
  456.  
  457. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement