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