Win32_GDI_五星红旗绘制
五星红旗画法
- 设置矩形长与高的比为3:2
- 把矩形分为四个相等的长方形

- 把左上角宽分为15份,高分为10份

- 定位大五角星圆心位置,x为宽的5份,y为高的5份
- 计算五角星五个点的坐标
|
void SetFivePoints(POINT* pts,int nCount,int r, int angle, POINT pOrg) { for (int i=0;i<nCount;i++) { //POINT pt1; // 第一个点在正上方,所以角度为90 pts[i].x = pOrg.x + (LONG)(r*cos((angle+i*72 )* PI / 180)); pts[i].y = pOrg.y - (LONG)(r*sin((angle+i*72) * PI / 180)); } }
|
pts为点坐标数组
nCount 为数组个数
r 为半径
angle 为角度
pOrg 为圆点坐标
- 用画多边形画五角星
|
POINT pts[5] = { 0 }; SetFivePoints(pts, 5, nHeight*3, 90, pOrg);
POINT pNewPts[5] = { pts[0],pts[2],pts[4],pts[1],pts[3] }; Polygon(hdc, pNewPts, 5); |
|
|
画线是从第一点到到3,再到5,再到2,再到4的顺序画的,
所有要重新调整数组中坐标位置

- 用相同方法绘制其他四个小五角星
- 第一个小星坐标为宽的10份,高的2份位置, 第一点起始角度为70
第二个小星坐标为宽的12份,高的4份位置,第一点起始角度为120
第三个小星坐标为宽的12份,高的7份位置,起始角度为90
每四个小星坐标为宽的10份,高的9份位置,起始角度为70
|
// 定位第一个小五星圆心 POINT ptOrg1 = { nWidth * 10,nHeight * 2 };
// 调整第一点的起始角度 SetFivePoints(pts, 5, nHeight, 70, ptOrg1); POINT pNewPts1[5] = { pts[0],pts[2],pts[4],pts[1],pts[3] }; Polygon(hdc, pNewPts1, 5);
// 定位第二个小五星圆心 ptOrg1 = { nWidth * 12,nHeight * 4 };
SetFivePoints(pts, 5, nHeight, 120, ptOrg1); POINT pNewPts2[5] = { pts[0],pts[2],pts[4],pts[1],pts[3] }; Polygon(hdc, pNewPts2, 5);
// 定位第三个小五星圆心 ptOrg1 = { nWidth * 12,nHeight * 7 };
SetFivePoints(pts, 5, nHeight, 90, ptOrg1); POINT pNewPts3[5] = { pts[0],pts[2],pts[4],pts[1],pts[3] }; Polygon(hdc, pNewPts3, 5);
// 定位第四个小五星圆心 ptOrg1 = { nWidth * 10,nHeight * 9 };
SetFivePoints(pts, 5, nHeight, 70, ptOrg1); POINT pNewPts4[5] = { pts[0],pts[2],pts[4],pts[1],pts[3] }; Polygon(hdc, pNewPts4, 5); |

最后去掉辅助线
效果为:


浙公网安备 33010602011771号