MFC(2)
绘制万花筒
在头文件添加#include
在OnDraw中添加代码
int n = 2;
int r1 = 300 / n;
int r2 = 100 / n;
int w = 400 / n;
int h = 300 / n;
int s = 10;
int tmpx = w - (r1 - r2 + s);
int tmpy = h;
CString str;
str = "s=10";
//str.Format(s);
pDC->TextOutW(600,50,str );
CPen pen(PS_SOLID, 1, RGB(255, 0, 0));
CPen *oldpen = pDC->SelectObject(&pen);
int a1, a2, xt, yt;
for (int i = 1;i < 20000;i++)
{
a1 = (int)(3.14 / 30 * i);
a2 = (int)(r1 / r2 * a1);
xt = -(r1 - r2)*cos(a1) - s * cos(a2 - a1) + w;
yt = (r1 - r2)*sin(a1) - s * cos(a2 - a1) + h;
pDC->MoveTo(tmpx, tmpy);
pDC->LineTo(xt, yt);
tmpx = xt;
tmpy = yt;
运行结果