fork download
  1. #include <graphics.h>
  2. #include <stdlib.h>
  3. #include <stdio.h>
  4. #include <conio.h>
  5. #include <math.h>
  6. #define Pi 3.1415926536
  7. // this function initializes graphics mode
  8. // it will work only if you're using Borland C++ compiler & BGI drivers
  9. // if you're using another compiler you should overwrite body of this function
  10. void init_gr(void)
  11. {
  12. /* request autodetection */
  13. int gd = DETECT, gm;
  14.  
  15. // initgraph initializes the graphics system
  16. // by loading a graphics driver from disk
  17. initgraph(&gd, &gm, "");
  18.  
  19. // line for x1, y1, x2, y2
  20. line(150, 150, 450, 150);
  21.  
  22. // line for x1, y1, x2, y2
  23. line(150, 200, 450, 200);
  24.  
  25. // line for x1, y1, x2, y2
  26. line(150, 250, 450, 250);
  27.  
  28. getch();
  29.  
  30. // closegraph function closes the graphics
  31. // mode and deallocates all memory allocated
  32. // by graphics system .
  33. closegraph();
  34. }
  35. }
  36. // this function shuts graphics mode down
  37. // it will work only if you're using Borland C++ compiler & BGI drivers
  38. // if you're using another compiler you should overwrite body of this function
  39. void end_gr(void)
  40. {
  41. closegraph();
  42. }
  43. // this function moves CP to (x,y) position
  44. // it will work only if you're using Borland C++ compiler & BGI drivers
  45. // if you're using another compiler you should overwrite body of this function
  46. void MoveTo(int x, int y)
  47. {
  48. moveto(x,y);
  49. }
  50. // this function draws a line to (x,y) position
  51. // it will work only if you're using Borland C++ compiler & BGI drivers
  52. // if you're using another compiler you should overwrite body of this function
  53. void LineTo(int x, int y)
  54. {
  55. lineto(x,y);
  56. }
  57. const N=6; // number of points in the figure
  58. // coordinates of all given points
  59. enum actions {MOVE,DRAW};
  60. struct
  61. {
  62. actions action;
  63. int x;
  64. int y;
  65. } figure[N]={{MOVE,360,270},{DRAW,360,260},{DRAW,355,260},{DRAW,360,250},
  66. {DRAW,365,260},{DRAW,360,260}};
  67. int x0,y0,dx,dy;
  68. float phi;
  69. int main(void)
  70. {
  71. // initializing graphics mode
  72. init_gr();
  73. // rotating about (x0,y0)
  74. x0=300;
  75. y0=260;
  76. // by 10 degrees
  77. phi=45.0*Pi/180.0;
  78. // main loop
  79. for(int i=0;i<8;i++)
  80. {
  81. // rotating the figure
  82. for (int j=0;j<N;j++)
  83. {
  84. dx=figure[j].x-x0;
  85. dy=figure[j].y-y0;
  86. figure[j].x=x0+dx*cos(phi)-dy*sin(phi);
  87. figure[j].y=y0+dx*sin(phi)+dy*cos(phi);
  88. }
  89. // drawing rotated figure
  90. for (j=0;j<N;j++)
  91. if (figure[j].action==MOVE)
  92. MoveTo(figure[j].x,figure[j].y);
  93. else
  94. LineTo(figure[j].x,figure[j].y);
  95. }
  96. // clean up
  97. getch();
  98. end_gr();
  99. return 0;
  100. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.c:1:14: fatal error: graphics.h: No such file or directory
     #include <graphics.h>
              ^~~~~~~~~~~~
compilation terminated.
stdout
Standard output is empty