// ifs01Dlg.cpp : implementation file
//
#include "stdafx.h"
#include "ifs01.h"
#include "ifs01Dlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CIfs01Dlg dialog
CIfs01Dlg::CIfs01Dlg(CWnd* pParent /*=NULL*/)
: CDialog(CIfs01Dlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CIfs01Dlg)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CIfs01Dlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CIfs01Dlg)
// NOTE: the ClassWizard will add DDX and DDV calls here
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CIfs01Dlg, CDialog)
//{{AFX_MSG_MAP(CIfs01Dlg)
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CIfs01Dlg message handlers
BOOL CIfs01Dlg::OnInitDialog()
{
CDialog::OnInitDialog();
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon
// TODO: Add extra initialization here
return TRUE; // return TRUE unless you set the focus to a control
}
// If you add a minimize button to your dialog, you will need the code below
// to draw the icon. For MFC applications using the document/view model,
// this is automatically done for you by the framework.
void CIfs01Dlg::OnPaint()
{
AfxGetMainWnd()->SetWindowText("IFS系统(分形频道:fractal.cn)2004");
if (IsIconic())
{
CPaintDC dc(this); // device context for painting
SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
// Center icon in client rectangle
int cxIcon = GetSystemMetrics(SM_CXICON);
int cyIcon = GetSystemMetrics(SM_CYICON);
CRect rect;
GetClientRect(&rect);
int x = (rect.Width() - cxIcon + 1) / 2;
int y = (rect.Height() - cyIcon + 1) / 2;
// Draw the icon
dc.DrawIcon(x, y, m_hIcon);
}
else
{
CDialog::OnPaint();
}
}
HCURSOR CIfs01Dlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
/**
绘制图形
*/
void CIfs01Dlg::OnOK()
{
CDC * pDC = GetDC();
ifs(pDC);
ReleaseDC(pDC);
}
void CIfs01Dlg::ifs(CDC *pDC)
{
float x=0; // '仿射变换中的自变量
float y=0;
float newx, newy; //'仿射变换产生的新点
float a, b, c, d, e, f; //'仿射变幻中的系数
long n=100000; // '迭代次数
float R; //'随机变量
float m[7][7]={0}; // '存放IFS码
//'IFS码赋值
m[0][0] = 0.5; m[0][1] = 0; m[0][2] = 0; m[0][3] = 0.5; m[0][4] = 0; m[0][5] = 0; m[0][6] = 0.333;
m[1][0] = 0.5; m[1][1] = 0; m[1][2] = 0; m[1][3] = 0.5; m[1][4] = 0.5; m[1][5] = 0; m[1][6] = 0.333;
m[2][0] = 0.5; m[2][1] = 0; m[2][2] = 0; m[2][3] = 0.5; m[2][4] = 0.25; m[2][5] = 0.5; m[2][6] = 0.334;
//'循环迭代,在不同的概率空间下,赋不同的IFS码值
while (n > 0) {
R = (float)rand()/RAND_MAX;
if (R <= m[0][6]) {
a = m[0][0]; b = m[0][1]; c = m[0][2]; d = m[0][3]; e = m[0][4]; f = m[0][5];
} else if (R <= m[0][6] + m[1][6]) {
a = m[1][0]; b = m[1][1]; c = m[1][2]; d = m[1][3]; e = m[1][4]; f = m[1][5];
} else if (R <= m[0][6] + m[1][6] + m[2][6]) {
a = m[2][0]; b = m[2][1]; c = m[2][2]; d = m[2][3]; e = m[2][4]; f = m[2][5];
} else {
a = m[3][0]; b = m[3][1]; c = m[3][2]; d = m[3][3]; e = m[3][4]; f = m[3][5];
}
newx = (a * x) + (b * y) + e;
newy = (c * x) + (d * y) + f;
x = newx; y = newy;
pDC->SetPixelV((1000 + 7000 * x)/15, (6500 - 6000 * y)/15, RGB(x * 500 * R, R * 100, y * 2000 * R));
n--;
}
}