Skip to content

Commit

Permalink
[add] 集合内部の彩色 for issue #12
Browse files Browse the repository at this point in the history
  • Loading branch information
TOMOQ1024 committed Oct 3, 2022
1 parent a5d6af7 commit 8a2c785
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 34 deletions.
2 changes: 1 addition & 1 deletion Include/Color.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
INT Calc(UINT x, UINT y, UINT width, UINT height);
3 changes: 2 additions & 1 deletion Include/Graph.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions Include/Resource.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
48 changes: 34 additions & 14 deletions Source/Color.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#include "Color.h"
#include "Graph.h"
#define _USE_MATH_DEFINES
#include <math.h>

extern struct GRAPH graph;

Expand Down Expand Up @@ -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;
}
//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);
}


37 changes: 21 additions & 16 deletions Source/Graph.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}

Expand All @@ -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;
Expand All @@ -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:",
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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),
Expand All @@ -101,26 +105,27 @@ 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;
}
}
}

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]);
Expand Down Expand Up @@ -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
);
}

Expand Down
4 changes: 2 additions & 2 deletions Source/Menus.c
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down Expand Up @@ -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;
}

Expand Down

0 comments on commit 8a2c785

Please sign in to comment.