EasyIFS分形学演示工具是ZH@EASYX.CN用easyx库写的作品,体积比较大,并且不属于控制台程序,我用GDI库改写了该工具,使其可以在批处理中批量调用,并修复原版个别漏洞。体积也由112KB缩小到13KB。
下载附件:http://bcn.bathome.net/s/tool/index.html?key=EasyIFS
图片均为外链图
 | | | | | | | | | | | #include <string> | | #include <vector> | | #include <stdio.h> | | #include <windows.h> | | #include <conio.h> | | #include <time.h> | | #include <io.h> | | | | using namespace std; | | | | | | #if defined (__GNUC__) || (_MSC_VER == 1200) | | extern "C" HWND WINAPI GetConsoleWindow(); | | #endif | | | | | | #define F_EXIST 4 | | #define E_WITH 640 | | #define E_HIGH 480 | | | | | | #define HELP_INFORMATION "\ | | Usage: easyifs [file]\n\ | | \n\ | | The probability of requiring each formula and equ 1\n\ | | IFS configuration file:\n\ | | \n\ | | [Main]\n\ | | name = IFS name\n\ | | iterLimit = number of iterations\n\ | | color = drawing color\n\ | | minX = the lower limit of x\n\ | | maxX = the upper limit of x\n\ | | minY = the lower limit of y\n\ | | maxY = the upper limit of y\n\ | | condition = the number of formulas\n\ | | [Conditionx]\n\ | | p = probability\n" | | | | | | | | struct MAIN | | { | | string name; | | int iterLimit; | | int color; | | double scale; | | int offsetX, offsetY; | | }; | | | | | | struct IFS | | { | | int p; | | double a, b, c, d, e, f; | | }; | | | | | | MAIN g_main; | | vector<IFS> g_ifs; | | | | | | double GetPrivateProfileDouble(LPCTSTR lpAppName, LPCTSTR lpKeyName, double fDefault, LPCTSTR lpFileName) | | { | | TCHAR d[50]; | | GetPrivateProfileString(lpAppName, lpKeyName, NULL, d, 50, lpFileName); | | return (d[0]!=0)?atof(d):fDefault; | | } | | | | | | int initargs(int argc, char** argv) | | { | | | | if (argc <= 1) | | { | | fprintf(stdout, HELP_INFORMATION); | | exit(1); | | } | | | | | | double ix, ax, iy, ay, sx, sy; | | | | char tmpFpath[MAX_PATH*2]; | | if(strrchr(argv[1], ':')==NULL) | | { | | strcpy(tmpFpath, ".\\"); | | strcat(tmpFpath, argv[1]); | | } | | else | | { | | strcpy(tmpFpath, argv[1]); | | } | | | | char* filename=tmpFpath; | | | | | | if (_access(filename, F_EXIST) != 0) | | { | | fprintf(stdout, "The file \"%s\" does not exist or is disabled.\n", argv[1]); | | exit(2); | | } | | | | | | char tmpName[MAX_PATH*2]; | | GetPrivateProfileStringA("main", "name", "noname", tmpName, 50, filename); | | g_main.name = tmpName; | | | | | | g_main.iterLimit = GetPrivateProfileIntA("main", "iterLimit", 0, filename); | | | | | | g_main.color = GetPrivateProfileIntA("main", "color", 0xff00, filename); | | | | | | ix = GetPrivateProfileDouble("main", "minX", 0, filename); | | ax = GetPrivateProfileDouble("main", "maxX", 0, filename); | | sx = E_WITH / (ax - ix); | | | | | | iy = GetPrivateProfileDouble("main", "minY", 0, filename); | | ay = GetPrivateProfileDouble("main", "maxY", 0, filename); | | sy = E_HIGH / (ay - iy); | | | | | | if (sx > sy) | | { | | g_main.scale = sy; | | g_main.offsetX = (int)(-ix * g_main.scale + (E_WITH - (ax - ix) * g_main.scale) / 2); | | g_main.offsetY = (int)(-iy * g_main.scale); | | } | | else | | { | | g_main.scale = sx; | | g_main.offsetX = (int)(-ix * g_main.scale); | | g_main.offsetY = (int)(-iy * g_main.scale + (E_HIGH - (ay - iy) * g_main.scale) / 2); | | } | | | | | | int n; | | n = GetPrivateProfileIntA("main", "condition", 0, filename); | | | | | | IFS ifs; | | int sump = 0; | | char app[] = "condition?"; | | for(int i=0; i<n; i++) | | { | | app[9] = ('1' + i); | | ifs.a = GetPrivateProfileDouble(app, "a", 0, filename); | | ifs.b = GetPrivateProfileDouble(app, "b", 0, filename); | | ifs.c = GetPrivateProfileDouble(app, "c", 0, filename); | | ifs.d = GetPrivateProfileDouble(app, "d", 0, filename); | | ifs.e = GetPrivateProfileDouble(app, "e", 0, filename); | | ifs.f = GetPrivateProfileDouble(app, "f", 0, filename); | | ifs.p = int(GetPrivateProfileDouble(app, "p", 0, filename) * 1000000 + 0.5); | | ifs.p += sump; | | sump = ifs.p; | | | | g_ifs.push_back(ifs); | | } | | | | | | if (sump != 1000000) | | { | | fprintf(stdout, "IFS configuration file in the probability of the formula and not equal to 1, please check the configuration file.\n"); | | exit(3); | | } | | | | return 0; | | } | | | | | | int main(int argc, char* argv[]) | | { | | | | initargs(argc, argv); | | srand(unsigned(time(NULL))); | | | | | | HWND hCMD=GetConsoleWindow(); | | | | InvalidateRect(hCMD, NULL, TRUE); | | | | HDC hDC=GetDC(hCMD); | | | | | | double x = 0, y = 0, tx; | | int p, k; | | | | | | | | | | | | | | | | | | | | for(int i=0; i<g_main.iterLimit; i++) | | { | | | | p = int(double(rand()) / RAND_MAX * 1000000 + 0.5); | | | | | | for(k=0; k< (int)g_ifs.size(); k++) | | if (p <= g_ifs[k].p) break; | | | | | | tx = g_ifs[k].a * x + g_ifs[k].b * y + g_ifs[k].e; | | y = g_ifs[k].c * x + g_ifs[k].d * y + g_ifs[k].f; | | x = tx; | | | | | | SetPixel(hDC, int(x * g_main.scale) + g_main.offsetX, E_HIGH - (int(y * g_main.scale) + g_main.offsetY), g_main.color); | | } | | return 0; | | }COPY |
|