diff --git a/Include/Color.h b/Include/Color.h index c440796..d403acb 100644 --- a/Include/Color.h +++ b/Include/Color.h @@ -15,4 +15,4 @@ COLORREF Grad(COLORREF c0, COLORREF c1, double t); DWORD ColorAt(UINT x, UINT y, UINT width, UINT height); // width*heightのウィンドウにおける点(x,y)の漸化式適用回数を返す関数 -int Calc(UINT x, UINT y, UINT width, UINT height); \ No newline at end of file +INT Calc(UINT x, UINT y, UINT width, UINT height); \ No newline at end of file diff --git a/Include/Graph.h b/Include/Graph.h index d8fd9ec..f468fd6 100644 --- a/Include/Graph.h +++ b/Include/Graph.h @@ -14,7 +14,8 @@ struct GRAPH{ double size; double scale; UINT limit; - int color_mode; + int inner_color_mode; + int outer_color_mode; COLORREF color0;// 収束部 COLORREF color1;// 発散部1 COLORREF color2;// 発散部2 diff --git a/Include/Resource.h b/Include/Resource.h index eb63efa..1da565d 100644 --- a/Include/Resource.h +++ b/Include/Resource.h @@ -68,6 +68,13 @@ #define IDM_INITAREA 5510// #define IDM_INITCOLOR 5520// +#define GCM_I_SOLID 0 +#define GCM_I_GRAD 1 +#define GCM_O_TEMPLATE0 0 +#define GCM_O_TEMPLATE1 1 +#define GCM_O_TEMPLATE2 2 +#define GCM_O_CUSTOM 3 + #define IDI_MANDELBROTSET 107 #define IDI_SMALL 108 #define IDC_MANDELBROTSET 109 diff --git a/Source/Color.c b/Source/Color.c index 82ea680..3a7aad2 100644 --- a/Source/Color.c +++ b/Source/Color.c @@ -1,5 +1,7 @@ #include "Color.h" #include "Graph.h" +#define _USE_MATH_DEFINES +#include extern struct GRAPH graph; @@ -54,33 +56,51 @@ DWORD ColorAt(UINT x, UINT y, UINT width, UINT height) { //if ((x - width / 2) * (x - width / 2) + (y - height / 2) * (y - height / 2) < 50)return 0x00ff0000; int t = Calc(x, y, width, height); - if (t < 0) return (DWORD)graph.color0; - //return (DWORD)((t * 4 % 128 + 64) * 0x00010100); - //return (DWORD)HSV(t%128/128.0, 0.7, 1.0); - switch (graph.color_mode) - { - case 3: - return (DWORD)Grad(graph.color1, graph.color2, (1.0 * t / graph.limit - graph.color_stop0) / (graph.color_stop1 - graph.color_stop0)); - default: - return (DWORD)HSV(t / 40.0, 1 - graph.color_mode / 3.0, 1); + if (t < 0) { + switch (graph.inner_color_mode) { + case GCM_I_SOLID: + return (DWORD)graph.color0; + case GCM_I_GRAD: + return (DWORD)Grad(graph.color1, graph.color2, (1.0 * t / graph.limit - graph.color_stop0) / (graph.color_stop1 - graph.color_stop0)); + } + } + else { + //return (DWORD)((t * 4 % 128 + 64) * 0x00010100); + //return (DWORD)HSV(t%128/128.0, 0.7, 1.0); + switch (graph.outer_color_mode) + { + case GCM_O_CUSTOM: + return (DWORD)Grad(graph.color1, graph.color2, (1.0 * t / graph.limit - graph.color_stop0) / (graph.color_stop1 - graph.color_stop0)); + default: + return (DWORD)HSV(t / 40.0, 1 - graph.outer_color_mode / 3.0, 1); + } + //return (x + y) % 0x01000000; + //return (0x01000000 - 1) * (x + y) / (width + height); } - //return (x + y) % 0x01000000; - //return (0x01000000 - 1) * (x + y) / (width + height); } -int Calc(UINT x, UINT y, UINT width, UINT height) +INT Calc(UINT x, UINT y, UINT width, UINT height) { UINT m = min(width, height); int i; - double zr, zi, tmp, cr, ci; + double zr, zi, tmp, cr, ci;// , tr, ti; zr = zi = 0; + //tr = ti = 0; cr = graph.x0 + (x - (double)width / 2) / m * graph.size; ci = graph.y0 + (y - (double)height / 2) / m * graph.size; for (i = 0; i <= (int)graph.limit; i++) { if (zr * zr + zi * zi > 4) return i; + //tr = zr; ti = zi; tmp = zr * zr - zi * zi + cr; zi = 2 * zr * zi + ci; zr = tmp; + //tr = zr - tr; + //ti = zi - ti; } return -1; -} \ No newline at end of file + //return (INT)(fabs(atan2(zi, zr)) * graph.limit / M_PI); + //return (INT)(fabs(atan2(ti, tr)) * graph.limit / M_PI); + //return (INT)(sqrt(zi * zi + zr * zr) * graph.limit); +} + + diff --git a/Source/Graph.c b/Source/Graph.c index 5f13fdc..b6c7692 100644 --- a/Source/Graph.c +++ b/Source/Graph.c @@ -19,7 +19,8 @@ void InitGraph(UINT flg) if (flg & GRAPH_INIT_OTHER) { graph.scale = 1.5; graph.limit = 500; - graph.color_mode = 3;// 3: カスタマイズ + graph.inner_color_mode = GCM_I_SOLID;//GCM_I_GRAD; + graph.outer_color_mode = GCM_O_CUSTOM; } } @@ -35,14 +36,15 @@ void CopyGraph(struct GRAPH* gdest, struct GRAPH* gsrc) gdest->color_stop1 = gsrc->color_stop1; gdest->scale = gsrc->scale; gdest->limit = gsrc->limit; - gdest->color_mode = gsrc->color_mode; + gdest->inner_color_mode = gsrc->inner_color_mode; + gdest->outer_color_mode = gsrc->outer_color_mode; } BOOL SetGraphData(struct GRAPH *gdest, LPCWSTR input) { // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!フォーマットに適合する文字列か判定!!!!!!!!!!!!!!!!!!!!!!! int i = 0, j = 0, k = 0; - WCHAR data[10][50] = { {0} }; + WCHAR data[11][50] = { {0} }; while (input[i + j]) { if (input[i + j] == L'/') { k += 1; @@ -54,10 +56,10 @@ BOOL SetGraphData(struct GRAPH *gdest, LPCWSTR input) i += 1; } } - if (k != 9)return FALSE; + if (k != 10)return FALSE; - WCHAR names[10][19] = { + WCHAR names[][19] = { L"RE:", L"IM:", L"SIZE:", @@ -66,12 +68,13 @@ BOOL SetGraphData(struct GRAPH *gdest, LPCWSTR input) L"COLOR_C:", L"COLOR_STOP_A:", L"COLOR_STOP_B:", - L"COLOR_MODE:", + L"INNER_COLOR_MODE:", + L"OUTER_COLOR_MODE:", L"LIMIT:", }; - INT boo[10] = { 0 }; - for (i = 0; i < 10; i++)boo[i] = -1; + INT boo[11] = { 0 }; + for (i = 0; i < 11; i++)boo[i] = -1; typedef enum tagTYPE { TYPE_DOUBLE, @@ -80,7 +83,7 @@ BOOL SetGraphData(struct GRAPH *gdest, LPCWSTR input) TYPE_UINT, } TYPE; - TYPE typeof[10] = { + TYPE typeof[] = { TYPE_DOUBLE, TYPE_DOUBLE, TYPE_DOUBLE, @@ -90,9 +93,10 @@ BOOL SetGraphData(struct GRAPH *gdest, LPCWSTR input) TYPE_DOUBLE, TYPE_DOUBLE, TYPE_INT, + TYPE_INT, TYPE_UINT, }; - void* pointers[10] = { + void* pointers[] = { &(gdest->x0), &(gdest->y0), &(gdest->size), @@ -101,13 +105,14 @@ BOOL SetGraphData(struct GRAPH *gdest, LPCWSTR input) &(gdest->color2), &(gdest->color_stop0), &(gdest->color_stop1), - &(gdest->color_mode), + &(gdest->inner_color_mode), + &(gdest->outer_color_mode), //&(gdest->scale), &(gdest->limit), }; for (i = 0; i <= k; i++) { - for (j = 0; j < 10; j++) { + for (j = 0; j <= k; j++) { if (0 <= boo[j])continue; if (wcsncmp(names[j], data[i], lstrlen(names[j])) == 0) { boo[j] = i; @@ -115,12 +120,12 @@ BOOL SetGraphData(struct GRAPH *gdest, LPCWSTR input) } } - for (j = 0; j < 10; j++) { + for (j = 0; j < k; j++) { if (boo[j] < 0)return FALSE; } /* 以下,適切な入力があったときのみ実行 */ - for (j = 0; j < 10; j++) { + for (j = 0; j <= 10; j++) { switch (typeof[j]) { case TYPE_DOUBLE: swscanf_s(data[boo[j]] + lstrlen(names[j]), L"%lf", (double*)pointers[j]); @@ -152,10 +157,10 @@ void GetGraphData(LPWSTR buf, size_t bufSize) { swprintf( buf, bufSize, - L"RE:%29.20Lf/IM:%29.20Lf/SIZE:%29.20Lf/COLOR_A:%06lx/COLOR_B:%06lx/COLOR_C:%06lx/COLOR_STOP_A:%4.2Lf/COLOR_STOP_B:%4.2Lf/COLOR_MODE:%d/LIMIT:%u", + L"RE:%29.20Lf/IM:%29.20Lf/SIZE:%29.20Lf/COLOR_A:%06lx/COLOR_B:%06lx/COLOR_C:%06lx/COLOR_STOP_A:%4.2Lf/COLOR_STOP_B:%4.2Lf/INNER_COLOR_MODE:%d/OUTER_COLOR_MODE:%d/LIMIT:%u", graph.x0, graph.y0, graph.size, graph.color0, graph.color1, graph.color2, graph.color_stop0, graph.color_stop1, - graph.color_mode, /*graph.scale, */graph.limit + graph.inner_color_mode, graph.outer_color_mode, /*graph.scale, */graph.limit ); } diff --git a/Source/Menus.c b/Source/Menus.c index 38afd2a..f250735 100644 --- a/Source/Menus.c +++ b/Source/Menus.c @@ -202,7 +202,7 @@ INT_PTR CALLBACK MenuSetColor(HWND hDlg, UINT message, WPARAM wParam, LPARAM lPa cc[1].rgbResult = InvertColor(graph_cpy.color1); cc[2].rgbResult = InvertColor(graph_cpy.color2); - HWND hRadio = GetDlgItem(hDlg, IDC_SCRADIO1 + graph_cpy.color_mode); + HWND hRadio = GetDlgItem(hDlg, IDC_SCRADIO1 + graph_cpy.outer_color_mode); SendMessage(hRadio, BM_SETCHECK, 1, 0); SendDlgItemMessage(hDlg, IDC_SCSLIDER0, TBM_SETPOS, TRUE, (LPARAM)(graph_cpy.color_stop0 * 100)); SendDlgItemMessage(hDlg, IDC_SCSLIDER1, TBM_SETPOS, TRUE, (LPARAM)(graph_cpy.color_stop1 * 100)); @@ -294,7 +294,7 @@ INT_PTR CALLBACK MenuSetColor(HWND hDlg, UINT message, WPARAM wParam, LPARAM lPa case IDC_SCRADIO3: case IDC_SCRADIO4: { - graph_cpy.color_mode = LOWORD(wParam) - IDC_SCRADIO1; + graph_cpy.outer_color_mode = LOWORD(wParam) - IDC_SCRADIO1; break; }