Advertisement
Guest User

KGLab3

a guest
May 25th, 2017
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. void paintStar(HWND* hWnd, int sx, int sy)
  2. {
  3.     PAINTSTRUCT ps;
  4.     HBRUSH hBrush = CreateSolidBrush(RGB(0,0,255));; //Öâåò ôîíà çâåçäû
  5.     HDC hdc = BeginPaint(*hWnd, &ps);
  6.     HPEN hpen = CreatePen(PS_SOLID, 2, RGB(0,0,0)); //Öâåò ëèíèé
  7.  
  8.     const int WIDTH = 400;
  9.     const int HEIGHT = 300;
  10.    
  11.     POINT pt[5] = {
  12.         {0, -100},
  13.         {59, 95},
  14.         {-95, -31},
  15.         {95, -31},
  16.         {-59, 95}
  17.     };
  18.  
  19.     POINT pt1[5];
  20.  
  21.     SetMapMode(hdc, MM_ANISOTROPIC);
  22.     SetWindowExtEx(hdc, WIDTH, -HEIGHT, NULL);
  23.     SetViewportExtEx(hdc, sx/2, sy/2, NULL);
  24.     SetViewportOrgEx(hdc, sx/2, sy/2, NULL);
  25.    
  26.     //
  27.  
  28.     //Polygon(hdc, pt, 5);
  29.  
  30.     int n = 6;
  31.     double M_PI = 3.1415;
  32.     double alpha = M_PI / n;
  33.  
  34.     for(int i = 0; i < n; i++)
  35.     {
  36.         hBrush = CreateSolidBrush(RGB(255, 255-255./n*i, 255-255./n*i));
  37.        
  38.         SelectObject(hdc, hBrush);
  39.         for(int j = 0; j < 5; j++)
  40.         {
  41.             pt1[j].x = (pt[j].x * cos(alpha*i) - pt[j].y * sin(alpha*i)) + i * 10;
  42.             pt1[j].y = (pt[j].x * sin(alpha*i) + pt[j].y * cos(alpha*i));
  43.         }
  44.         BeginPath(hdc);
  45.        
  46.         Polygon(hdc, pt1, 5);
  47.        
  48.         CloseFigure(hdc);
  49.         EndPath(hdc);
  50.         SelectObject(hdc, hBrush);
  51.         SetPolyFillMode(hdc, WINDING);
  52.         FillPath(hdc);
  53.     }
  54.  
  55.  
  56.     EndPaint(*hWnd, &ps);
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement