Advertisement
Guest User

Untitled

a guest
Nov 12th, 2019
204
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.12 KB | None | 0 0
  1. //// C Implementation for drawing circle
  2. //#include <graphics.h>
  3. //
  4. ////driver code
  5. //int main()
  6. //{
  7. // // gm is Graphics mode which is
  8. // // a computer display mode that
  9. // // generates image using pixels.
  10. // // DETECT is a macro defined in
  11. // // "graphics.h" header file
  12. // int gd = DETECT, gm;
  13. //
  14. // // initgraph initializes the
  15. // // graphics system by loading a
  16. // // graphics driver from disk
  17. // initgraph(&gd, &gm, "");
  18. //
  19. // // circle fuction
  20. // circle(250, 200, 50);
  21. //
  22. // getch();
  23. //
  24. // // closegraph function closes the
  25. // // graphics mode and deallocates
  26. // // all memory allocated by
  27. // // graphics system .
  28. // closegraph();
  29. //
  30. // return 0;
  31. //}
  32. #include <windows.h>
  33. #include <conio.h>
  34. #include <math.h>
  35. void main()
  36. {
  37. HWND hwnd;
  38. char Title[1024];
  39. GetConsoleTitle(Title, 1024); // Óçíàåì èìÿ îêíà
  40.  
  41. hwnd = FindWindow(NULL, Title); // Óçíàåì hwnd îêíà
  42. RECT rc;
  43. GetClientRect(hwnd, &rc);
  44. int iWidth = rc.right;
  45. int iHeight = rc.bottom;
  46. HDC hdc = GetDC(hwnd); // Ïîëó÷àåì êîíòåêñò äëÿ ðèñîâàíèÿ
  47. HPEN p1, p2 = CreatePen(PS_SOLID, 2, RGB(255, 0, 0)), p3 = CreatePen(PS_SOLID, 2, RGB(200, 200, 255)); // Ñîçäàåì êðàñíîå ïåðî
  48. p1 = (HPEN)SelectObject(hdc, p2); // Çàíîñèì êðàñíîå ïåðî â êîíòåêñò ðèñîâàíèÿ
  49. int x = 0, y = 0, R = iWidth / 2;
  50. double fi = 0;
  51. do
  52. {
  53. x = R * cos(fi);
  54. y = R * sin(fi);
  55. MoveToEx(hdc, iWidth / 2, iHeight / 2, NULL);
  56. LineTo(hdc, x + iWidth / 2, iHeight / 2 - y);
  57. fi += 0.1;
  58. } while (fi < 6.28);
  59. (HPEN)SelectObject(hdc, p3);
  60. //fi = 0.1;
  61. //do
  62. //{
  63. // x = R * cos(fi);
  64. // y = R * sin(fi);
  65. // MoveToEx(hdc, iWidth / 2, iHeight / 2, NULL);
  66. // LineTo(hdc, x + iWidth / 2, iHeight / 2 - y);
  67. // fi += 0.2;
  68. //} while (fi < 6.28);
  69. HBRUSH oldb, hBlackBrush = CreateSolidBrush(RGB(100, 100, 255)), hOrangeBrush = CreateSolidBrush(RGB(253, 184, 19)), hEarthBrush = CreateSolidBrush(RGB(255, 0, 0));
  70. oldb = SelectObject(hdc, hBlackBrush);
  71. fi = 0;
  72. int size = 0;
  73. for (int k = 0; k < 50;k++) {
  74. for (int j =10; j > 0; j--) {
  75. for (int i = 1200 - (j * 20); i > 0; i -= 100) {
  76. Ellipse(hdc, -i+x + iWidth / 2, -i+iHeight / 2 - y, i + x + iWidth / 2, i + iHeight / 2 - y);
  77. //Ellipse(hdc, R - i, R - i, R + i, R + i);
  78. }
  79. x = (R/2) * cos(fi);
  80. y = (R/2) * sin(fi);
  81.  
  82. //SelectObject(hdc, hOrangeBrush);
  83. //Ellipse(hdc, R-50, R-50, R+50 , R+50);
  84. (HPEN)SelectObject(hdc, p3);
  85. SelectObject(hdc, hEarthBrush);
  86.  
  87.  
  88.  
  89. Ellipse(hdc, -50-1*size + x + iWidth / 2, -50 - 1 * size + iHeight / 2 - y, 50 + 1 * size + x + iWidth / 2, 50 + 1 * size + iHeight / 2 - y);
  90. SelectObject(hdc, hBlackBrush);
  91. fi += 0.1;
  92. //if (sin(fi)<0) { size++; }
  93. if (j<=5) { size+=5; }
  94. else { size-=5; }
  95.  
  96. Sleep(100);
  97. }
  98. }
  99.  
  100.  
  101. SelectObject(hdc, oldb);
  102. SelectObject(hdc, p1); // Âîçâðàùàåì ñòàðîå ïåðî
  103. ReleaseDC(hwnd, hdc); // Îñâîáîæäàåì êîíòåêñò ðèñîâàíèÿ
  104. DeleteObject(p2); // Óäàëÿåì ñîçäàííîå ïåðî
  105. _getch();
  106.  
  107.  
  108.  
  109.  
  110.  
  111.  
  112.  
  113. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement