动圆1(c语言程序)
CClientDC* pDC = new CClientDC(this);
const double PI = 3.1415926536, _2PI = PI + PI; #define Sum s[n - 1]
const int r = 200, p = 20;
const int x0=r+20, y0=r+20, x1=x0-r, y1=y0-r, x2=x0+r, y2=y0+r;
int n = 5, *data = new int[n], *s = new int[n];
static int promin = 0;
data[0] = 2;
data[1] = 3;
data[2] = 5;
data[3] = 1;
data[4] = 7; // 演示数据
int x3, y3, x4, y4;
double theta3, theta4, thetam, tx, ty;
#define R 156+ rand() % 100
CBrush br, *p_br;
CRect rc;
GetClientRect(&rc);
DC->Rectangle(0, 0, rc.right, rc.bottom); // 清屏
int i;
for(s[0] = data[0], i = 1; i < n; ++i)
s[i] = s[i - 1] + data[i];
srand((unsigned)time(NULL));
for(theta3 = 0.0, x3 = x0 + r, y3 = y0, i = 0; i < n; ++i)
{
theta4 = _2PI * s[i] / Sum;
x4 = x0 + r * cos(theta4);
y4 = y0 + r * sin(theta4);
if(i != promin) tx = ty = 0;
// 如果不是要突出的那个扇形,其位置不必调节(位移量为0)
else
{
thetam = (theta3 + theta4) * 0.5; // 扇形的中心角
tx = p * cos(thetam) * (_2PI - theta4 + theta3) / _2PI;
ty = p * sin(thetam) * (_2PI - theta4 + theta3) / _2PI;
// 如果是要突出的那个扇形,则沿中心角方向向外位移(tx, ty)
}
br.CreateSolidBrush(RGB(R, R, R));
p_br = pDC -> SelectObject(&br);
pDC -> Pie(x1+tx, y1+ty, x2+tx, y2+ty, x4+tx, y4+ty, x3+tx, y3+ty);
theta3 = theta4;
x3 = x4;
y3 = y4;
pDC -> SelectObject(p_br);
br.DeleteObject();
}
delete data;
delete s;
delete pDC;
promin = (promin + 1) % n;