📄 factionview.cpp
字号:
// FactionView.cpp : implementation of the CFactionView class
//
#include "stdafx.h"
#include "Global.h"
#include "Faction.h"
#include "FactionDoc.h"
#include "FactionView.h"
#include <math.h>
#include "MemDC.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CFactionView
IMPLEMENT_DYNCREATE(CFactionView, CView)
BEGIN_MESSAGE_MAP(CFactionView, CView)
//{{AFX_MSG_MAP(CFactionView)
ON_COMMAND(ID_FILE_SAVE_AS_BMP, OnFileSaveAsBmp)
ON_COMMAND(ID_FILE_REDRAW, OnFileRedraw)
//}}AFX_MSG_MAP
// Standard printing commands
ON_COMMAND(ID_FILE_PRINT, CView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_DIRECT, CView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_PREVIEW, CView::OnFilePrintPreview)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CFactionView construction/destruction
CFactionView::CFactionView()
{
// TODO: add construction code here
}
CFactionView::~CFactionView()
{
}
BOOL CFactionView::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return CView::PreCreateWindow(cs);
}
/////////////////////////////////////////////////////////////////////////////
// CFactionView drawing
void CFactionView::OnDraw(CDC* pDC)
{
CFactionDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
// TODO: add draw code for native data here
// 具体执行绘制操作的过程
int i;
//临时用变量 temp
int temp;
double temp1, temp2;//, tempA, temp3, temp4, temp5;
double x1, y1, x2, y2; //记录坐标范围
int M, nM; //最大迭代次数;最小迭代次数
// double Tmang; //防止同时运行多个本线程的代码
int Se1, Se2, Se3, se; //记录颜色的变量
int A, B, n; //从中间开始向两边绘制时使用的变量
double x0, y0; //复平面上的一个点
float Kn2;// As Single //颜色渐变强度调节参数
double Hssx, Hssy; //用来保存返回的函数的一项性质,用作颜色函数的参数,(下同 )
double dL1, dL2, dL3, dL4;
//------------------------------------------------------------
CRect r; GetClientRect(r);
//CMemDC memDC(pDC,r.right,r.bottom,TRUE);
//picX = Picture2.ScaleWidth: picY = Picture2.ScaleHeight //绘图显示尺寸
int picX = r.Width();
int picY = r.Height();
G.m_dwWidth = picX;
G.m_dwHeight = picY;
//坐标范围
x1 = G.m_dSeData[0][1]; y1 = G.m_dSeData[0][2];
x2 = G.m_dSeData[0][3]; y2 = G.m_dSeData[0][4];
G.m_bESCStop=FALSE;
Se1 = (int)G.m_dSeData[0][6];
Se2 = (int)G.m_dSeData[0][7];
Se3 = (int)G.m_dSeData[0][8]; //调色参数
A = picX / 2; //从中间开始向两边绘制
temp1 = -1;
temp2 = -1;
for(n=0; n<=picX; n++)
{
A = A-((n%2)*2-1)*n; //总体上从中间向两边绘制
for(B=0; B<=picY; B++) //从上到下绘制
{
if(int(G.m_dSeData[0][13]) == 4)
{
int nColor = G.MDBLT(A,B);
se = RGB(nColor,nColor>127?nColor:128+nColor,255-nColor);
pDC->SetPixelV(A, B, se);
continue;
}
x0 = (x2-x1) * A / picX + x1;
y0 = (y2-y1) * B / picY + y1; //获得复平面上的一个点
if(x0==0) x0 = 1E-150; //最好不要有(0,0)点
if(y0==0) y0 = 1E-150;
//特效处理(4重),原理是对(x0,y0)点进行某种变换,使点映射得一个新的复表面上
for(i=3; i>=0; i--)
{
switch(int(G.m_dSeData[0][16]/(100^i))%100)
{
case 0:
//无
break;
case 1: //圆
temp1 = sqrt(x0*x0 + y0*y0);
temp2 = G.ZArg(y0, x0, 0);
temp = int(temp1);
if(temp!=1){
temp1 -=temp;
temp = (temp1>0 ? 1 : (temp1<0 ? -1 : 0));
x0 = temp*(sqrt(2*temp1*temp1/(1-temp1*temp1))+temp1);
y0 = temp2;
}
else{
x0 = temp1;
y0 = 45 / 180 * PI;
}
temp1 = x0;
temp2 = y0;
x0 = temp1 * cos(temp2);
y0 = temp1 * sin(temp2);
break;
case 2: //加倍
temp1 = x0*x0 - y0*y0;
temp2 = 2*x0*y0;
x0 = temp1;
y0 = temp2;
break;
case 3: //平铺
temp1 = tan(x0 / 1.5);
temp2 = tan(y0);
x0 = temp1;
y0 = temp2;
break;
case 4: //网
temp1 = sin(x0 * 2 + y0 * 2);
temp2 = cos(x0 * 2 - y0 * 2);
x0 = temp1;
y0 = temp2;
break;
case 5: //黎曼面
temp1 = sqrt(x0 * x0 + y0 * y0);
temp2 = G.ZArg(x0, y0, 0);
temp1 = tan(temp1 * 1.5) * 2;
x0 = temp1 * sin(temp2);
y0 = temp1 * cos(temp2);
break;
case 6: //1/c
G.Zshang(1, 0, x0, y0, &temp1, &temp2);
x0 = temp1;
y0 = temp2;
break;
case 7: //Mandelbrot
G.fz2(x0 - 0.5, y0, x0 - 0.5, y0, &temp1, &temp2, 4);
x0 = temp1;
y0 = temp2;
break;
}
}
//颜色方案处理原理
// RGB(256 - ((x1 % 512) - 256),
// 256 - ((x2 % 512) - 256),
// 256 - ((x3 % 512) - 256))
//程序中这样可以保持颜色的渐变
//这样更好: RGB(255 - ((x1 % 511) - 255),
// 255 - ((x2 % 511) - 255),
// 255 - ((x3 % 511) - 255))
//
se = RGB((int)G.m_dSeData[0][6], (int)G.m_dSeData[0][7], (int)G.m_dSeData[0][8]); //默认颜色
//
switch((int)G.m_dSeData[0][19] + 1)
{ //颜色方案 (其中有的效果有上面使用的特效处理方式,特效独立出来是由伍胜富先生提出的)
case 1:
M = 10000;
nM = 11;
i = G.MMi(x0, y0, int(G.m_dSeData[0][13]), M, nM, &Hssx, &Hssy, &dL1, &dL2, &dL3, &dL4); //i
Kn2 = (float)G.m_dSeData[0][9] + 10;
se = RGB(256 - abs((int)fabs(Se1 - (2*Se2-256) * pow((M-i)*2, Kn2)/M )%512-256),
256 - abs((int)fabs(Se2 - (2*Se3-256) * pow((M-i)*2, Kn2)/M )%512-256),
256 - abs((int)fabs(Se3 - (2*Se1-256) * pow((M-i)*2, Kn2)/M )%512-256) );
break;
case 2:
M = 3;
nM = 1;
i = G.MMi(x0, y0, int(G.m_dSeData[0][13]), M, nM, &Hssx, &Hssy, &dL1, &dL2, &dL3, &dL4); //i
Kn2 = (float)G.m_dSeData[0][9] / 2;
se = RGB(256 - abs((int)fabs(Se1 - (2*Se2-256) * pow((log(fabs(Hssy)))*2,Kn2) )%512-256),
256 - abs((int)fabs(Se2 - (2*Se3-256) * pow((log(dL1))*2,Kn2) )%512-256),
256 - abs((int)fabs(Se3 - (2*Se1-256) * pow((log(fabs(Hssx)))*2,Kn2) )%512-256));
break;
case 3:
M = 3;
nM = 1;
i = G.MMi(x0, y0, int(G.m_dSeData[0][13]), M, nM, &Hssx, &Hssy, &dL1, &dL2, &dL3, &dL4); //i
Kn2 = ((float)G.m_dSeData[0][9] + 5) / 2;
se = RGB(256 - abs((int)fabs(Se1 - (2*Se2-256) * pow(log(dL1)*2,Kn2) )%512-256),
256 - abs((int)fabs(Se2 - (2*Se3-256) * pow((fabs(cos(Hssx)))*2,Kn2) )%512-256),
256 - abs((int)fabs(Se3 - (2*Se1-256) * pow((fabs(cos(Hssy)))*2,Kn2) )%512-256));
break;
case 4:
M = 3;
nM = 1;
i = G.MMi(x0, y0, int(G.m_dSeData[0][13]), M, nM, &Hssx, &Hssy, &dL1, &dL2, &dL3, &dL4); //i
Kn2 = (float)G.m_dSeData[0][9] / 2;
se = RGB(256 - abs((int)fabs(Se1 - (2*Se2-256) * pow((dL1/Hssx)*2,Kn2) )%512-256),
256 - abs((int)fabs(Se2 - (2*Se3-256) * pow((tan(Hssy)/dL1)*2,Kn2) )%512-256),
256 - abs((int)fabs(Se3 - (2*Se1-256) * pow((Hssx/Hssy)*2,Kn2) )%512-256));
break;
case 5:
temp1 = sqrt(x0*x0 + y0*y0);
temp2 = G.ZArg(y0, x0, 0);
temp = int(temp1);
if(temp != 1){
temp1 -= temp;
int sgn = temp1>0 ? 1 : (temp1<0 ? -1 : 0);
x0 = sgn * (sqrt(2*temp1*temp1/(1-temp1*temp1))+temp1);
y0 = temp2;
}
else{
x0 = temp1;
y0 = 45 / 180 * PI;
}
temp1 = x0;
temp2 = y0;
x0 = temp1 * cos(temp2);
y0 = temp1 * sin(temp2);
M = 1000;
nM = 15;
i = G.MMi(x0, y0, int(G.m_dSeData[0][13]), M, nM, &Hssx, &Hssy, &dL1, &dL2, &dL3, &dL4); //i
if( !i) i=7;
dL2 = dL2;
Kn2 = (float)G.m_dSeData[0][9] + 10;
se = RGB(256 - abs((int)fabs(Se1 - (2*Se2-256) * pow((sin(log(1/i)+log(fabs(dL2))))*2, Kn2)/M )%512 - 256),
256 - abs((int)fabs(Se2 - (2*Se3-256) * pow((cos(log(1/i)+log(fabs(dL2))))*2, Kn2)/M )%512 - 256),
256 - abs((int)fabs(Se3 - (2*Se1-256) * pow((sin(log(1/i)+log(fabs(dL2))))*2, Kn2)/M )%512 - 256));
break;
case 6:
M = 3;
nM = 1;
i = G.MMi(x0, y0, int(G.m_dSeData[0][13]), M, nM, &Hssx, &Hssy, &dL1, &dL2, &dL3, &dL4); //i
Kn2 = (float)G.m_dSeData[0][9] / 2;
se = RGB(66, 124, 221);
se = RGB(256 - abs((int)fabs(Se1 - (2*Se2-256) * pow((log(log(fabs(Hssy))))*2, Kn2) )%512-256),
256 - abs((int)fabs(Se2 - (2*Se3-256) * pow((log(log(dL1)))*2, Kn2) )%512-256),
256 - abs((int)fabs(Se3 - (2*Se1-256) * pow((log(log(fabs(Hssx))))*2, Kn2) )%512-256));
break;
case 7:
M = 13;
nM = 11;
i = G.MMi(x0, y0, int(G.m_dSeData[0][13]), M, nM, &Hssx, &Hssy, &dL1, &dL2, &dL3, &dL4); //i
Kn2 = (float)G.m_dSeData[0][9]*0.5f - 1.5f;
se = RGB(256 - abs((int)fabs(Se1 - (2*Se2-256) * pow((log(fabs(Hssx*Hssx+0.000001)))*2, Kn2) )%512-256),
256 - abs((int)fabs(Se2 - (2*Se3-256) * pow((log(dL2+0.000001))*2, Kn2) )%512-256),
256 - abs((int)fabs(Se3 - (2*Se1-256) * pow((log(fabs(Hssy*Hssy+0.000001)))*2, Kn2) )%512-256));
break;
case 8:
M = 4;
nM = 2;
i = G.MMi(x0, y0, int(G.m_dSeData[0][13]), M, nM, &Hssx, &Hssy, &dL1, &dL2, &dL3, &dL4); //i
Kn2 = (float)G.m_dSeData[0][9]*0.5f - 1.5f;
se = RGB(256 - abs((int)fabs(Se1 - (2*Se2-256) * pow((log(fabs(Hssx*Hssx+0.000001)))*2, Kn2) )%512-256),
256 - abs((int)fabs(Se2 - (2*Se3-256) * pow((log((dL2*100+Hssy+0.000001)))*2, Kn2) )%512-256),
256 - abs((int)fabs(Se3 - (2*Se1-256) * pow((log(fabs(Hssy*Hssy+0.000001)))*2, Kn2) )%512-256));
break;
case 9:
M = 5;
nM = 3;
i = G.MMi(x0, y0, int(G.m_dSeData[0][13]), M, nM, &Hssx, &Hssy, &dL1, &dL2, &dL3, &dL4); //i
Kn2 = (float)G.m_dSeData[0][9]*0.5f - 1.5f;
se = RGB(256 - abs((int)fabs(Se1 - (2*Se2-256) * pow((log(fabs((Hssx+Hssy)*(Hssx+Hssy)+0.000001)))*2, Kn2) )%512-256),
256 - abs((int)fabs(Se2 - (2*Se3-256) * pow((log((dL2 * 100+0.000001)))*2, Kn2) )%512-256),
256 - abs((int)fabs(Se3 - (2*Se1-256) * pow((log(fabs((Hssx+Hssy)*(Hssx+Hssy)+0.000001)))*2, Kn2) )%512-256));
break;
case 10:
M = 4;
nM = 3;
i = G.MMi(x0, y0, int(G.m_dSeData[0][13]), M, nM, &Hssx, &Hssy, &dL1, &dL2, &dL3, &dL4); //i
Kn2 = (float)G.m_dSeData[0][9]*0.5f - 1;
se = RGB(256 - abs((int)fabs(Se1 - (2*Se2-256) * pow((log(fabs((Hssy*Hssy)/(Hssx*Hssx)+0.000001)))*2, Kn2) )%512-256),
256 - abs((int)fabs(Se2 - (2*Se3-256) * pow((log((dL2+0.000001)))*2, Kn2) )%512-256),
256 - abs((int)fabs(Se3 - (2*Se1-256) * pow((log(fabs((Hssx+Hssy)*(Hssx+Hssy)+0.000001)))*2, Kn2) )%512-256));
break;
case 11:
M = 22;
nM = 20;
i = G.MMi(x0, y0, int(G.m_dSeData[0][13]), M, nM, &Hssx, &Hssy, &dL1, &dL2, &dL3, &dL4); //i
Kn2 = (float)G.m_dSeData[0][9]*0.5f - 1;
se = RGB(256 - abs((int)fabs(Se1 - (2*Se2-256) * pow((cos(log(fabs(Hssy+0.000001))))*2, Kn2) )%512-256),
256 - abs((int)fabs(Se2 - (2*Se3-256) * pow((log((dL2/dL1*Hssx*Hssy+0.000001)))*2, Kn2) )%512-256),
256 - abs((int)fabs(Se3 - (2*Se1-256) * pow((cos(log(fabs(Hssx+0.000001))))*2, Kn2) )%512-256));
break;
case 12:
M = 14;
nM = 13;
i = G.MMi(x0, y0, int(G.m_dSeData[0][13]), M, nM, &Hssx, &Hssy, &dL1, &dL2, &dL3, &dL4); //i
Kn2 = (float)G.m_dSeData[0][9]*0.5f - 1;
temp1 = atan2(Hssy, Hssx) + dL2;
temp2 = atan2(Hssx, Hssy) - dL2;
se = RGB(256 - abs((int)fabs(Se1 - (2*Se2-256) * pow((fabs(temp1))*2, Kn2) )%512-256),
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -