LineFlowerSP

小时候玩过一种画线圈的玩具,将一个圆形齿轮在一个大圈里转,会画出各种图形来.这个程序就是模仿它做的.算法原理:将一个圆围绕着另一个大圆公转,并且它还做自转运动.那么圆内一点的运动轨迹就能生成一个奇妙的图形.更奇妙的是,一个小小参数的改变,会使整个画面完全不同.
      程序启动后,会随机生成不同的图形,点击鼠标或按下键盘任意按键会自动退出.使用鼠标滚轮滚动进行图形切换.我的博客头像就是用这个软件生成的.

屏保:画线圈LineFlower-LMLPHP

屏保:画线圈LineFlower-LMLPHP

屏保:画线圈LineFlower-LMLPHP

下载地址:

http://files.cnblogs.com/WhyEngine/LineFlower%E5%B1%8F%E4%BF%9D.zip

图形生成算法代码:

 void        CLineFlowerSPEntity::Reset()
{
m_nFinishTime = ;
m_nVerticesNum = ;
m_nPlayVertices = ; UINT width;
UINT height;
m_pDX9Render->GetBackBufferSize(width, height); Vector2 vScreenCenter(width*0.5f, height*0.5f); Yreal screenCircleRadius = width < height ? width*0.5f : height*0.5f;
if (screenCircleRadius < 10.0f)
{
return;
} Yreal rotateCircleRadius = yf_rand_real(screenCircleRadius - 128.0f);
Yreal fixCircleRadius = screenCircleRadius - rotateCircleRadius;
Yreal offset = yf_rand_real(64.0f, screenCircleRadius - 10.0f);
if (yf_rand_bool())
{
offset = -offset;
} Yreal stepScale0 = yf_rand_real(0.1f, 1.0f);
if (yf_rand_bool())
{
stepScale0 = 1.0f / stepScale0;
}
Yreal stepScale180 = yf_rand_real(0.1f, 1.0f);
if (yf_rand_bool())
{
stepScale180 = 1.0f / stepScale180;
} Yreal offsetScale0 = yf_rand_real(0.1f, 1.0f);
if (yf_rand_bool())
{
offsetScale0 = 1.0f / offsetScale0;
}
Yreal offsetScale180 = yf_rand_real(0.1f, 1.0f);
if (yf_rand_bool())
{
offsetScale180 = 1.0f / offsetScale180;
} Yreal maxOffset = (offsetScale180 > offsetScale0) ? offsetScale180 : offsetScale0;
maxOffset *= fabs(offset);
Yreal posScale = screenCircleRadius / (fixCircleRadius + maxOffset);
posScale *= 0.95f; Yreal scale0 = yf_rand_real(0.1f, 1.0f);
if (yf_rand_bool())
{
scale0 = 1.0f / scale0;
}
Yreal scale180 = yf_rand_real(0.1f, 1.0f);
if (yf_rand_bool())
{
scale180 = 1.0f / scale0;
} Yreal step = screenCircleRadius / rotateCircleRadius;
if (step > 360.0f)
{
return;
} m_nCirclesCount = YD_MAX_CIRCLES_COUNT;
m_nVerticesNum = m_nCirclesCount * ; Vector2 vCenter;
Yreal degree = ; Vector2 vPos;
Vector2 vPos0;
Vector2 vPos1;
Yuint index;
Yreal r, a;
Yreal scale; RhwVertex* vb;
m_pVB->Lock(, , (void**)&vb, ); for (Yuint i = ; i < m_nCirclesCount; i++)
{
for (Yuint j = ; j < ; j++)
{
vCenter.x = vScreenCenter.x + fixCircleRadius*m_listSinValues[j];
vCenter.y = vScreenCenter.y + fixCircleRadius*m_listCosValues[j]; r = fabsf(degree - 180.0f) / 180.0f;
scale = yf_lerp(offsetScale0, offsetScale180, r); index = (Yint)degree;
vPos0.x = vCenter.x - offset*scale*m_listSinValues[index];
vPos0.y = vCenter.y - offset*scale*m_listCosValues[index]; vPos1.x = vCenter.x - offset*scale*m_listSinValues[index + ];
vPos1.y = vCenter.y - offset*scale*m_listCosValues[index + ]; a = degree - index;
vPos = vPos0*(1.0f - a) + vPos1*a;
vPos.x = posScale*(vScreenCenter.x - vPos.x) + vScreenCenter.x;
vPos.y = posScale*(vScreenCenter.y - vPos.y) + vScreenCenter.y; vb[i* + j].Set(vPos.x, vPos.y, 0.0f, 1.0f); scale = yf_lerp(stepScale0, stepScale180, r);
degree += step*scale;
degree = fmodf(degree, 360.0f);
} if (degree < YD_DEGREE_MAX_ERROR || degree > 360.0f - YD_DEGREE_MAX_ERROR)
{
m_nCirclesCount = i + ;
m_nVerticesNum = m_nCirclesCount * ;
vb[m_nVerticesNum] = vb[];
m_nVerticesNum++;
break;
}
} m_pVB->Unlock();
}

屏保设置方式
XP:
将目录下的所有文件拷贝到WINDOWS系统目录下如"C:\WINDOWS\system32"
在设置屏保的对话框中,选择"LineFlowerSP"

WIN7,WIN8
将目录下的所有文件拷贝到"C:\WINDOWS\SysWOW64"或"C:\WINDOWS\SysWOW32"目录下
在设置屏保的对话框中,选择"LineFlowerSP"

05-08 08:29