www.gusucode.com > VC++牛顿法解方程之混沌情况图形示例源代码源码程序 > VC++牛顿法解方程之混沌情况图形示例源代码源码程序\code\FactionView.cpp
// FactionView.cpp : implementation of the CFactionView class // Download by http://www.NewXing.com #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), 256 - abs((int)fabs(Se2 - (2*Se3-256) * pow(log(fabs(atan(log(fabs(sin(dL2)*sin(Hssx)+cos(Hssy))))))*2, Kn2) )%512-256), 256 - abs((int)fabs(Se3 - (2*Se1-256) * pow((fabs(temp2)-fabs(temp1))*2, Kn2) )%512-256)); break; case 13: M = 10; nM = 9; 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 + 3; se = RGB(256 - abs((int)fabs(Se1 - (2*Se2-256) * pow(log(fabs(sin(cos(dL3))))*2, Kn2) )%512-256), 256 - abs((int)fabs(Se2 - (2*Se3-256) * pow(log(fabs(cos(sin(dL3))))*2, Kn2) )%512-256), 256 - abs((int)fabs(Se3 - (2*Se1-256) * pow(log(fabs(sin(dL3)))*2, Kn2) )%512-256)); break; case 14: M = 1000; 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]*0.5f + 3; se = RGB(256 - abs((int)fabs(Se1 - (2*Se2-256) * pow(log(fabs(sin(cos(log(dL4)))))*2, Kn2) )%512-256), 256 - abs((int)fabs(Se2 - (2*Se3-256) * pow(log(fabs(cos(sin(log(dL4)))))*2, Kn2) )%512-256), 256 - abs((int)fabs(Se3 - (2*Se1-256) * pow(log(fabs(sin(log(dL4))))*2, Kn2) )%512-256)); break; case 15: temp1 = x0*x0 - y0*y0; temp2 = 2*x0*y0; x0 = temp1; y0 = temp2; temp1 = x0*x0 - y0*y0; temp2 = 2*x0*y0; x0 = temp1; y0 = temp2; M = 23; nM = 21; 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 - 3.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((10 * 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 16: M = 1000; 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] + 12; se = RGB(256 - abs((int)fabs(Se1 - (2*Se2-256) * pow((sin(M-i/1000 + log(fabs(dL2) + log(fabs(dL1)))))*2, Kn2)/M )%512-256), 256 - abs((int)fabs(Se2 - (2*Se3-256) * pow((cos(M-i/1000 + log(fabs(dL2) + log(fabs(dL3)))))*2, Kn2)/M )%512-256), 256 - abs((int)fabs(Se3 - (2*Se1-256) * pow((sin(M-i/1000 + (fabs(dL2))))*2, Kn2)/M )%512-256)); break; case 17: M = 1000; 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] + 9; se = RGB(256 - abs((int)fabs(Se1 - (2*Se2-256) * pow((log(dL1+0.001*dL2))*2, Kn2)/M)%512-256), 256 - abs((int)fabs(Se2 - (2*Se3-256) * pow((log(dL1+0.001*dL2))*2, Kn2)/M)%512-256), 256 - abs((int)fabs(Se3 - (2*Se1-256) * pow((log(dL2+0.001*dL2))*2, Kn2)/M)%512-256)); break; case 18: temp1 = x0*x0 - y0*y0; temp2 = 2*x0*y0; x0 = temp1; y0 = temp2; temp1 = sin(x0); temp2 = sin(y0); x0 = temp1; y0 = temp2; M = 23; nM = 21; 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 - 3.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((10 * 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 19: M = 1000; 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] + 9; se = RGB(256 - abs((int)fabs(Se1 - (2*Se2-256) * pow(tan(fabs(log(log(dL2+dL3) + sin(log(dL1+dL3)))))*2, Kn2)/M )%512-256), 256 - abs((int)fabs(Se2 - (2*Se3-256) * pow(tan(fabs(log(log(dL2+dL3) + sin(log(dL1+dL3)))))*2, Kn2)/M )%512-256), 256 - abs((int)fabs(Se3 - (2*Se1-256) * pow(tan(fabs(log(log(dL2+dL3) + sin(log(dL1+dL3)))))*2, Kn2)/M )%512-256)); break; case 20: temp1 = x0*x0 - y0*y0; temp2 = 2*x0*y0; x0 = temp1; y0 = temp2; 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; 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 21: 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=21; 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 22: 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=22; Kn2 = (float)G.m_dSeData[0][9] + 10; se = RGB(256 - abs((int)fabs(Se1 - (2*Se2-256) * pow((sin(log(10/i) + log(fabs(log(fabs(dL2))))))*2, Kn2)/M )%512-256), 256 - abs((int)fabs(Se2 - (2*Se3-256) * pow((cos(log(10/i) + log(fabs(log(fabs(dL2))))))*2, Kn2)/M )%512-256), 256 - abs((int)fabs(Se3 - (2*Se1-256) * pow((sin(log(10/i) + log(fabs(log(fabs(dL2))))))*2, Kn2)/M )%512-256)); break; case 23: temp1 = (x0*x0) - (y0*y0); temp2 = 2*x0*y0; x0 = temp1; y0 = temp2; G.Zshang(0.7, 0, x0, y0, &temp1, &temp2); x0 = temp1; y0 = temp2; M = 1000; nM = 30; i = G.MMi(x0, y0, int(G.m_dSeData[0][13]), M, nM, &Hssx, &Hssy, &dL1, &dL2, &dL3, &dL4); //i if(!i) i=23; Kn2 = (float)G.m_dSeData[0][9] + 10; se = RGB(256 - abs((int)fabs(Se1 - (2*Se2-256) * pow((sin(log(100/i) + sin(fabs(log(fabs(dL2))))))*2, Kn2)/M )%512-256), 256 - abs((int)fabs(Se2 - (2*Se3-256) * pow((cos(log(100/i) + sin(fabs(log(fabs(dL2))))))*2, Kn2)/M )%512-256), 256 - abs((int)fabs(Se3 - (2*Se1-256) * pow((sin(log(100/i) + cos(fabs(log(fabs(dL2))))))*2, Kn2)/M )%512-256)); break; case 24: M = 1000; nM = 30; i = G.MMi(x0, y0, int(G.m_dSeData[0][13]), M, nM, &Hssx, &Hssy, &dL1, &dL2, &dL3, &dL4); //i if(!i) i=24; Kn2 = (float)G.m_dSeData[0][9] + 10; se = RGB(256 - abs((int)fabs(Se1 - (2*Se2-256) * pow((sin(log(100/i)+1/(sin(fabs(log(fabs(dL2)))))))*2, Kn2)/M )%512-256), 256 - abs((int)fabs(Se2 - (2*Se3-256) * pow((cos(log(100/i)+1/(sin(fabs(log(fabs(dL2)))))))*2, Kn2)/M )%512-256), 256 - abs((int)fabs(Se3 - (2*Se1-256) * pow((sin(log(100/i)+1/(cos(fabs(log(fabs(dL2)))))))*2, Kn2)/M )%512-256)); break; case 25: M = 1000; nM = 10; i = G.MMi(x0, y0, int(G.m_dSeData[0][13]), M, nM, &Hssx, &Hssy, &dL1, &dL2, &dL3, &dL4); //i if(!i) i=25; Kn2 = (float)G.m_dSeData[0][9] + 11; temp1 = tan(fabs(sin(fabs(log(fabs(dL4)))))); temp2 = tan(fabs(sin(fabs(log(fabs(dL2)))))); se = RGB(256 - abs((int)fabs(Se1 - (2*Se2-256) * pow((sin(log(100/i)+temp1))*2, Kn2)/M )%512-256), 256 - abs((int)fabs(Se2 - (2*Se3-256) * pow((cos(log(100/i)+temp2))*2, Kn2)/M )%512-256), 256 - abs((int)fabs(Se3 - (2*Se1-256) * pow((sin(log(100/i)+temp1))*2, Kn2)/M )%512-256)); break; case 26: M = 1000; nM = 30; i = G.MMi(x0, y0, int(G.m_dSeData[0][13]), M, nM, &Hssx, &Hssy, &dL1, &dL2, &dL3, &dL4); //i if(!i) i=26; Kn2 = (float)G.m_dSeData[0][9] + 11; temp1 = tan(fabs(sin(fabs(log(fabs(dL4)))))); temp2 = tan(fabs(sin(fabs(log(fabs(dL2)))))); se = RGB(256 - abs((int)fabs(Se1 - (2*Se2-256) * pow((sin(log(100/i)+temp1))*2, Kn2)/M )%512-256), 256 - abs((int)fabs(Se2 - (2*Se3-256) * pow((cos(log(100/i)+temp2))*2, Kn2)/M )%512-256), 256 - abs((int)fabs(Se3 - (2*Se1-256) * pow((sin(log(100/i)+temp1))*2, Kn2)/M )%512-256)); break; case 27: temp1 = (x0*x0) - (y0*y0); temp2 = 2*x0*y0; x0 = temp1; y0 = temp2; G.Zshang(0.7, 0, x0, y0, &temp1, &temp2); x0 = temp1; y0 = temp2; 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; 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 28: temp1 = x0*x0 - y0*y0; temp2 = 2*x0*y0; x0 = temp1; y0 = temp2; temp1 = x0*x0 - y0*y0; temp2 = 2*x0*y0; x0 = temp1; y0 = temp2; 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 29: temp1 = tan(x0 / 1.5); temp2 = tan(y0); x0 = temp1; y0 = temp2; 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(pow(Hssy, 2.5)+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(pow(Hssx, 2.5)+0.000001)))*2, Kn2) )%512-256)); break; case 30: temp1 = x0*x0 - y0*y0; temp2 = 2*x0*y0; x0 = temp1; y0 = temp2; M = 23; nM = 21; 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 - 3.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((3 * 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 31: G.fz2(x0, y0, 0, 1, &temp1, &temp2, 2); x0 = temp1; y0 = temp2; temp1 = x0*x0 - y0*y0; temp2 = 2*x0*y0; x0 = temp1; y0 = temp2; temp1 = x0*x0 - y0*y0; temp2 = 2*x0*y0; x0 = temp1; y0 = temp2; 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; 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 32: G.fz2(y0, x0, 0.3, 0.3, &temp1, &temp2, 4); x0 = temp1; y0 = temp2; temp1 = x0*x0 - y0*y0; temp2 = 2*x0*y0; x0 = temp1; y0 = temp2; temp1 = x0*x0 - y0*y0; temp2 = 2*x0*y0; x0 = temp1; y0 = temp2; 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; default: 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] + 11.5f; 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)); } //temp = memDC.SetPixelV(A, B, se); temp = pDC->SetPixelV(A, B, se); //因为单独的绘图操作占整个显示图像的时间比很少,所以这里没有做优化, _ //但用API的函数还是比VB自带的快很多倍,(SetPixelV比SetPixel快) } MSG msg; while(PeekMessage(&msg,NULL,0,0,PM_REMOVE))//post all messages { TranslateMessage(&msg); DispatchMessage(&msg); } if(G.m_bESCStop) break; /* DoEvents If Mang <> Tmang Then //防止同时运行多个本线程的代码 Mang = -1 Exit Sub End If */ //Picture2保存绘制的图像(实际的图形),Picture1用来显示,以下代码实现显示,并尽量减少绘图操作。 /*tempA = int(A * frmMain.Picture1.ScaleWidth / frmMain.Picture2.ScaleWidth) If (tempA <> temp1 And tempA <> temp2) Then temp2 = temp1: temp1 = tempA frmMain.Picture1.PaintPicture frmMain.Picture2.Image, _ tempA, _ 0, _ int(1# * frmMain.Picture1.ScaleWidth / frmMain.Picture2.ScaleWidth + 0.999999999999), _ frmMain.Picture1.ScaleHeight, _ A, _ 0, _ 1, _ frmMain.Picture2.ScaleHeight, _ &HCC0020 Else tempA = -1 End If */ } //整幅图像全部刷新显示 /*frmMain.Picture1.PaintPicture frmMain.Picture2.Image, 0, 0, _ frmMain.Picture1.ScaleWidth, frmMain.Picture1.ScaleHeight, _ 0, _ 0, frmMain.Picture2.ScaleWidth, _ frmMain.Picture2.ScaleHeight, &HCC0020 frmMain.Picture1.Refresh */ //pDC->BitBlt(r.left,r.top,r.Width(),r.Height(),&memDC,0,0,SRCCOPY); } ///////////////////////////////////////////////////////////////////////////// // CFactionView printing BOOL CFactionView::OnPreparePrinting(CPrintInfo* pInfo) { // default preparation return DoPreparePrinting(pInfo); } void CFactionView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/) { // TODO: add extra initialization before printing } void CFactionView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/) { // TODO: add cleanup after printing } ///////////////////////////////////////////////////////////////////////////// // CFactionView diagnostics #ifdef _DEBUG void CFactionView::AssertValid() const { CView::AssertValid(); } void CFactionView::Dump(CDumpContext& dc) const { CView::Dump(dc); } CFactionDoc* CFactionView::GetDocument() // non-debug version is inline { ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CFactionDoc))); return (CFactionDoc*)m_pDocument; } #endif //_DEBUG ///////////////////////////////////////////////////////////////////////////// // CFactionView message handlers void CFactionView::OnFileRedraw() { // TODO: Add your command handler code here //g_document.UpdateAllViews(NULL); CRect rt; GetClientRect(rt); InvalidateRect(rt,FALSE); } /////////////////////////////////////////////////////// ////////保存为位图 START WORD WINAPI PaletteSize(LPSTR lpbi) { DWORD dwClrUsed; dwClrUsed=((LPBITMAPINFOHEADER)lpbi)->biClrUsed; if (dwClrUsed == 0) switch ( ((LPBITMAPINFOHEADER)lpbi)->biBitCount ) { case 1: dwClrUsed=2; break; case 4: dwClrUsed=16; break; case 8: dwClrUsed=256; break; default: dwClrUsed=0; break; } return (WORD)(dwClrUsed * sizeof(RGBQUAD)); } HANDLE WINAPI BitmapToDIB(HBITMAP hBitmap, HPALETTE hPal) { ASSERT(hBitmap); BITMAP bm; BITMAPINFOHEADER bi; LPBITMAPINFOHEADER lpbi; DWORD dwLen; HANDLE hDib,h; HDC hDC; WORD biBits; UINT wLineLen; DWORD dwSize; DWORD wColSize; if (!hBitmap) return NULL; if (!::GetObject(hBitmap, sizeof(bm), &bm)) return NULL; if (hPal == NULL) hPal = (HPALETTE)::GetStockObject(DEFAULT_PALETTE); biBits = (WORD) (bm.bmPlanes * bm.bmBitsPixel); wLineLen = ( bm.bmWidth * biBits + 31 ) / 32 * 4; wColSize = sizeof(RGBQUAD) * (( biBits <= 8 ) ? 1 << biBits : 0 ); dwSize = sizeof( BITMAPINFOHEADER ) + wColSize + (DWORD)(UINT)wLineLen * (DWORD)(UINT)bm.bmHeight; if (biBits <= 1) biBits = 1; else if (biBits <= 4) biBits = 4; else if (biBits <= 8) biBits = 8; else biBits = 24; bi.biSize = sizeof(BITMAPINFOHEADER); bi.biWidth = bm.bmWidth; bi.biHeight = bm.bmHeight; bi.biPlanes = 1; bi.biBitCount = biBits; bi.biCompression = BI_RGB; bi.biSizeImage = dwSize - sizeof(BITMAPINFOHEADER) - wColSize; bi.biXPelsPerMeter = 0; bi.biYPelsPerMeter = 0; bi.biClrUsed = ( biBits <= 8 ) ? 1 << biBits : 0; bi.biClrImportant = 0; dwLen = bi.biSize + ::PaletteSize((LPSTR) &bi); hDC = ::GetDC(NULL); hPal = ::SelectPalette(hDC, hPal, FALSE); ::RealizePalette(hDC); hDib = (HANDLE)::GlobalAlloc(GHND, dwLen); if (!hDib) { ::SelectPalette(hDC, hPal, TRUE); ::RealizePalette(hDC); ::ReleaseDC(NULL, hDC); return NULL; } lpbi = (LPBITMAPINFOHEADER)::GlobalLock((HGLOBAL)hDib); if (!lpbi) { ::SelectPalette(hDC, hPal, TRUE); ::RealizePalette(hDC); ::ReleaseDC(NULL, hDC); return NULL; } *lpbi = bi; ::GetDIBits(hDC, hBitmap, 0, (WORD)bi.biHeight, NULL, (LPBITMAPINFO)lpbi, DIB_RGB_COLORS); bi = *lpbi; bi.biClrUsed = ( biBits <= 8 ) ? 1 << biBits : 0; ::GlobalUnlock(hDib); if (bi.biSizeImage == 0) bi.biSizeImage = ( ( ( (DWORD)bm.bmWidth * biBits ) + 31 ) / 32 * 4) * bm.bmHeight; dwLen = bi.biSize+::PaletteSize((LPSTR)&bi)+bi.biSizeImage; h = (HANDLE)::GlobalReAlloc(hDib, dwLen, 0); if ( h ) { hDib = h; } else { ::GlobalFree(hDib); hDib = NULL; ::SelectPalette(hDC, hPal, TRUE); ::RealizePalette(hDC); ::ReleaseDC(NULL, hDC); return NULL; } lpbi = (LPBITMAPINFOHEADER)::GlobalLock((HGLOBAL)hDib); if (!lpbi) { ::GlobalFree(hDib); hDib = NULL; ::SelectPalette(hDC, hPal, TRUE); ::RealizePalette(hDC); ::ReleaseDC(NULL, hDC); return NULL; } if (::GetDIBits(hDC,hBitmap,0,(WORD)bi.biHeight, (LPSTR)lpbi + (WORD)lpbi->biSize + ::PaletteSize((LPSTR) lpbi), (LPBITMAPINFO)lpbi,DIB_RGB_COLORS) == 0) { ::GlobalUnlock(hDib); hDib = NULL; ::SelectPalette(hDC, hPal, TRUE); ::RealizePalette(hDC); ::ReleaseDC(NULL, hDC); return NULL; } bi = *lpbi; ::GlobalUnlock(hDib); ::SelectPalette(hDC, hPal, TRUE); ::RealizePalette(hDC); ::ReleaseDC(NULL, hDC); return hDib; } HANDLE WINAPI WindowToDIB(CWnd *pWnd, CRect* pRect) { CBitmap bitmap; CWindowDC dc(pWnd); CDC memDC; CRect rect; memDC.CreateCompatibleDC(&dc); if ( pRect == NULL ) { pWnd->GetWindowRect(rect); rect.OffsetRect(-rect.left,-rect.top); } else rect = *pRect; bitmap.CreateCompatibleBitmap(&dc, rect.Width(),rect.Height() ); CBitmap* pOldBitmap = memDC.SelectObject(&bitmap); memDC.BitBlt(0, 0, rect.Width(),rect.Height(), &dc, rect.left, rect.top, SRCCOPY); CPalette pal; if ( dc.GetDeviceCaps(RASTERCAPS) & RC_PALETTE ) { UINT nSize=sizeof(LOGPALETTE) + (sizeof(PALETTEENTRY) * 256); LOGPALETTE *pLP=(LOGPALETTE *) new BYTE[nSize]; pLP->palVersion=0x300; pLP->palNumEntries = (USHORT) GetSystemPaletteEntries( dc, 0, 255, pLP->palPalEntry ); pal.CreatePalette( pLP ); delete[] pLP; } memDC.SelectObject(pOldBitmap); HANDLE hDib = BitmapToDIB( bitmap, pal ); return hDib; } BOOL WINAPI SaveDIBFile(HANDLE hDib, CFile& file) { BITMAPFILEHEADER bmfHdr; LPBITMAPINFOHEADER lpBI; DWORD dwDIBSize; if (hDib == NULL) return FALSE; lpBI = (LPBITMAPINFOHEADER) ::GlobalLock((HGLOBAL) hDib); if (lpBI == NULL) return FALSE; bmfHdr.bfType = ((WORD) ('M' << 8) | 'B'); // "BM" dwDIBSize = *(LPDWORD)lpBI + ::PaletteSize((LPSTR)lpBI); if ((lpBI->biCompression == BI_RLE8) || (lpBI->biCompression == BI_RLE4)) { dwDIBSize += lpBI->biSizeImage; } else { DWORD dwBmBitsSize; dwBmBitsSize = ( ( (lpBI->biWidth)*((DWORD)lpBI->biBitCount) + 31) / 32 * 4) * lpBI->biHeight; dwDIBSize += dwBmBitsSize; lpBI->biSizeImage = dwBmBitsSize; } bmfHdr.bfSize = dwDIBSize + sizeof(BITMAPFILEHEADER); bmfHdr.bfReserved1 = 0; bmfHdr.bfReserved2 = 0; bmfHdr.bfOffBits = (DWORD)sizeof(BITMAPFILEHEADER) + lpBI->biSize + PaletteSize((LPSTR)lpBI); file.Write((LPSTR)&bmfHdr, sizeof(BITMAPFILEHEADER)); file.WriteHuge(lpBI, dwDIBSize); ::GlobalUnlock((HGLOBAL) hDib); return TRUE; } ////////保存为位图 END /////////////////////////////////////////////////////// /*void CSaveDibView::OnViewSave() { CWnd *pWnd=AfxGetMainWnd(); HANDLE hDib=WindowToDIB(pWnd,NULL); CFile file; file.Open("save.bmp",CFile::modeCreate|CFile::modeWrite); SaveDIBFile(hDib,file); file.Close(); GlobalFree(hDib); }*/ void CFactionView::OnFileSaveAsBmp() { // TODO: Add your command handler code here static char BASED_CODE szFilter[] = "BMP Files (*.BMP)|*.BMP|All Files (*.*)|*.*||"; CFileDialog fileDlg(FALSE, NULL, "*.bmp", OFN_HIDEREADONLY|OFN_OVERWRITEPROMPT, szFilter, this); fileDlg.m_ofn.lpstrTitle = "选择BMP位图文件"; char cPath[128]; CString csFile; GetCurrentDirectory(128, cPath); fileDlg.m_ofn.lpstrInitialDir = cPath; if( fileDlg.DoModal() == IDOK) { csFile = fileDlg.GetPathName(); if( ! csFile.GetLength() ) return; } SetCurrentDirectory(cPath); CWnd *pWnd=AfxGetMainWnd(); HANDLE hDib=WindowToDIB(pWnd,NULL); CFile file; file.Open(csFile,CFile::modeCreate|CFile::modeWrite); SaveDIBFile(hDib,file); file.Close(); GlobalFree(hDib); }